On Sat, Jan 15, 2011 at 6:36 AM, Arjun Dhar <dhar...@yahoo.com> wrote:
> > I was hoping on the lines, where you do "get(<component id>)"; Wicket > returns > the Component. > So if there was a way to customize the nomenclature of what the "names" of > the fields are in a loop then it would be easy to refer to components via > name directly. > > ... I can't do [IN CONCEPT] get("additionalFeatures").get("<My naming > convention Sub Item component Id>").getDefaultModelObject() or something. > <-- I was asking if there was any magical way like that. > The question Igor asked isn't answered. WHY do you need to access the ListItem? For what purpose? From where in your code? Why? This is just regular java - access it as a reference to a java object if you must. But I don't see why you need to. Unless you're doing something wrong. Not a big deal , I worked around . For the sake of discussion my ListItem is > defined by the following: > > ListView additionalFeatures = new ListView<String>("additionalFeatures", > additionalFeaturesKeyList) { > ... > @Override > protected void populateItem(ListItem<String> item) { > String key = item.getModelObject(); //Assume > this to be the Name / Id of > something > item.add(new Label("name", new Model(key))); > > String modelKeyName = > MarshalUtils.toAlphaNumeric(key); > final Feature feature = > additionalFeaturesMap.get(key); > item.add(new TextArea("value", new > Model(feature.getValue().toString())) > .setLabel(new > Model(modelKeyName)) > .setMarkupId(key)); > } > ... > } > OH! There's where you're doing something wrong. Rather than allowing a model (or here, several models) to marshal your data for you (get the current value from the list, and the map, and finally from your pojo), you are doing it yourself. Using "new Model(...)" does *not* mean you are using models correctly. Your code above should be using property models to get the properties from the pojos. By doing this, the form fields will also set the updated values back on your pojos, which means you won't need to manually access these list items later. Try to avoid touching the domain object at all in your component creation code (only let the models touch it). What I went with at the end was: > > ListView listView = > (ListView)get("additionalFeatures"); > for (int x=0; > x<listView.size(); x++) { > ListItem > additionalFeatureField = (ListItem)listView.get(x); > > //Now I work > with the ListItem however I want to and derive what I want :) > Well, I would say "where are you doing that?" which was basically the original question - where would you need to access the list item directly? But, from looking at the code above, I'll bet that you are doing this loop over list items in your form onSubmit or similar. Again, this is horrible. You shouldn't be doing that. The form fields should have models that set the data on the pojo for you. Then you don't need to iterate through them and marshal data yourself. ..Which works also, but not as elegant as I hoped. But I realize its a LIST, > so my expectations are perhaps unjustified and iteration of the list is > logical and inescapable. > No - iteration of the list is not necessary, and *very* escapable! -- Jeremy Thomerson http://wickettraining.com *Need a CMS for Wicket? Use Brix! http://brixcms.org*