you are passing a list of enum objects into the list model of the dropdown
choice, that means the one selected object out of that list - of type enum -
will be set into the model object.

so there are two ways to do this

you can pass in a list of ints into the choice component, that way the
selected int will be set into your model

or you can write a model decorator that does the transform

class SizeEnumToIntModel extends Model {
  private final IModel delegate;
  public SizeEnumToIntModel(IModel delegate) {
        this.delegate=delegate; }

 public Object getObject(Component c) {return Size.forValue(
delegate.getObject(c); // convert int to enum }
 public void setObject(Component c, Object o) {
delegate.setObject(((Size)o).getintvalue();
// convert enum to int }
 public void detach() {  delegate.detach(); }
}

then

new DropDownChoice(id, new SizeEnumToIntModel(new PropertyModel(form,
"size"))....

you lose the nice compound model syntax, but oh well

you might also be able to use a convert to accomplish the same, but i havent
looked into that


-igor

On 12/30/06, Flavius <[EMAIL PROTECTED]> wrote:



I tried this:

                        DropDownChoice severityChoice = new
DropDownChoice("size",
                        Arrays.asList(SIZE.values()),
                        new ChoiceRenderer()
                        {
                                public Object getDisplayValue(Object
object)
                                {
                                        return ((SIZE)object).getName();
                                }

                                public String getIdValue(Object object,
int index)
                                {
                                        return ((SIZE)object).getId();
                                }
                        });

The page renders fine.  But when I submit the form, I get this error:

WicketMessage: unable to set object Small, model:
Model:classname=[wicket.model.CompoundPropertyModel]

Root cause:

wicket.util.convert.ConversionException: Cannot parse 'Small' using format
[EMAIL PROTECTED]
at
wicket.util.convert.converters.AbstractConverter.newConversionException(
AbstractConverter.java:72)

As I understand it, it's trying to set an int in the Shirt model for size,
but the drop down returned the Small object.  What I really need is
Small.getId().  So I need to tell the form to bind the id property of the
return object to the field "size"




Nick Heudecker wrote:
>
> IChoiceRenderer allows you to specify the id and display values for a
> DropDownChoice.  It's exactly what you're looking for.  To explain a
bit:
>
> getDisplayValue(...) - returns the value you want the user to see.
> "Small",
> "Medium", etc.  This is where you'd return SIZE.getName().
> getIdValue(...) returns the value submitted to the application.  This is
> where you'd return SIZE.getId().
>
>

--
View this message in context:
http://www.nabble.com/DropDownChoice-binding-question-tf2900580.html#a8104039
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
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

-------------------------------------------------------------------------
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
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to