struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Li Ying <liying.cn.2...@gmail.com>
Subject Re: Databinding a checkboxlist
Date Fri, 19 Nov 2010 12:59:24 GMT
try

<s:checkboxlist
               list="@my.site.enums.Color@values()"
               listKey="label"
               listValue="label"
               name="colors"
               />


2010/11/19 Altenhof, David Aron <daltenho@iupui.edu>:
> Trying to figure out a way to do the following without much luck.
>
> I have an enumeration with a list of menu options and corresponding labels such as:
>
> public enum Color {
>        RED("Red"),
>        BLUE("Blue"),
>        GREEN("Green");
>
>        private String myLabel;
>        private Color(String label){ this.myLabel = label; }
>        public String getLabel(){ return this.myLabel; }
> }
>
> This can be easily used to create a checkboxlist:
>
> <p> Please enter your favorite colors: </p>
> <s:checkboxlist
>                list="@my.site.enums.Color@values()"
>                listValue="label"
>                name="colors"
>                />
>
> I also have a set of Color on the Action that came from the persistence layer and has
a Color for each of the user's (past) choices:
>
> public Set<Color> getColors() {
>        return colors;
> }
>
> Question is: How do I automagically "check" the appropriate checkbox if they have a corresponding
value in getColors? I guess I'm looking for something like a databind from other languages.
>
> I suppose one could iterate over the enum and create individual checkboxes for each while
testing to see if they have an already selected color, but I thought there might be a more
direct way...
>
> -David
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message