This content has been marked as final.
Show 7 replies
-
1. Re: how to order aplhabetically a selectOneMenu
whitty69 Aug 25, 2008 9:42 AM (in response to molif)if you are retrieving the data from a backing bean then you can use any of the standard sorting methods such as sorted sets and comperators to pre-sort your values, then add the selectItems from that pre-sorted list.
hope this helps. -
2. Re: how to order aplhabetically a selectOneMenu
molif Sep 2, 2008 10:07 AM (in response to molif)Actually I take the data from the bean's properties. Like this:
<s:selectItems value="#{templateManager.template.templateFields}" var="templateField" label="#{templateField.field.parentField.code}.#{templateField.field.code}"/>
I want to order the items by templateField.field.parentField.code
I guess I have to do it in the JSF page itself? But how? -
3. Re: how to order aplhabetically a selectOneMenu
molif Sep 3, 2008 4:39 AM (in response to molif)Please, help? Is there any tag or something to add to the code?
-
4. Re: how to order aplhabetically a selectOneMenu
molif Sep 3, 2008 8:32 AM (in response to molif)Can I user some rich faces tag instead of the seam one?
-
5. Re: how to order aplhabetically a selectOneMenu
jnwelzel Sep 3, 2008 1:02 PM (in response to molif)On situations like this I usually have a
List<SelectItem>
on my backing bean and that's where my<h:selectOneMenu>
gets all its options from. On the backing I have a method that looks kinda like this (simplified and easy-to-understand version lol):private void loadUserList() { backingBeanList = new ArrayList<SelectItem>(); List<User> lista = new UserController().retrieveAll(); for (User u : lista) { String name = u.getName(); backingBeanList .add(new SelectItem(u, name)); } }
They're automatically displayed in alphabetical order inside the selectOneMenu if I do it like this.
Hope this helps.
Cya. -
6. Re: how to order aplhabetically a selectOneMenu
molif Sep 10, 2008 4:13 AM (in response to molif)Thank you for the idea, but unfortunately, it won't work. Here is my code:
public List<SelectItem> getFieldsForTemplate() { List<SelectItem> result = new ArrayList<SelectItem>(); Set<TemplateField> fields = //retrieve somehow for (TemplateField tf : fields) { String label = tf.getField().getParentField().getCode() + "." + tf.getField().getCode(); result.add(new SelectItem(tf, label)); } return result; }
In the JSP, I have:<h:selectOneMenu id="templateFieldMenu" value="#{newTemplateField}"> <f:selectItems value="#{templateManager.fieldsForTemplate}" /> <s:convertEntity /> </h:selectOneMenu>
And finally, in the application, the drop-down menu is still not ordered alphabetically. :( -
7. Re: how to order aplhabetically a selectOneMenu
molif Sep 10, 2008 4:34 AM (in response to molif)Well, I created my own Comparator and it worked:
Collections.sort(result, new Comparator<SelectItem>() { public int compare(SelectItem sItem1, SelectItem sItem2) { String sItem1Label = sItem1.getLabel(); String sItem2Label = sItem2.getLabel(); return (sItem1Label.compareToIgnoreCase(sItem2Label)); } });
Thank you however :)
Regards