You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris <ch...@carlsoncentral.com> on 2009/05/08 23:19:49 UTC

DropDownChoice ID's

 List test = Arrays.asList(new String[] { "A", "B", "C" });
 add(new DropDownChoice("test", test));

How can I make the Id's match the Values?  There coming through as 
1,2,3.  I've tried custom ChoiceRenderer, but seem to be missing something.

Any help is appreciated.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice ID's

Posted by Oblivian <ch...@carlsoncentral.com>.
Thanks.


Oblivian wrote:
> 
>  List test = Arrays.asList(new String[] { "A", "B", "C" });
>  add(new DropDownChoice("test", test));
> 
> How can I make the Id's match the Values?  There coming through as 
> 1,2,3.  I've tried custom ChoiceRenderer, but seem to be missing
> something.
> 
> Any help is appreciated.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23454080.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice ID's

Posted by Oblivian <ch...@carlsoncentral.com>.
basicDemographicInfo.gender is a String
and
genders is List<Gender> 




Oblivian wrote:
> 
>  List test = Arrays.asList(new String[] { "A", "B", "C" });
>  add(new DropDownChoice("test", test));
> 
> How can I make the Id's match the Values?  There coming through as 
> 1,2,3.  I've tried custom ChoiceRenderer, but seem to be missing
> something.
> 
> Any help is appreciated.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23466110.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice ID's

Posted by Oblivian <ch...@carlsoncentral.com>.
Think I figured it out by doing something like this.  Is this the right way?

public class StringChoiceRender implements IChoiceRenderer {

  public Object getDisplayValue(Object object) {
    return object.toString();
  }
  
  public String getIdValue(Object object, int index) {
    return object.toString();
  }

}


Oblivian wrote:
> 
>  List test = Arrays.asList(new String[] { "A", "B", "C" });
>  add(new DropDownChoice("test", test));
> 
> How can I make the Id's match the Values?  There coming through as 
> 1,2,3.  I've tried custom ChoiceRenderer, but seem to be missing
> something.
> 
> Any help is appreciated.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23454055.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice ID's

Posted by Igor Vaynberg <ig...@gmail.com>.
new ichoicerenderer<string> {
  object getid(string object, int index) { return object; }
  string getdisplayvalue(string object) { return object; }
}

-igor

On Fri, May 8, 2009 at 2:19 PM, Chris <ch...@carlsoncentral.com> wrote:
> List test = Arrays.asList(new String[] { "A", "B", "C" });
> add(new DropDownChoice("test", test));
>
> How can I make the Id's match the Values?  There coming through as 1,2,3.
>  I've tried custom ChoiceRenderer, but seem to be missing something.
>
> Any help is appreciated.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice ID's

Posted by Igor Vaynberg <ig...@gmail.com>.
this should clear things up for you

http://www.systemmobile.com/?page_id=236

-igor

