It returns exactly what you have in your list... that's a String "choice1",
"choice2", etc.
The integer values in the options are used by wicket internally.

If you want to apply integer identifers to your labels you should use a
custom object instead of Strings to feed your DropDownChoice, e.g. let this
custom class have a getValue() and get getLabel() method and use new
ChoiceRenderer("value","label") as 4th argument to DropDownChoice.
This way, you also have 100% control, which value is applied to which label.

HTH



m_salman wrote:
> 
> 
> Hi,
> 
> For a DropDownChoice I am using a simple list as following:
> 
>       List<String> choices = new LinkedList<String>();
>       choices.add("choice1");
>       choices.add("choice2");
> 
> 
> Here is the code for the DropDownChoice:
> 
>       add(new DropDownChoice<String>(
>                       "dropDownField", 
>                       new PropertyModel<String>(bean, "value"),  
>                       bean.getChoices(), // List of choices
>                       new ChoiceRenderer()));
> 
> 
> I want to get the index number of the list as the "value".  That is, if
> "choice1" is selected I should get 0, and if "choice2" is selected  I
> should get 1.
> 
> 
> I do see that in th generated html the values are set as "0", "1"
> 
> <select name="fieldPanels:3:fieldPanel:dropDownField"
> wicket:id="dropDownField">
>       <option selected="selected" value="">Choose One</option>
>       <option value="0">choice1</option>
>       <option value="1">choice2</option>
> </select>
>           
> 
> But for some reason I keep getting "choice1" or "choice2" as the returned
> values instead of "0" or "1".
> 
> I have also tried 
> 
>               IChoiceRenderer choiceRenderer = new IChoiceRenderer() 
>               {
>                       public String getIdValue(Object object, int index) 
>                       {
>                               return ""+index;
>                               //return object.toString();
>                       }
>                       
>                       public Object getDisplayValue(Object object) 
>                       {
>                               String string = (String) object;
>                               return string;
>                       }
>               };
> But this does not work either.
> 
> Any idea what might be wrong here and why it is not working.
> 
> I am using 1.4 version.
> 
> Thanks.
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/getting-the-list%27s-index-value-for-selection-in-DropDownChoice-tp18626007p18630905.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to