ok, I see where you're going with this.
very cool.

My enum is in a helper class and I started writing conversion methods in the
helper class.  But I like the way you wrapped your conversion methods
 in a class to use on the Page class.

I also gave some thought last night to using a Map<Integer, String> with
the same conversion technique.  Then my dropdown uses Integers and
I can do a map.get() in getDisplayValue() for the String.

Thanks for your help, Igor.


igor.vaynberg wrote:
> 
> 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
> 
> 


-- 
View this message in context: 
http://www.nabble.com/DropDownChoice-binding-question-tf2900580.html#a8108551
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

Reply via email to