2012-03-24 26 views
0

我試圖把數據&顯示,通過使用組件標籤
數據,但這些數據並沒有看到在頁面
所有標籤都在錶行&行increses在這裏,但排犯規獲得標籤數據來源列表中,但不會看到到頁面

package com.cerebrum.pages;  

    import java.util.ArrayList; 

    import java.util.List;  

    import org.apache.wicket.markup.html.basic.Label; 
    import org.apache.wicket.markup.html.form.Form; 
    import org.apache.wicket.markup.html.list.ListItem; 
    import org.apache.wicket.markup.html.list.ListView; 
    import org.apache.wicket.model.CompoundPropertyModel; 
    import org.apache.wicket.model.PropertyModel; 

    import com.cerebrum.common.Home; 
    import com.cerebrum.hibernate.AddForumSubCategoryEntity; 
    import com.cerebrum.hibernate.ForumHome; 
    import com.cerebrum.pojo.ForumModel; 
    public class Forum extends Home 
    { 
    ForumHome forumHome=new ForumHome(); 
    ForumModel forumModel=new ForumModel(); 
    List<ForumModel> listForum=new ArrayList<ForumModel>(); 
    public Forum() 
    { 
     super(); 
     add(new ForumForm()); 
    } 
    class ForumForm extends Form 
    { 
    public ForumForm() 
    { 
     super("ForumForm"); 
     setModel(new CompoundPropertyModel(forumModel)); 

     List<AddForumSubCategoryEntity> list=forumHome.getAll(); 
     for(AddForumSubCategoryEntity addForumSubCategoryEntity:list) 
     { 
      listForum.add(new  
     ForumModel(addForumSubCategoryEntity.getMain_key(), 
     addForumSubCategoryEntity.getDescription())); 
     } 

     ListView listView=new ListView("listForum",listForum) 
     { 
      @Override 
      protected void populateItem(ListItem item) 
      { 
       ForumModel model=(ForumModel)item.getDefaultModelObject(); 

       Label lblMainCategory=new Label("lblMainCategory",new  
    PropertyModel(model, "lblMainCategory")); 
       item.add(lblMainCategory); 

       Label lblLastSubCategory=new 
    Label("lblLastSubCategory",new PropertyModel(model, "lblLastSubCategory")); 
       item.add(lblLastSubCategory); 

       Label lblTotalNoofPost=new Label("lblTotalNoofPost",new 
    PropertyModel(model, "lblTotalNoofPost")); 
       item.add(lblTotalNoofPost); 
      } 
     }; 
     listView.setOutputMarkupId(true); 
     add(listView); 
    } 
} 
} 
+0

我失去了所有的車型。你想要歸檔什麼? – bert 2012-03-24 09:46:38

回答

1

儘量避免創建這個中間列表「listForum」這將是更好,如果你forumModel有一個方法「getListForum」,所以你不需要模型傳遞到ListView。 (請參閱CompoundPropertyModels在這裏的工作方式https://cwiki.apache.org/WICKET/working-with-wicket-models.html)。

而在你的ListView中,你使用的是「getDefaultModelObject()」而不是「getModel」,然後你使用這個作爲PropertyModel的模型,這很奇怪。

我不完全理解你的模型(被ForumHome或ForumModel實施IModel?),但我想這樣的事情會是一個更好的辦法:

public class Forum extends Home { 

private ForumHome forumHome = new ForumHome(); 
private ForumModel forumModel = new ForumModel(forumHome); 

public Forum() { 
    super(); 

    add(new ForumForm("ForumForm", forumModel)); 
} 

private static class ForumForm extends Form { 
    public ForumForm(String wicketId, ForumModel forumModel) { 
     super(wicketId, new CompoundPropertyModel(forumModel)); 

     ListView<ForumModel> listView = new ListView<ForumModel>("listForum") { 

      @Override 
      protected void populateItem(ListItem item) { 
       IModel<ForumModel> model = item.getModel(); 

       item.add(new Label("lblMainCategory", new PropertyModel(model, "lblMainCategory"))); 
       item.add(new Label("lblLastSubCategory", new PropertyModel(model, "lblLastSubCategory"))); 
       item.add(new Label("lblTotalNoofPost", new PropertyModel(model, "lblTotalNoofPost"))); 

      } 
     }; 
     listView.setOutputMarkupId(true); 
     add(listView); 
    } 
} 
} 
相關問題