-
1. SelectOneMenu output display problem
iabughosh May 18, 2011 3:53 AM (in response to abdoulmou3in)welcome to the forum abdoulmou3in, what is the version of JSF, RF ?
-
2. Re: SelectOneMenu output display problem
h2g2 May 18, 2011 5:18 AM (in response to abdoulmou3in)Hi,
at first, I think a f:selectItems objet can only be mapped to an array of SelectItems (such as :
ArrayList<SelectItem> civilites= new ArrayList<SelectItem>();
And since it's a list of both "value" and "label" items, you needn't a "itemLabel" in your f:selectItems. That's why this attribute does not exist for the tag f:selectItems (or it would be called instead "itemLabels" or something like that).
Eventually, you need to populate such a list with a list of SelectItems<Value,Label> where the value will be the key to know which item is selected (or to set it from your bean) , and the label the displayed entry for the user.
For those, you can for exemple put some string holding the "VAR" in your TCivilites, such as
for (TCivilite civilite : AllCivilites){
civilites.add(newSelectItems(civilite.id,Integer.toString(civilite.var1)+Integer.toString(civilite.var2)));
}Hope it will help.
-
3. SelectOneMenu output display problem
abdoulmou3in May 18, 2011 1:36 PM (in response to abdoulmou3in)Hi all,
Thak you very much for your unswers.
For now i'm wrinting from train using m'y phone.
Ibrahim, i'm using eclips 3.6 Helios / tomcat 7 / JSF 2 majora / RICHFACES 4 and hibernate 2.3
H2g2, i'll try to mofdify m'y code and let you know.
Thanks again for all of you.
-
4. SelectOneMenu output display problem
iabughosh May 18, 2011 5:32 PM (in response to abdoulmou3in)there is a new feature in JSF 2 allows you to do that :
<h:selectOneMenu>
<f:selectItems value="#{mybean.list}"
var="item"
itemLabel="#{item.name}"
itemValue="#{item.value}"/>
</h:selectOneMenu>
where mybean.list is an ArrayList<MyBean>.
regards.
-
5. Re: SelectOneMenu output display problem
adballeras May 18, 2011 11:45 PM (in response to abdoulmou3in)Make sure that value for the itemLabel is of type String or it will use toString method of that object. In your case it is getting the return value of toString method in TCivilite.
If you have for example a property name of type String in TCivilite:
<h:selectOneMenu value="#{yourBean.selected}"> <f:selectItems value="#{yourBean.list}" var="item" itemLabel="#{item.name}" itemValue="#{item}" /> </h:selectOneMenu>
You also need to have a property of type TCivilite with matching getter and setter methods in order to get what is selected by the user.