On Sat, May 9, 2009 at 7:26 PM, Oblivian <ch...@carlsoncentral.com> wrote:
>
> basicDemographicInfo.gender is a String
> and
> genders is List<Gender>
>
>
> John Krasnay wrote:
>>
>> What is the type of the "gender" property of BasicDemographicInfo?
>>
>> jk
>>
>> On Sat, May 09, 2009 at 12:39:58PM -0700, Oblivian wrote:
>>>
>>> Not sure what I'm doing wrong.  I need a DropDownChoice with ...
>>>
>>> <option value="f">Female</option>
>>> <option value="m">Male</option>
>>>
>>> have a basic class like this ...
>>>
>>> public class Gender  implements Serializable {
>>>      String id;
>>>      String name;
>>>      public Gender();
>>>      public Gender(String id, String name);
>>>      public String getId();
>>>      public void setId(String id);
>>>      public void setName(String name);
>>> }
>>>
>>> A custom ChoiceRenderer ...
>>>
>>> public class GenderChoiceRenderer implements IChoiceRenderer {
>>>      public Object getDisplayValue(Object arg0) {
>>>              return  ((Gender) arg0).getName();
>>>      }
>>>
>>>      public String getIdValue(Object arg0, int arg1) {
>>>              // Sometimes this is a String
>>>              if(arg0 instanceof String){
>>>                      return (String)arg0;
>>>              }
>>>              if (Utility.isNull(arg0)){
>>>                      return null;
>>>
>>>              }
>>>              // Other times it is not.
>>>              return ((Gender) arg0).getId();
>>>      }
>>>
>>> }
>>>
>>> ----------
>>> Finally in my Form...
>>>
>>> add(new DropDownChoice("gender", new PropertyModel(model,
>>> "basicDemographicInfo.gender"), genders, new GenderChoiceRender()));
>>>
>>>
>>> Viewing the HTML, the id's are correct "m" and "f", however in onSubmit,
>>> I
>>> get this.
>>>
>>> model.getBasicDemographicInfo().getGender() =
>>> com.spinn.sdk.db.model.Gender@30ea3e3c
>>>
>>>
>>>
>>>
>>>
>>> Oblivian wrote:
>>> >
>>> >  List test = Arrays.asList(new String[] { "A", "B", "C" });
>>> >  add(new DropDownChoice("test", test));
>>> >
>>> > How can I make the Id's match the Values?  There coming through as
>>> > 1,2,3.  I've tried custom ChoiceRenderer, but seem to be missing
>>> > something.
>>> >
>>> > Any help is appreciated.
>>> >
>>> > ---------------------------------------------------------------------
>>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> > For additional commands, e-mail: users-help@wicket.apache.org
>>> >
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23463880.html
>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23466542.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice ID's

Posted by Oblivian <ch...@carlsoncentral.com>.
basicDemographicInfo.gender is a String
and
genders is List<Gender> 


John Krasnay wrote:
> 
> What is the type of the "gender" property of BasicDemographicInfo?
> 
> jk
> 
> On Sat, May 09, 2009 at 12:39:58PM -0700, Oblivian wrote:
>> 
>> Not sure what I'm doing wrong.  I need a DropDownChoice with ...
>> 
>> <option value="f">Female</option>
>> <option value="m">Male</option>
>> 
>> have a basic class like this ...
>> 
>> public class Gender  implements Serializable {
>> 	String id;
>> 	String name;
>> 	public Gender();
>> 	public Gender(String id, String name);
>> 	public String getId();
>> 	public void setId(String id);
>> 	public void setName(String name);
>> }
>> 
>> A custom ChoiceRenderer ...
>> 
>> public class GenderChoiceRenderer implements IChoiceRenderer {
>> 	public Object getDisplayValue(Object arg0) {
>> 		return  ((Gender) arg0).getName();
>> 	}
>> 
>> 	public String getIdValue(Object arg0, int arg1) {
>> 		// Sometimes this is a String
>> 		if(arg0 instanceof String){
>> 			return (String)arg0;
>> 		}
>> 		if (Utility.isNull(arg0)){
>> 			return null;
>> 
>> 		}
>> 		// Other times it is not.
>> 		return ((Gender) arg0).getId();
>> 	}
>> 
>> }
>> 
>> ----------
>> Finally in my Form...
>> 
>> add(new DropDownChoice("gender", new PropertyModel(model,
>> "basicDemographicInfo.gender"), genders, new GenderChoiceRender()));
>> 
>> 
>> Viewing the HTML, the id's are correct "m" and "f", however in onSubmit,
>> I
>> get this.
>> 
>> model.getBasicDemographicInfo().getGender() =
>> com.spinn.sdk.db.model.Gender@30ea3e3c
>> 
>> 
>> 
>> 
>> 
>> Oblivian wrote:
>> > 
>> >  List test = Arrays.asList(new String[] { "A", "B", "C" });
>> >  add(new DropDownChoice("test", test));
>> > 
>> > How can I make the Id's match the Values?  There coming through as 
>> > 1,2,3.  I've tried custom ChoiceRenderer, but seem to be missing
>> > something.
>> > 
>> > Any help is appreciated.
>> > 
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> > 
>> > 
>> > 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23463880.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23466542.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice ID's

Posted by Oblivian <ch...@carlsoncentral.com>.
I was missing the fact the values are looked up.  Your right, I do not care
if the values are 1,2,3... as long as I get the right stuff in my Model



