-
1. Re: Custom Converter
daxxy Feb 16, 2010 7:36 PM (in response to pbosman)Hi Pieter I'm in exactly the same boat as you are, however, I am starting to get a glimmer of understanding regarding custom converters.
My dilemma is I wish to use a richfaces comboBox instead of a selectOneMenu.
BTW -- as I'm writing this it occurs to me that you don't need a converter if you are using selectOneMenu. You can use s:selectItems to display values and labels based on your database query.
Here is some code I used to display a selectOneMenu containing entries that look like this
AK (Alaska) AL (Alabama)
But the value that gets input is simply the 2 character abbreviation, ie AK or AL
<h:selectOneMenu value="#{office.state}"> <s:selectItems noSelectionLabel=" " value="#{statesList.stateNames}" var="_state" label="#{_state[0]} (#{_state[1]})" itemValue="#{_state[0]}" /> </h:selectOneMenu>
Let me know if you need more details. The basic is that what you display is the value of
label
and what you input is the value ofitemValue
.http://in.relation.to/Bloggers/SselectItemsCustomisingTheValue
-
2. Re: Custom Converter
kenfrommera Feb 17, 2010 11:11 AM (in response to pbosman)Either use <s:convertEntity> (see section 33.1.2.2 of the Seam documentation) or write your own converter (section 33.2 of the Seam documentation).
-
3. Re: Custom Converter
kblief.kblief.gmail.com Feb 25, 2010 3:47 PM (in response to pbosman)You can use s:convertEntity like so
<h:selectOneMenu value="#{someBean.user}" id="utoL" > <s:selectItems value="#{userBean.users}" var="user" label="#{user.firstname} #{user.lastName}" noSelectionLabel="None"/> <s:convertEntity/> </h:selectOneMenu>
If you use s:convertEntity you have to over ride the equals and hashcode methods of you entity. It can be something as simple as :
public boolean equals(Object obj) { boolean equals = false; if (obj != null && obj instanceof User && ((User) obj).userId == this.userId) { equals = true; } return equals; }