首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >继承+ RPC GWT

继承+ RPC GWT
EN

Stack Overflow用户
提问于 2014-10-04 21:45:38
回答 1查看 92关注 0票数 0

看起来我不理解继承。我有这些类: PicaAsset,VideoAsset,它们继承自一个名为Assets的类名。这是Assets类声明:

代码语言:javascript
复制
public class Assets {
protected int book=0;
protected int fromChapter=0;
protected int toChapter=0;
protected int fromVerse=0;
protected int toVerse=0;
protected String creator=null;
protected String discription=null;
protected String source=null;
protected String title=null;
protected String duration=null;
protected String url=null;

public Assets(int book, int fromChapter, int toChapter, int fromVerse,
        int toVerse, String creator, String discription, String source,
        String title, String duration, String url) {

    this.book = book;
    this.fromChapter = fromChapter;
    this.toChapter = toChapter;
    this.fromVerse = fromVerse;
    this.toVerse = toVerse;
    this.creator = creator;
    this.discription = discription;
    this.source = source;
    this.title = title;
    this.duration = duration;
    this.url = url;
}

public Assets() {
}

public int getBook() {
    return book;
}

public void setBook(int book) {
    this.book = book;
}
public int getFromChapter() {
    return fromChapter;
}
public void setFromChapter(int fromChapter) {
    this.fromChapter = fromChapter;
}
public int getToChapter() {
    return toChapter;
}
public void setToChapter(int toChapter) {
    this.toChapter = toChapter;
}
public int getFromVerse() {
    return fromVerse;
}
public void setFromVerse(int fromVerse) {
    this.fromVerse = fromVerse;
}
public int getToVerse() {
    return toVerse;
}
public void setToVerse(int toVerse) {
    this.toVerse = toVerse;
}
public String getCreator() {
    return creator;
}
public void setCreator(String creator) {
    this.creator = creator;
}
public String getDiscription() {
    return discription;
}
public void setDiscription(String discription) {
    this.discription = discription;
}
public String getSource() {
    return source;
}
public void setSource(String source) {
    this.source = source;
}
public String getTitle() {
    return title;
}
public void setTitle(String title) {
    this.title = title;
}
public String getDuration() {
    return duration;
}
public void setDuration(String duration) {
    this.duration = duration;
}
public String getUrl() {
    return url;
}
public void setUrl(String url) {
    this.url = url;
}

PicAsset:

代码语言:javascript
复制
public class PicAsset extends Assets implements IsSerializable {

  private int picId=0;

  public PicAsset(){
  }

  public PicAsset(int picId, int book, int fromChapter, int toChapter,
        int fromVerse, int toVerse, String creator, String discription,
        String source, String title, String duration, String url) {
    super(  book,  fromChapter,  toChapter,
             fromVerse,  toVerse, creator,  discription,
            source,  title,  duration,  url);
    this.picId = picId;
  }

  public int getIdpic() {
    return picId;
  }
  public void setIdpic(int idpic) {
    this.picId = idpic;
  }
}

现在我使用一个RPC调用来使用在服务器端声明的方法来从我的数据库中获取信息,因为您可以看到该方法返回一个列表PicAsset,List。

代码语言:javascript
复制
 rpcService.getPicture((books.getSelectedIndex()+1), (chapters.getSelectedIndex()+1), new AsyncCallback<List<PicAsset>>(){
                    public void onFailure(Throwable caught) {
                        Window.alert("Can't connect to database" + books.getSelectedIndex() + chapters.getSelectedIndex());
                    }

                    public void onSuccess(List<PicAsset> result) {
                        int listSize = result.size();
                        int i;
                        int flag = 0;

                        assetPicPanel.clear();

                          Label frameTitle = new Label("Pictures");
                                for(i=0;i<listSize;i++)
                                {
                                    if(flag == 0)
                                    {
                                        assetPicPanel.add(frameTitle);
                                        flag = 1;
                                    }


                                    HorizontalPanel vPanelPic = new HorizontalPanel();

                                    System.out.print("heeeeey" +" " + result.get(i).getFromChapter());                                      
                                    Grid g = result.get(i).AssetGrid(result.get(i));

                                    vPanelPic.add(g);
                                    assetPicPanel.add(vPanelPic);
                                }
                    }
                });

现在,当我在服务器端打印..get().getFromChapter()时,它会带来正确的值。但是当我打印返回给RPC调用的值时,我得到了默认的构造函数值……而不是必须送回的东西。

这里还有服务器端的getPicture实现:

代码语言:javascript
复制
public List<PicAsset> getPicture(int book, int chapter) throws Exception

 {

    System.out.print("getPicture ok " + book +"," + chapter);
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet result = null;
    List<PicAsset> relevantAssets = new ArrayList<PicAsset>();
    PicAsset relAsset;


    try {
        conn = getConnection();
        pstmt = conn.prepareStatement("SELECT * FROM picasset WHERE book = ? AND fromChapter <= ? AND toChapter >= ?");

        //System.out.print("connection" + conn);
        pstmt.setInt(1, book);
        pstmt.setInt(2, chapter);
        pstmt.setInt(3, chapter);

        result = pstmt.executeQuery();

      //  System.out.print(result);
        while (result.next()) {

            //System.out.print("in while");
            relAsset = new PicAsset(result.getInt("picId"),result.getInt("book"), result.getInt("fromChapter"), result.getInt("toChapter"),result.getInt("fromVerse"),result.getInt("toVerse"),result.getString("creator"),result.getString("discription"),result.getString("source"),result.getString("title"),result.getString("duration"),result.getString("url"));
            relevantAssets.add(relAsset);

        }
    }

        catch (SQLException sqle) 
        {
            sqle.printStackTrace();
        } 
        finally
        {
            // Cleanup
            result.close();
            pstmt.close();
            conn.close();
        }

    System.out.print("In MySql get Chapter  " + relevantAssets.get(0).getFromChapter() + " " + relevantAssets.get(0).getIdpic());
    return relevantAssets;
}
EN

回答 1

Stack Overflow用户

发布于 2014-10-05 02:17:16

在GWT中,使用原始数组比使用集合接口要好得多-从方法PicAsset[]返回,而不是List。这将允许您(a)解决您的问题,(b)避免将不必要的类编译为客户端代码。

请参阅gwtproject.org上的“原始类型”部分

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26193428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档