You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Andrew Robinson <an...@gmail.com> on 2008/05/05 17:23:23 UTC

Re: [TRINIDAD] How to bind constant values in selections? Or bind Enums to the itemValue.

public enum Gender { MALE, FEMALE }

<tr:selectOneChoice label="Gender"  value="#{person.gender}" required="true">
 <f:selectItem itemLabel="#{text['person.genderMale']}" itemValue="MALE"/>
 <f:selectItem itemLabel="#{text['person.genderFemale']}" itemValue="FEMALE"/>

That may work in 1.2, I cannot remember. I always used Seam to work with enums:
http://docs.jboss.com/seam/2.0.1.GA/reference/en/html/controls.html

See <s:convertEnum> and <s:enumItem>

-Andrew


On Mon, May 5, 2008 at 3:39 AM, Martin Piekorz <pi...@primion.de> wrote:
>
>
>
>
> Hi @ all,
>
>
>
> does someone knows a way to bind some constants? Perhaps with help of Enums?
>
>
>
>
>
> Here my person class with gender const.
>
>
>
> Class Person{
>
>     /** Constants for the gender */
>
>     public static final int GENDER_MALE = 1;
>
>     public static final int GENDER_FEMALE = 2;
>
>
>
>
>
>
>
>
>
>
>
> Here my jps.
>
> …
>
> <tr:selectOneChoice label="Gender"  value="#{person.gender}"
> required="true">
>
>  <f:selectItem itemLabel="#{text['person.genderMale']}" itemValue="1"/>
>
>  <f:selectItem itemLabel="#{text['person.genderFemale']}" itemValue="2"/>
>
>
>
>
>
> I want something like this!
>
> <tr:selectOneChoice label="Gender"  value="#{person.gender}"
> required="true">
>
>   <f:selectItem itemLabel="#{text['person.gender']}"
> itemValue="#{person.GENDER_MALE}"/>
>
>   <f:selectItem itemLabel="#{text['person.gender']}"
> itemValue="#{person.GENDER_FEMALE}"/>
>
>
>
>
>
>
>
> I thought about create a getter for each const but if I have some more it
> would be not very pretty to
>
> Have a getter for each const value.
>
> I also thought about enums, but I do not really how I could implement this.
> Has someone a solution for this?
>
>
>
>
>
>
>
> Thank you.
>
> Martin
>
>