John Krasnay wrote:
> 
> Why do you care what the id's are? Wicket doesn't store the ID anywhere,
> it just uses the ID to look up the list element to put into the model.
> 
> jk
> 
> On Sun, May 10, 2009 at 08:08:30AM -0700, Oblivian wrote:
>> 
>> After changing genders from List<Gender> to List<String>, I'm seeing the
>> opposite behaviour.  The values are coming across as ['m','f'] but the
>> id's
>> are ['0','1']
>> 
>> Overriding getIdValues() instead of getDisplayValues() seems to work.
>> 
>> 
>> John Krasnay wrote:
>> > 
>> > The golden rule of DropDownChoice is that the values in the list must
>> be
>> > the same as the property you are trying to set. In your case, if you
>> > want basicDemographicInfo.gender to be set to "m" or "f", you must pass
>> > the DropDownChoice the list [ "m", "f" ]. You'll then need a renderer
>> > that produces the appropriate display value:
>> > 
>> > new ChoiceRender() {
>> >     public Object getDisplayValue(Object value) {
>> >         // here, value will be "m" or "f"
>> >         // look up and return "Male" or "Female" accordingly
>> >     }
>> > }
>> > 
>> > You shouldn't care about the ID value. The default provided by
>> > ChoiceRenderer should be fine.
>> > 
>> > jk
>> > 
>> > On Sat, May 09, 2009 at 05:52:29PM -0700, Oblivian wrote:
>> >> 
>> >> basicDemographicInfo.gender is a String 
>> >> and 
>> >> genders is List<String>
>> >> 
>> >> 
>> >> 
>> >> John Krasnay wrote:
>> >> > 
>> >> > What is the type of the "gender" property of BasicDemographicInfo?
>> >> > 
>> >> > jk
>> >> > 
>> >> > On Sat, May 09, 2009 at 12:39:58PM -0700, Oblivian wrote:
>> >> >> 
>> >> >> Not sure what I'm doing wrong.  I need a DropDownChoice with ...
>> >> >> 
>> >> >> <option value="f">Female</option>
>> >> >> <option value="m">Male</option>
>> >> >> 
>> >> >> have a basic class like this ...
>> >> >> 
>> >> >> public class Gender  implements Serializable {
>> >> >> 	String id;
>> >> >> 	String name;
>> >> >> 	public Gender();
>> >> >> 	public Gender(String id, String name);
>> >> >> 	public String getId();
>> >> >> 	public void setId(String id);
>> >> >> 	public void setName(String name);
>> >> >> }
>> >> >> 
>> >> >> A custom ChoiceRenderer ...
>> >> >> 
>> >> >> public class GenderChoiceRenderer implements IChoiceRenderer {
>> >> >> 	public Object getDisplayValue(Object arg0) {
>> >> >> 		return  ((Gender) arg0).getName();
>> >> >> 	}
>> >> >> 
>> >> >> 	public String getIdValue(Object arg0, int arg1) {
>> >> >> 		// Sometimes this is a String
>> >> >> 		if(arg0 instanceof String){
>> >> >> 			return (String)arg0;
>> >> >> 		}
>> >> >> 		if (Utility.isNull(arg0)){
>> >> >> 			return null;
>> >> >> 
>> >> >> 		}
>> >> >> 		// Other times it is not.
>> >> >> 		return ((Gender) arg0).getId();
>> >> >> 	}
>> >> >> 
>> >> >> }
>> >> >> 
>> >> >> ----------
>> >> >> Finally in my Form...
>> >> >> 
>> >> >> add(new DropDownChoice("gender", new PropertyModel(model,
>> >> >> "basicDemographicInfo.gender"), genders, new
>> GenderChoiceRender()));
>> >> >> 
>> >> >> 
>> >> >> Viewing the HTML, the id's are correct "m" and "f", however in
>> >> onSubmit,
>> >> >> I
>> >> >> get this.
>> >> >> 
>> >> >> model.getBasicDemographicInfo().getGender() =
>> >> >> com.spinn.sdk.db.model.Gender@30ea3e3c
>> >> >> 
>> >> >> 
>> >> >> 
>> >> >> 
>> >> >> 
>> >> >> Oblivian wrote:
>> >> >> > 
>> >> >> >  List test = Arrays.asList(new String[] { "A", "B", "C" });
>> >> >> >  add(new DropDownChoice("test", test));
>> >> >> > 
>> >> >> > How can I make the Id's match the Values?  There coming through
>> as 
>> >> >> > 1,2,3.  I've tried custom ChoiceRenderer, but seem to be missing
>> >> >> > something.
>> >> >> > 
>> >> >> > Any help is appreciated.
>> >> >> > 
>> >> >> >
>> >> ---------------------------------------------------------------------
>> >> >> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> >> > For additional commands, e-mail: users-help@wicket.apache.org
>> >> >> > 
>> >> >> > 
>> >> >> > 
>> >> >> 
>> >> >> -- 
>> >> >> View this message in context:
>> >> >>
>> http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23463880.html
>> >> >> Sent from the Wicket - User mailing list archive at Nabble.com.
>> >> >> 
>> >> >> 
>> >> >>
>> ---------------------------------------------------------------------
>> >> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >> >> 
>> >> > 
>> >> >
>> ---------------------------------------------------------------------
>> >> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> > For additional commands, e-mail: users-help@wicket.apache.org
>> >> > 
>> >> > 
>> >> > 
>> >> 
>> >> -- 
>> >> View this message in context:
>> >> http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23466101.html
>> >> Sent from the Wicket - User mailing list archive at Nabble.com.
>> >> 
>> >> 
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >> 
>> > 
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> > 
>> > 
>> > 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23470952.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23494051.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice ID's

