-
1. Re: How do you customize the label for s:selectItems
stephen May 26, 2008 8:53 PM (in response to jim.barrows)Your description is a little vague, so I'm not sure if I understand the problem correctly.
IMHO you should have a common interface for your entities (actually you don't even need the interface as long as each class has a getLabel() method).If that won't do I guess you can always have a helper method like
<s:selectItems value="#{myVal}" var="myVar" label="#{someBean.getLabel(myVar)}"/>
You could define an EL function for that getLabel method, but I usually have an application scoped seam componente
utils
for such methods. -
2. Re: How do you customize the label for s:selectItems
jim.barrows May 26, 2008 11:48 PM (in response to jim.barrows)I have a collection of different classes that can be selected. Some need one getter called, the others may need two different getters to display as a label. I just need to be able to do something like rendered =
#{ beanName.class.simpleName = 'ClassName'}
I'll try it the way you suggest. I was hoping I was missing something on the tag though. :)
I'm of themodels shouldn't have anything that relates to the view in them
camp, and these are all model objects in the list. -
3. Re: How do you customize the label for s:selectItems
stephen May 27, 2008 1:11 AM (in response to jim.barrows)Hm, now that I saw your last post, I think this should indeed work, too (though it doesn't feel quite right, either)
<s:selectItems value="#{myVal}" var="myVar" label="#{myVar.class.simpleName == 'LabeledEntity' ? myVar.getLabel(myVar)} : myVar.getName()"/>
You can nest the ternary operator to err, increase flexibility (while decreasing readability).