Struts might be more transparent in that it delivers you a flat model. There's just that request and that one form comming in, and the form is populated by matching incomming request parameters with formbean properties. Furthermore, that formbean IS your model (and your only one), instead of a facade like Wicket's models are. It's surely simpler in that respect, but quite limited too.
Eelco On 3/15/06, Michael K <[EMAIL PROTECTED]> wrote: > mmhh It did struck me for a while to understand the underlying concept of > Wicket's model and the relationship with various components. One thing I > notice, It seems that Struts deal with form backing model more transparent > than Wicket does in terms of accessing the model object (or may be I'm just > being bias :). Or perhaps it just the way model 2 was implemented. > However I agree in long run Wicket provides better reusability and > scalability once I get used to with the concept. > > Thanks for your thorough explanation I really appreciate it. > > > Michael > > > > Jonathan Cone <[EMAIL PROTECTED]> wrote: > > > Hi Michael, > > One thing that I personally think is important to understanding ListView is > knowing that each item in the ListView is one concrete model object > instance. If you think about it, then you will see you shouldn't need > many(if any) collections in your form backing model classes. So a ListView > takes a 'list' of model objects and displays each one independent of the > other. One of the cool things about wicket is that your model object > instance fields can be strongly typed (more easily than Struts). As you'll > see in the model object below. Take a look at the following code which is > based on your example (I only used generics for type clarity): > > > > public class DetailForm extends Form { > private final List ageList = Arrays.asList(new Integer[] { > Integer.valueOf(10), Integer.valueOf(20), Integer.valueOf(30) }); > > // You'll probably want to pass your list in to your form constructor, as > opposed to this. > private final static List<DetailModel> model = initModelList(); > > public DetailForm(final String id) { > > super(id); > > // This model is a list of DetailModels > ListView listView = new ListView("detailList", model) { > > public void populateItem(final ListItem listItem) { > > listItem.setModel(new CompoundPropertyModel( > (DetailModel) listItem.getModelObject())); > > // This is bound to model.getCode()/setCode() > listItem.add(new TextField("code")); > > // Same for model.getAge()/setAge() > listItem.add(new DropDownChoice("age", ageList)); > > // Same for model.getName()/setName() > listItem.add(new TextField("name")); > } > }; > add(listView); > > } > > // Just a test to see that your changes are taking effect. > @Override > protected void onSubmit() { > System.out.println(model); > } > > // Again, not ideal, but for the sake of this example. > private static List<DetailModel> initModelList() { > List<DetailModel> model = new ArrayList<DetailModel>(); > model.add(new DetailModel(Integer.valueOf(10), "Harry", "bigboy")); > model.add(new DetailModel(Integer.valueOf(20), "Jan", "foo")); > model.add(new DetailModel(Integer.valueOf(30), "Meg", "boss")); > return model; > } > > public static class DetailModel implements Serializable { > > private Integer age; > private String name; > private String code; > > public DetailModel() { > > } > > public DetailModel(Integer age, String name, String code) { > super(); > this.age = age; > this.name = name; > this.code = code; > } > > public String getCode() { > return code; > } > > public void setCode(String code) { > this.code = code; > } > > public Integer getAge() { > return age; > } > > public void setAge(Integer age) { > this.age = age; > } > > public String getName() { > return name; > } > > public void setName(String name) { > this.name = name; > } > > @Override > public String toString() { > return name + ", " + age + "(" + code + ")"; > } > } > > } > > Good luck, I hope this helps you understand. Just remember th at it really > is as easy as it should be, which (sadly) takes some getting used to if > you've used other frameworks. > > ----- Original Message ----- > From: Michael K > To: Wicket User List > Sent: Wednesday, March 15, 2006 4:22 AM > Subject: [Wicket-user] Newbie question: applying dynamic form component with > ListView > > Hi, > > Which type should I define in POJO Model to hold the value of the array of > TextField/DropDownChoice when populated by ListView? Should I define it as > String[] or ArrayList o r something else? > > I have attached the following example to explain my situation: > > > public class DetailForm extends Form { > private java.util.List ageList = Arrays.asList(new String[]{ "10", > "20", "30" }); > public DetailForm(String string){ > > super(string); > DetailModel dm = new DetailModel(); > > setModel(new CompoundPropertyModel(dm)); > > ListView listView = new ListView("detailList", new > PropertyModel(this, "detailData")){ > > public void populateItem(final ListItem listItem){ > final String detail = (String) > listItem.getModelObject(); > listItem.add(new Label("code",detail)); > listItem.add(new DropDownChoice("age",ageList)); > listItem.add(new TextField("name")); > } > }; > add(listView); > > } > > public List getDetailData(){ > java.util.List hm = new ArrayList(); > > // Should get the data from DB, for simplicity I use hardcode > value > hm.add("aaaa"); > hm.add("bbbb"); > hm.add("cccc"); > return hm; > } > } > > > & nbsp; // Model class > public class DetailModel implements Serializable { > > private String[] age = new ArrayList(); // ???? Not sure about the > type > private String[] name; > > public String[] getAge(){ > return age; > } > > public void setAge(String[] age){ > this.age = age; > } > > public String[] getName(){ > return name; > } > > public void setName(String[] name){ > this.name = name; > } > } > > The idea behind String[] was my 'past time' with Struts :) > Any suggestion? > > > Cheers, > > Michael > > > > > ________________________________ > Yahoo! Mail > Use Photomail to share photos without annoying attachments. > > ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642 _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user