Posted by John Krasnay <jo...@krasnay.ca>.
Why do you care what the id's are? Wicket doesn't store the ID anywhere,
it just uses the ID to look up the list element to put into the model.

jk

On Sun, May 10, 2009 at 08:08:30AM -0700, Oblivian wrote:
> 
> After changing genders from List<Gender> to List<String>, I'm seeing the
> opposite behaviour.  The values are coming across as ['m','f'] but the id's
> are ['0','1']
> 
> Overriding getIdValues() instead of getDisplayValues() seems to work.
> 
> 
> John Krasnay wrote:
> > 
> > The golden rule of DropDownChoice is that the values in the list must be
> > the same as the property you are trying to set. In your case, if you
> > want basicDemographicInfo.gender to be set to "m" or "f", you must pass
> > the DropDownChoice the list [ "m", "f" ]. You'll then need a renderer
> > that produces the appropriate display value:
> > 
> > new ChoiceRender() {
> >     public Object getDisplayValue(Object value) {
> >         // here, value will be "m" or "f"
> >         // look up and return "Male" or "Female" accordingly
> >     }
> > }
> > 
> > You shouldn't care about the ID value. The default provided by
> > ChoiceRenderer should be fine.
> > 
> > jk
> > 
> > On Sat, May 09, 2009 at 05:52:29PM -0700, Oblivian wrote:
> >> 
> >> basicDemographicInfo.gender is a String 
> >> and 
> >> genders is List<String>
> >> 
> >> 
> >> 
> >> John Krasnay wrote:
> >> > 
> >> > What is the type of the "gender" property of BasicDemographicInfo?
> >> > 
> >> > jk
> >> > 
> >> > On Sat, May 09, 2009 at 12:39:58PM -0700, Oblivian wrote:
> >> >> 
> >> >> Not sure what I'm doing wrong.  I need a DropDownChoice with ...
> >> >> 
> >> >> <option value="f">Female</option>
> >> >> <option value="m">Male</option>
> >> >> 
> >> >> have a basic class like this ...
> >> >> 
> >> >> public class Gender  implements Serializable {
> >> >> 	String id;
> >> >> 	String name;
> >> >> 	public Gender();
> >> >> 	public Gender(String id, String name);
> >> >> 	public String getId();
> >> >> 	public void setId(String id);
> >> >> 	public void setName(String name);
> >> >> }
> >> >> 
> >> >> A custom ChoiceRenderer ...
> >> >> 
> >> >> public class GenderChoiceRenderer implements IChoiceRenderer {
> >> >> 	public Object getDisplayValue(Object arg0) {
> >> >> 		return  ((Gender) arg0).getName();
> >> >> 	}
> >> >> 
> >> >> 	public String getIdValue(Object arg0, int arg1) {
> >> >> 		// Sometimes this is a String
> >> >> 		if(arg0 instanceof String){
> >> >> 			return (String)arg0;
> >> >> 		}
> >> >> 		if (Utility.isNull(arg0)){
> >> >> 			return null;
> >> >> 
> >> >> 		}
> >> >> 		// Other times it is not.
> >> >> 		return ((Gender) arg0).getId();
> >> >> 	}
> >> >> 
> >> >> }
> >> >> 
> >> >> ----------
> >> >> Finally in my Form...
> >> >> 
> >> >> add(new DropDownChoice("gender", new PropertyModel(model,
> >> >> "basicDemographicInfo.gender"), genders, new GenderChoiceRender()));
> >> >> 
> >> >> 
> >> >> Viewing the HTML, the id's are correct "m" and "f", however in
> >> onSubmit,
> >> >> I
> >> >> get this.
> >> >> 
> >> >> model.getBasicDemographicInfo().getGender() =
> >> >> com.spinn.sdk.db.model.Gender@30ea3e3c
> >> >> 
> >> >> 
> >> >> 
> >> >> 
> >> >> 
> >> >> Oblivian wrote:
> >> >> > 
> >> >> >  List test = Arrays.asList(new String[] { "A", "B", "C" });
> >> >> >  add(new DropDownChoice("test", test));
> >> >> > 
> >> >> > How can I make the Id's match the Values?  There coming through as 
> >> >> > 1,2,3.  I've tried custom ChoiceRenderer, but seem to be missing
> >> >> > something.
> >> >> > 
> >> >> > Any help is appreciated.
> >> >> > 
> >> >> >
> >> ---------------------------------------------------------------------
> >> >> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> >> > For additional commands, e-mail: users-help@wicket.apache.org
> >> >> > 
> >> >> > 
> >> >> > 
> >> >> 
> >> >> -- 
> >> >> View this message in context:
> >> >> http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23463880.html
> >> >> Sent from the Wicket - User mailing list archive at Nabble.com.
> >> >> 
> >> >> 
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> >> For additional commands, e-mail: users-help@wicket.apache.org
> >> >> 
> >> > 
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> > For additional commands, e-mail: users-help@wicket.apache.org
> >> > 
> >> > 
> >> > 
> >> 
> >> -- 
> >> View this message in context:
> >> http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23466101.html
> >> Sent from the Wicket - User mailing list archive at Nabble.com.
> >> 
> >> 
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >> 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> > 
> > 
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23470952.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice ID's

