Thank you very much. Your explanation cleared things up for me and solved my
problem.
Peter
Johan Compagner wrote:
>
> to quickly do it right in your example:
>
> you should do it in reverse.
>
> so this:
>
> for(;i<ids.length;i++)
> choices.add(values[i]);
>
> should be
>
> for(;i<ids.length;i++)
> choices.add(ids[i]);
>
>
> so the id's are the valules/choices not the display values. Thats done in
> the choicerenderer:
>
> public Object getDisplayValue(Object obj) {
> // obj == id, lookup id in id array then return value out of
> value array.
> }
>
> public String getIdValue(Object obj, int i) {
> return obj; // obj == the id
> }
>
>
> hopefully this will make it also more clear to other people, because this
> question does popup again and again. :(
> To many people come from the Swing world, with its Cell renderers :(
>
> johan
>
>
>
>> public class DateDropDownChoice extends DropDownChoice implements
>> Serializable {
>> // values to go into the hidden value attribute in the HTML option
>> tag
>> // AND to go into the model/database
>> final static private String[] ids =
>> {"20031","20032","20033","20034","20041",…};
>>
>> // values to be displayed in the dropdown
>> final static private String[] values ={"2003, Fall","2003,
>> Winter","2003, Spring","2003, Summer","2004, Fall",…};
>>
>> public DateDropDownChoice(String id, IModel iModel) {
>> super(id, iModel);
>> ArrayList choices = new ArrayList();
>>
>> int i = 0;
>> for(;i<ids.length;i++)
>> // choices.add(new DateChoice(ids[i],values[i]));
>> choices.add(values[i]);
>>
>> this.setChoices(choices);
>> this.setChoiceRenderer(new CustomChoiceRenderer());
>> }
>>
>>
>>
>> class CustomChoiceRenderer implements IChoiceRenderer{
>>
>>
>> public Object getDisplayValue(Object obj) {
>> return obj.toString();
>> }
>>
>> public String getIdValue(Object obj, int i) {
>>
>> /**
>> * An "i" of -1 is passed when a previous selection
>> * has been made and is stored, so just return the obj string
>> value
>> * because it is a properly stored value such as "20063" from
>> the previous submission
>> *
>> * An "i" > 0 means that I need to look up the
>> appropriate/corresponding
>> * value from the ids array.
>> *
>> */
>>
>> String returnVal = i<0?obj.toString():ids[i];
>> System.out.println("returnVal: "+returnVal+" :: ID:: "+i);
>> return returnVal;
>> }
>> }
>> }
>>
>>
>>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Wicket-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
>
--
View this message in context:
http://www.nabble.com/DropDownChoice-inconsistent-value-returned-tf2971300.html#a8374726
Sent from the Wicket - User mailing list archive at Nabble.com.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user