2012-03-24 3 views
0

ich Daten versuche & Anzeige zu nehmen, dass die Daten durch die Komponente Label-
verwenden, aber, dass die Daten nicht auf Seite nicht gesehen
alle Etiketten sind in table-row & Reihe increses hier aber Reihe doesnt LabelDie Daten stammen aus der Liste aber nicht auf die Seite gesehen

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

Ich bin in allen Modellen verloren. Was versuchst du zu archivieren? – bert

Antwort

1

Versuchen erhalten Erstellung dieser Zwischen Liste „listForum“ zu vermeiden, es wäre besser, wenn Ihr forumModel eine Methode „getListForum“ haben, so dass Sie nicht das Modell an die Listview übergeben müssen. (Sehen Sie, wie CompoundPropertyModels hier funktioniert https://cwiki.apache.org/WICKET/working-with-wicket-models.html).

Und in Ihrem ListView verwenden Sie "getDefaultModelObject()" anstelle von "getModel" und dann verwenden Sie dies als ein Modell für das PropertyModel, das ist seltsam.

ich nicht vollständig verstehen, Ihr Modell (Are FORUMHOME oder ForumModel Umsetzung IModel?), Aber ich denke, dass so etwas wie dies wäre ein besserer Ansatz sein:

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); 
    } 
} 
} 
Verwandte Themen