Posted by Oblivian <ch...@carlsoncentral.com>.
After changing genders from List<Gender> to List<String>, I'm seeing the
opposite behaviour.  The values are coming across as ['m','f'] but the id's
are ['0','1']

Overriding getIdValues() instead of getDisplayValues() seems to work.


John Krasnay wrote:
> 
> The golden rule of DropDownChoice is that the values in the list must be
> the same as the property you are trying to set. In your case, if you
> want basicDemographicInfo.gender to be set to "m" or "f", you must pass
> the DropDownChoice the list [ "m", "f" ]. You'll then need a renderer
> that produces the appropriate display value:
> 
> new ChoiceRender() {
>     public Object getDisplayValue(Object value) {
>         // here, value will be "m" or "f"
>         // look up and return "Male" or "Female" accordingly
>     }
> }
> 
> You shouldn't care about the ID value. The default provided by
> ChoiceRenderer should be fine.
> 
> jk
> 
> On Sat, May 09, 2009 at 05:52:29PM -0700, Oblivian wrote:
>> 
>> basicDemographicInfo.gender is a String 
>> and 
>> genders is List<String>
>> 
>> 
>> 
>> John Krasnay wrote:
>> > 
>> > What is the type of the "gender" property of BasicDemographicInfo?
>> > 
>> > jk
>> > 
>> > On Sat, May 09, 2009 at 12:39:58PM -0700, Oblivian wrote:
>> >> 
>> >> Not sure what I'm doing wrong.  I need a DropDownChoice with ...
>> >> 
>> >> <option value="f">Female</option>
>> >> <option value="m">Male</option>
>> >> 
>> >> have a basic class like this ...
>> >> 
>> >> public class Gender  implements Serializable {
>> >> 	String id;
>> >> 	String name;
>> >> 	public Gender();
>> >> 	public Gender(String id, String name);
>> >> 	public String getId();
>> >> 	public void setId(String id);
>> >> 	public void setName(String name);
>> >> }
>> >> 
>> >> A custom ChoiceRenderer ...
>> >> 
>> >> public class GenderChoiceRenderer implements IChoiceRenderer {
>> >> 	public Object getDisplayValue(Object arg0) {
>> >> 		return  ((Gender) arg0).getName();
>> >> 	}
>> >> 
>> >> 	public String getIdValue(Object arg0, int arg1) {
>> >> 		// Sometimes this is a String
>> >> 		if(arg0 instanceof String){
>> >> 			return (String)arg0;
>> >> 		}
>> >> 		if (Utility.isNull(arg0)){
>> >> 			return null;
>> >> 
>> >> 		}
>> >> 		// Other times it is not.
>> >> 		return ((Gender) arg0).getId();
>> >> 	}
>> >> 
>> >> }
>> >> 
>> >> ----------
>> >> Finally in my Form...
>> >> 
>> >> add(new DropDownChoice("gender", new PropertyModel(model,
>> >> "basicDemographicInfo.gender"), genders, new GenderChoiceRender()));
>> >> 
>> >> 
>> >> Viewing the HTML, the id's are correct "m" and "f", however in
>> onSubmit,
>> >> I
>> >> get this.
>> >> 
>> >> model.getBasicDemographicInfo().getGender() =
>> >> com.spinn.sdk.db.model.Gender@30ea3e3c
>> >> 
>> >> 
>> >> 
>> >> 
>> >> 
>> >> Oblivian wrote:
>> >> > 
>> >> >  List test = Arrays.asList(new String[] { "A", "B", "C" });
>> >> >  add(new DropDownChoice("test", test));
>> >> > 
>> >> > How can I make the Id's match the Values?  There coming through as 
>> >> > 1,2,3.  I've tried custom ChoiceRenderer, but seem to be missing
>> >> > something.
>> >> > 
>> >> > Any help is appreciated.
>> >> > 
>> >> >
>> ---------------------------------------------------------------------
>> >> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> > For additional commands, e-mail: users-help@wicket.apache.org
>> >> > 
>> >> > 
>> >> > 
>> >> 
>> >> -- 
>> >> View this message in context:
>> >> http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23463880.html
>> >> Sent from the Wicket - User mailing list archive at Nabble.com.
>> >> 
>> >> 
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >> 
>> > 
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> > 
>> > 
>> > 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23466101.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23470952.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice ID's

