Re: Changing/Accessing name of ListItem in ListView

2011-01-15 Thread Igor Vaynberg
why do you need to access the listitem? listitem.getmodelobject() will
give you the item in the list the item is pointed to.

-igor

On Fri, Jan 14, 2011 at 11:07 PM, Arjun Dhar dhar...@yahoo.com wrote:

 Hi,
  when using a ListView, the name uses the following format to Render. loop
 name:index:field id

 In onSubmit(..); this is fine if you know the order of the list. However say
 if the primary data Structure is a hashmap then its more convenient/elegant
 to retrieve by Name. I can change the name of the attribute but Wicket does
 not recognize it when one does get(componentId).

 Using ListView.getList() I can access the Model, but this does not help
 getting the access to the individual components.

 Looks like the only way is to use a numberic counter and construct the
 Component ID's to access it one my one.

 Is there a way to change the component Id ..or perhaps access these by name?
 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/Changing-Accessing-name-of-ListItem-in-ListView-tp3218777p3218777.html
 Sent from the Users forum mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Changing/Accessing name of ListItem in ListView

2011-01-15 Thread Arjun Dhar

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.

Not a big deal , I worked around . For the sake of discussion my ListItem is
defined by the following:

ListView additionalFeatures = new ListViewString(additionalFeatures,
additionalFeaturesKeyList) {
...
@Override
protected void populateItem(ListItemString 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));
}
...
}



What I went with at the end was:

ListView listView = 
(ListView)get(additionalFeatures);
for (int x=0; 
xlistView.size(); x++) {
ListItem 
additionalFeatureField = (ListItem)listView.get(x);

//Now I work
with the ListItem however I want to and derive what I want :)
 ...
}

..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.



-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Changing-Accessing-name-of-ListItem-in-ListView-tp3218777p3219010.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Changing/Accessing name of ListItem in ListView

2011-01-15 Thread Jeremy Thomerson
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 ListViewString(additionalFeatures,
 additionalFeaturesKeyList) {
 ...
@Override
protected void populateItem(ListItemString 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;
 xlistView.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*


Re: Changing/Accessing name of ListItem in ListView

2011-01-15 Thread Jeremy Thomerson
On Sat, Jan 15, 2011 at 9:34 PM, Jeremy Thomerson jer...@wickettraining.com
 wrote:



 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 ListViewString(additionalFeatures,
 additionalFeaturesKeyList) {
 ...
@Override
protected void populateItem(ListItemString 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;
 xlistView.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*



PS - meant to include a link to this page, which may help you understand
models: https://cwiki.apache.org/WICKET/working-with-wicket-models.html

Don't worry - it's probably the most common mistake Wicket newbs make!  It's
definitely the thing I stress understanding the most in my Wicket classes.

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*


Re: Changing/Accessing name of ListItem in ListView

2011-01-15 Thread Arjun Dhar

Your bet was right, it was onSubmit()! I understand better now.

On a funny note; I can  imagine Igor exasperated ...This guys on a
different tangent... :)


Don't worry - it's probably the most common mistake Wicket newbs make! 
It's
definitely the thing I stress understanding the most in my Wicket classes. 

 thanks, honestly it comforting to know I'm not a complete moron :)


On a technical Note (further understanding):
I had read about Bindgen and it highlighted the issues with using
PropertyModels, and Bindgen is a bit more inconvenient. So I guess I
somewhere lost my track. Now I realize the pitfall of not following either.
...valuable lesson.

Thanks guys, very much appreciated!
-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Changing-Accessing-name-of-ListItem-in-ListView-tp3218777p3219725.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Changing/Accessing name of ListItem in ListView

2011-01-14 Thread Arjun Dhar

Hi,
 when using a ListView, the name uses the following format to Render. loop
name:index:field id

In onSubmit(..); this is fine if you know the order of the list. However say
if the primary data Structure is a hashmap then its more convenient/elegant
to retrieve by Name. I can change the name of the attribute but Wicket does
not recognize it when one does get(componentId).

Using ListView.getList() I can access the Model, but this does not help
getting the access to the individual components.

Looks like the only way is to use a numberic counter and construct the
Component ID's to access it one my one.

Is there a way to change the component Id ..or perhaps access these by name?
-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Changing-Accessing-name-of-ListItem-in-ListView-tp3218777p3218777.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org