On Fri, 28 Oct 2005 10:03:53 -0700, Johan Compagner <[EMAIL PROTECTED]>
wrote:
<snip>
The id was not null!
Only when the selection is null and null is allowed Choose One is added.
This was the problem. I had changed the default from null to an empty
String in the model. That is why it stopped working.
<snip>
But what you could do is for example make getUSState() object on youre
model
that is looked up by for example hibernate as a 1-> N relation and code
is
the key..
Then you can do setUSState(USState) on youre object but the value stored
to
the database is ofcourse just the code
This is an approach I hadn't thought about.
Perhaps I don't understand the intended usage here.
It seems like the type of thing I want to do must be fairly common. Say
I
want to list US States by full name, but persist the abbreviation (code)
in my model. A map of Strings in the front end (display, value) to a
String in the model (value). Is there a simple way to do this?
Pretty simple
first:
What is youre selected object?
this is the code because you don't have setUSState/getUSState as
explained
above.
then make a list of the same things that can be selected, so in youre
case
the codes
Then make a choiceRenderer:
class StateChoiceRender
{
Map codesToStates
getDisplayValue(Object code, int index)
{
// the object is one of the code strings. you want to display the name
so in
this
return ((USStates)codesToNames.get(code)).getName();
}
getIdValue(Object code)
{
// the code string is directly the id value:
return code;
}
}
new DropDownChoice("usstate", LIST_OF_CODES, new StateChoiceRenderer())
then it works.
I think I understand. Following this example, I could do away with the
USState object altogether, and use a List of codes and a custom
ChoiceRenderer containing a Map. At this point, wouldn't it be easier if
there was a DropDownChoice that directly accepted a Map? I really only
care about moving a String around. I don't think that for this project
I'll ever really need a USState object, and the additional complexity it
brings, though it is nicer OO.
Thanks again. I appreciate all your help.
David
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user