Posted by John Krasnay <jo...@krasnay.ca>.
The golden rule of DropDownChoice is that the values in the list must be
the same as the property you are trying to set. In your case, if you
want basicDemographicInfo.gender to be set to "m" or "f", you must pass
the DropDownChoice the list [ "m", "f" ]. You'll then need a renderer
that produces the appropriate display value:

new ChoiceRender() {
    public Object getDisplayValue(Object value) {
        // here, value will be "m" or "f"
        // look up and return "Male" or "Female" accordingly
    }
}

You shouldn't care about the ID value. The default provided by
ChoiceRenderer should be fine.

jk

On Sat, May 09, 2009 at 05:52:29PM -0700, Oblivian wrote:
> 
> basicDemographicInfo.gender is a String 
> and 
> genders is List<String>
> 
> 
> 
> John Krasnay wrote:
> > 
> > What is the type of the "gender" property of BasicDemographicInfo?
> > 
> > jk
> > 
> > On Sat, May 09, 2009 at 12:39:58PM -0700, Oblivian wrote:
> >> 
> >> Not sure what I'm doing wrong.  I need a DropDownChoice with ...
> >> 
> >> <option value="f">Female</option>
> >> <option value="m">Male</option>
> >> 
> >> have a basic class like this ...
> >> 
> >> public class Gender  implements Serializable {
> >> 	String id;
> >> 	String name;
> >> 	public Gender();
> >> 	public Gender(String id, String name);
> >> 	public String getId();
> >> 	public void setId(String id);
> >> 	public void setName(String name);
> >> }
> >> 
> >> A custom ChoiceRenderer ...
> >> 
> >> public class GenderChoiceRenderer implements IChoiceRenderer {
> >> 	public Object getDisplayValue(Object arg0) {
> >> 		return  ((Gender) arg0).getName();
> >> 	}
> >> 
> >> 	public String getIdValue(Object arg0, int arg1) {
> >> 		// Sometimes this is a String
> >> 		if(arg0 instanceof String){
> >> 			return (String)arg0;
> >> 		}
> >> 		if (Utility.isNull(arg0)){
> >> 			return null;
> >> 
> >> 		}
> >> 		// Other times it is not.
> >> 		return ((Gender) arg0).getId();
> >> 	}
> >> 
> >> }
> >> 
> >> ----------
> >> Finally in my Form...
> >> 
> >> add(new DropDownChoice("gender", new PropertyModel(model,
> >> "basicDemographicInfo.gender"), genders, new GenderChoiceRender()));
> >> 
> >> 
> >> Viewing the HTML, the id's are correct "m" and "f", however in onSubmit,
> >> I
> >> get this.
> >> 
> >> model.getBasicDemographicInfo().getGender() =
> >> com.spinn.sdk.db.model.Gender@30ea3e3c
> >> 
> >> 
> >> 
> >> 
> >> 
> >> Oblivian wrote:
> >> > 
> >> >  List test = Arrays.asList(new String[] { "A", "B", "C" });
> >> >  add(new DropDownChoice("test", test));
> >> > 
> >> > How can I make the Id's match the Values?  There coming through as 
> >> > 1,2,3.  I've tried custom ChoiceRenderer, but seem to be missing
> >> > something.
> >> > 
> >> > Any help is appreciated.
> >> > 
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> > For additional commands, e-mail: users-help@wicket.apache.org
> >> > 
> >> > 
> >> > 
> >> 
> >> -- 
> >> View this message in context:
> >> http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23463880.html
> >> Sent from the Wicket - User mailing list archive at Nabble.com.
> >> 
> >> 
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >> 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> > 
> > 
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23466101.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice ID's

Posted by Oblivian <ch...@carlsoncentral.com>.
basicDemographicInfo.gender is a String 
and 
genders is List<String>



John Krasnay wrote:
> 
> What is the type of the "gender" property of BasicDemographicInfo?
> 
> jk
> 
> On Sat, May 09, 2009 at 12:39:58PM -0700, Oblivian wrote:
>> 
>> Not sure what I'm doing wrong.  I need a DropDownChoice with ...
>> 
>> <option value="f">Female</option>
>> <option value="m">Male</option>
>> 
>> have a basic class like this ...
>> 
>> public class Gender  implements Serializable {
>> 	String id;
>> 	String name;
>> 	public Gender();
>> 	public Gender(String id, String name);
>> 	public String getId();
>> 	public void setId(String id);
>> 	public void setName(String name);
>> }
>> 
>> A custom ChoiceRenderer ...
>> 
>> public class GenderChoiceRenderer implements IChoiceRenderer {
>> 	public Object getDisplayValue(Object arg0) {
>> 		return  ((Gender) arg0).getName();
>> 	}
>> 
>> 	public String getIdValue(Object arg0, int arg1) {
>> 		// Sometimes this is a String
>> 		if(arg0 instanceof String){
>> 			return (String)arg0;
>> 		}
>> 		if (Utility.isNull(arg0)){
>> 			return null;
>> 
>> 		}
>> 		// Other times it is not.
>> 		return ((Gender) arg0).getId();
>> 	}
>> 
>> }
>> 
>> ----------
>> Finally in my Form...
>> 
>> add(new DropDownChoice("gender", new PropertyModel(model,
>> "basicDemographicInfo.gender"), genders, new GenderChoiceRender()));
>> 
>> 
>> Viewing the HTML, the id's are correct "m" and "f", however in onSubmit,
>> I
>> get this.
>> 
>> model.getBasicDemographicInfo().getGender() =
>> com.spinn.sdk.db.model.Gender@30ea3e3c
>> 
>> 
>> 
>> 
>> 
>> Oblivian wrote:
>> > 
>> >  List test = Arrays.asList(new String[] { "A", "B", "C" });
>> >  add(new DropDownChoice("test", test));
>> > 
>> > How can I make the Id's match the Values?  There coming through as 
>> > 1,2,3.  I've tried custom ChoiceRenderer, but seem to be missing
>> > something.
>> > 
>> > Any help is appreciated.
>> > 
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> > 
>> > 
>> > 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23463880.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23466101.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice ID's

Posted by John Krasnay <jo...@krasnay.ca>.
What is the type of the "gender" property of BasicDemographicInfo?

jk

On Sat, May 09, 2009 at 12:39:58PM -0700, Oblivian wrote:
> 
> Not sure what I'm doing wrong.  I need a DropDownChoice with ...
> 
> <option value="f">Female</option>
> <option value="m">Male</option>
> 
> have a basic class like this ...
> 
> public class Gender  implements Serializable {
> 	String id;
> 	String name;
> 	public Gender();
> 	public Gender(String id, String name);
> 	public String getId();
> 	public void setId(String id);
> 	public void setName(String name);
> }
> 
> A custom ChoiceRenderer ...
> 
> public class GenderChoiceRenderer implements IChoiceRenderer {
> 	public Object getDisplayValue(Object arg0) {
> 		return  ((Gender) arg0).getName();
> 	}
> 
> 	public String getIdValue(Object arg0, int arg1) {
> 		// Sometimes this is a String
> 		if(arg0 instanceof String){
> 			return (String)arg0;
> 		}
> 		if (Utility.isNull(arg0)){
> 			return null;
> 
> 		}
> 		// Other times it is not.
> 		return ((Gender) arg0).getId();
> 	}
> 
> }
> 
> ----------
> Finally in my Form...
> 
> add(new DropDownChoice("gender", new PropertyModel(model,
> "basicDemographicInfo.gender"), genders, new GenderChoiceRender()));
> 
> 
> Viewing the HTML, the id's are correct "m" and "f", however in onSubmit, I
> get this.
> 
> model.getBasicDemographicInfo().getGender() =
> com.spinn.sdk.db.model.Gender@30ea3e3c
> 
> 
> 
> 
> 
> Oblivian wrote:
> > 
> >  List test = Arrays.asList(new String[] { "A", "B", "C" });
> >  add(new DropDownChoice("test", test));
> > 
> > How can I make the Id's match the Values?  There coming through as 
> > 1,2,3.  I've tried custom ChoiceRenderer, but seem to be missing
> > something.
> > 
> > Any help is appreciated.
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> > 
> > 
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23463880.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DropDownChoice ID's

Posted by Oblivian <ch...@carlsoncentral.com>.
Not sure what I'm doing wrong.  I need a DropDownChoice with ...

<option value="f">Female</option>
<option value="m">Male</option>

have a basic class like this ...

public class Gender  implements Serializable {
	String id;
	String name;
	public Gender();
	public Gender(String id, String name);
	public String getId();
	public void setId(String id);
	public void setName(String name);
}

A custom ChoiceRenderer ...

public class GenderChoiceRenderer implements IChoiceRenderer {
	public Object getDisplayValue(Object arg0) {
		return  ((Gender) arg0).getName();
	}

	public String getIdValue(Object arg0, int arg1) {
		// Sometimes this is a String
		if(arg0 instanceof String){
			return (String)arg0;
		}
		if (Utility.isNull(arg0)){
			return null;

		}
		// Other times it is not.
		return ((Gender) arg0).getId();
	}

}

----------
Finally in my Form...

add(new DropDownChoice("gender", new PropertyModel(model,
"basicDemographicInfo.gender"), genders, new GenderChoiceRender()));


Viewing the HTML, the id's are correct "m" and "f", however in onSubmit, I
get this.

model.getBasicDemographicInfo().getGender() =
com.spinn.sdk.db.model.Gender@30ea3e3c





Oblivian wrote:
> 
>  List test = Arrays.asList(new String[] { "A", "B", "C" });
>  add(new DropDownChoice("test", test));
> 
> How can I make the Id's match the Values?  There coming through as 
> 1,2,3.  I've tried custom ChoiceRenderer, but seem to be missing
> something.
> 
> Any help is appreciated.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice-ID%27s-tp23453868p23463880.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org