Re: Checkbox and enum value

2008-09-26 Thread Cédric Thiébault
Thanks Igor, it was exactly what i needed :-)

To complete this post, here is the solution I found :
http://surunairdejava.blogspot.com/2008/09/wicket-checkbox-abstractcheckboxmodel.html

Sorry it's in french but the code is easy to understand...

Cedric


On Wed, Sep 24, 2008 at 2:46 PM, Igor Vaynberg [EMAIL PROTECTED] wrote:
 see abstractcheckboxmodel

 -igor

 On Wed, Sep 24, 2008 at 11:37 AM, Cédric Thiébault
 [EMAIL PROTECTED] wrote:
 Hi,

 I'm trying to use a checkbox to set an enum value on my form object
 but I always get a type mismatch error (boolean is not an enum and
 vice versa).

 My form object has an enum and I want to display a list of checkboxes
 to allow the user to select the value.
 I don't want to use a radio because my enum can be null and I can't
 unselect my radio group once a radio is selected.

 I tried to extends Checkbox to convert teh boolean to the specified
 enum... it works only in one way (to set the enum value) but it does
 not work when my enum has a value and the checkbox need to render
 itself (the value must be a boolean).


 public class CheckBoxEnum extends CheckBox {

  private final Enum? enumValue;

  public CheckBoxEnum(String id, IModel model, String property,
 Enum? enumValue) {
super(id, new PropertyModel(model, property));
this.enumValue = enumValue;
  }

  @Override
  protected void convertInput() {
String value = getValue();
if (value != null  BooleanUtils.toBoolean(value))
 setConvertedInput(enumValue);
  }
 }

 Any ideas ?

 Thanks

 Cedric

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



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



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



Re: Checkbox and enum value

2008-09-26 Thread francisco treacy
i'm sorry i didn't see this post before-- i came up with a solution a
couple of weeks ago.

i called it EnumCheckGroup (that is, i went for CheckGroup rather than
CheckBox).

usage:

for a given enum:

public static enum Niveau {
etage, mezzanine, sous_sol;
}

   form.add(new EnumCheckGroupPlan.Niveau(niveaux,
Plan.Niveau.values()));


  span wicket:id=niveaux
   span wicket:id=items
   input type=checkbox wicket:id=check /
   span wicket:id=label/spanbr /
   /span
   /span


impl:

public class EnumCheckGroupT extends EnumT extends CheckGroupT {

   public EnumCheckGroup(String id, T[] values) {
   super(id);

   ListViewT listview = new ListViewT(items,
Arrays.asList(values)) {
   protected void populateItem(ListItemT item) {
   item.add(new CheckT(check, item.getModel()));
   item.add(new Label(label, new
ResourceModel(item.getModelObject().name(;
   };
   }.setReuseItems(true);

   add(listview);

   }

}

obviously you must have the keys in your properties file, such as:

etage=Étage
mezzanine=Mezzanine
sous_sol=Sous-sol


francisco


On Fri, Sep 26, 2008 at 4:29 PM, Cédric Thiébault
[EMAIL PROTECTED] wrote:
 Thanks Igor, it was exactly what i needed :-)

 To complete this post, here is the solution I found :
 http://surunairdejava.blogspot.com/2008/09/wicket-checkbox-abstractcheckboxmodel.html

 Sorry it's in french but the code is easy to understand...

 Cedric


 On Wed, Sep 24, 2008 at 2:46 PM, Igor Vaynberg [EMAIL PROTECTED] wrote:
 see abstractcheckboxmodel

 -igor

 On Wed, Sep 24, 2008 at 11:37 AM, Cédric Thiébault
 [EMAIL PROTECTED] wrote:
 Hi,

 I'm trying to use a checkbox to set an enum value on my form object
 but I always get a type mismatch error (boolean is not an enum and
 vice versa).

 My form object has an enum and I want to display a list of checkboxes
 to allow the user to select the value.
 I don't want to use a radio because my enum can be null and I can't
 unselect my radio group once a radio is selected.

 I tried to extends Checkbox to convert teh boolean to the specified
 enum... it works only in one way (to set the enum value) but it does
 not work when my enum has a value and the checkbox need to render
 itself (the value must be a boolean).


 public class CheckBoxEnum extends CheckBox {

  private final Enum? enumValue;

  public CheckBoxEnum(String id, IModel model, String property,
 Enum? enumValue) {
super(id, new PropertyModel(model, property));
this.enumValue = enumValue;
  }

  @Override
  protected void convertInput() {
String value = getValue();
if (value != null  BooleanUtils.toBoolean(value))
 setConvertedInput(enumValue);
  }
 }

 Any ideas ?

 Thanks

 Cedric

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



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



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



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



Re: Checkbox and enum value

2008-09-26 Thread James Carman
Why not just pass the enum class into the constructor?  But, also have
one that allows you to provide a subset of enum values (as you already
have).


On Fri, Sep 26, 2008 at 4:43 PM, francisco treacy
[EMAIL PROTECTED] wrote:
 i'm sorry i didn't see this post before-- i came up with a solution a
 couple of weeks ago.

 i called it EnumCheckGroup (that is, i went for CheckGroup rather than
 CheckBox).

 usage:

 for a given enum:

public static enum Niveau {
etage, mezzanine, sous_sol;
}

   form.add(new EnumCheckGroupPlan.Niveau(niveaux,
 Plan.Niveau.values()));


  span wicket:id=niveaux
   span wicket:id=items
   input type=checkbox wicket:id=check /
   span wicket:id=label/spanbr /
   /span
   /span


 impl:

 public class EnumCheckGroupT extends EnumT extends CheckGroupT {

   public EnumCheckGroup(String id, T[] values) {
   super(id);

   ListViewT listview = new ListViewT(items,
 Arrays.asList(values)) {
   protected void populateItem(ListItemT item) {
   item.add(new CheckT(check, item.getModel()));
   item.add(new Label(label, new
 ResourceModel(item.getModelObject().name(;
   };
   }.setReuseItems(true);

   add(listview);

   }

 }

 obviously you must have the keys in your properties file, such as:

 etage=Étage
 mezzanine=Mezzanine
 sous_sol=Sous-sol


 francisco


 On Fri, Sep 26, 2008 at 4:29 PM, Cédric Thiébault
 [EMAIL PROTECTED] wrote:
 Thanks Igor, it was exactly what i needed :-)

 To complete this post, here is the solution I found :
 http://surunairdejava.blogspot.com/2008/09/wicket-checkbox-abstractcheckboxmodel.html

 Sorry it's in french but the code is easy to understand...

 Cedric


 On Wed, Sep 24, 2008 at 2:46 PM, Igor Vaynberg [EMAIL PROTECTED] wrote:
 see abstractcheckboxmodel

 -igor

 On Wed, Sep 24, 2008 at 11:37 AM, Cédric Thiébault
 [EMAIL PROTECTED] wrote:
 Hi,

 I'm trying to use a checkbox to set an enum value on my form object
 but I always get a type mismatch error (boolean is not an enum and
 vice versa).

 My form object has an enum and I want to display a list of checkboxes
 to allow the user to select the value.
 I don't want to use a radio because my enum can be null and I can't
 unselect my radio group once a radio is selected.

 I tried to extends Checkbox to convert teh boolean to the specified
 enum... it works only in one way (to set the enum value) but it does
 not work when my enum has a value and the checkbox need to render
 itself (the value must be a boolean).


 public class CheckBoxEnum extends CheckBox {

  private final Enum? enumValue;

  public CheckBoxEnum(String id, IModel model, String property,
 Enum? enumValue) {
super(id, new PropertyModel(model, property));
this.enumValue = enumValue;
  }

  @Override
  protected void convertInput() {
String value = getValue();
if (value != null  BooleanUtils.toBoolean(value))
 setConvertedInput(enumValue);
  }
 }

 Any ideas ?

 Thanks

 Cedric

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



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



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



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



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



Re: Checkbox and enum value

2008-09-26 Thread James Carman
Also, you could have a varargs feature so that users could specify
exactly what they want without having to instantiate an array.

On Fri, Sep 26, 2008 at 6:15 PM, James Carman
[EMAIL PROTECTED] wrote:
 Why not just pass the enum class into the constructor?  But, also have
 one that allows you to provide a subset of enum values (as you already
 have).


 On Fri, Sep 26, 2008 at 4:43 PM, francisco treacy
 [EMAIL PROTECTED] wrote:
 i'm sorry i didn't see this post before-- i came up with a solution a
 couple of weeks ago.

 i called it EnumCheckGroup (that is, i went for CheckGroup rather than
 CheckBox).

 usage:

 for a given enum:

public static enum Niveau {
etage, mezzanine, sous_sol;
}

   form.add(new EnumCheckGroupPlan.Niveau(niveaux,
 Plan.Niveau.values()));


  span wicket:id=niveaux
   span wicket:id=items
   input type=checkbox wicket:id=check /
   span wicket:id=label/spanbr /
   /span
   /span


 impl:

 public class EnumCheckGroupT extends EnumT extends CheckGroupT {

   public EnumCheckGroup(String id, T[] values) {
   super(id);

   ListViewT listview = new ListViewT(items,
 Arrays.asList(values)) {
   protected void populateItem(ListItemT item) {
   item.add(new CheckT(check, item.getModel()));
   item.add(new Label(label, new
 ResourceModel(item.getModelObject().name(;
   };
   }.setReuseItems(true);

   add(listview);

   }

 }

 obviously you must have the keys in your properties file, such as:

 etage=Étage
 mezzanine=Mezzanine
 sous_sol=Sous-sol


 francisco


 On Fri, Sep 26, 2008 at 4:29 PM, Cédric Thiébault
 [EMAIL PROTECTED] wrote:
 Thanks Igor, it was exactly what i needed :-)

 To complete this post, here is the solution I found :
 http://surunairdejava.blogspot.com/2008/09/wicket-checkbox-abstractcheckboxmodel.html

 Sorry it's in french but the code is easy to understand...

 Cedric


 On Wed, Sep 24, 2008 at 2:46 PM, Igor Vaynberg [EMAIL PROTECTED] wrote:
 see abstractcheckboxmodel

 -igor

 On Wed, Sep 24, 2008 at 11:37 AM, Cédric Thiébault
 [EMAIL PROTECTED] wrote:
 Hi,

 I'm trying to use a checkbox to set an enum value on my form object
 but I always get a type mismatch error (boolean is not an enum and
 vice versa).

 My form object has an enum and I want to display a list of checkboxes
 to allow the user to select the value.
 I don't want to use a radio because my enum can be null and I can't
 unselect my radio group once a radio is selected.

 I tried to extends Checkbox to convert teh boolean to the specified
 enum... it works only in one way (to set the enum value) but it does
 not work when my enum has a value and the checkbox need to render
 itself (the value must be a boolean).


 public class CheckBoxEnum extends CheckBox {

  private final Enum? enumValue;

  public CheckBoxEnum(String id, IModel model, String property,
 Enum? enumValue) {
super(id, new PropertyModel(model, property));
this.enumValue = enumValue;
  }

  @Override
  protected void convertInput() {
String value = getValue();
if (value != null  BooleanUtils.toBoolean(value))
 setConvertedInput(enumValue);
  }
 }

 Any ideas ?

 Thanks

 Cedric

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



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



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



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




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



Re: Checkbox and enum value

2008-09-26 Thread francisco treacy
 Also, you could have a varargs feature so that users could specify
 exactly what they want without having to instantiate an array.

yes, of course there is place for improvements...
public EnumCheckGroup(String id, T... values)

 Why not just pass the enum class into the constructor?

if i pass the enum object itself, how do i actually get the values?

francisco


 On Fri, Sep 26, 2008 at 4:43 PM, francisco treacy
 [EMAIL PROTECTED] wrote:
 i'm sorry i didn't see this post before-- i came up with a solution a
 couple of weeks ago.

 i called it EnumCheckGroup (that is, i went for CheckGroup rather than
 CheckBox).

 usage:

 for a given enum:

public static enum Niveau {
etage, mezzanine, sous_sol;
}

   form.add(new EnumCheckGroupPlan.Niveau(niveaux,
 Plan.Niveau.values()));


  span wicket:id=niveaux
   span wicket:id=items
   input type=checkbox wicket:id=check /
   span wicket:id=label/spanbr /
   /span
   /span


 impl:

 public class EnumCheckGroupT extends EnumT extends CheckGroupT {

   public EnumCheckGroup(String id, T[] values) {
   super(id);

   ListViewT listview = new ListViewT(items,
 Arrays.asList(values)) {
   protected void populateItem(ListItemT item) {
   item.add(new CheckT(check, item.getModel()));
   item.add(new Label(label, new
 ResourceModel(item.getModelObject().name(;
   };
   }.setReuseItems(true);

   add(listview);

   }

 }

 obviously you must have the keys in your properties file, such as:

 etage=Étage
 mezzanine=Mezzanine
 sous_sol=Sous-sol


 francisco


 On Fri, Sep 26, 2008 at 4:29 PM, Cédric Thiébault
 [EMAIL PROTECTED] wrote:
 Thanks Igor, it was exactly what i needed :-)

 To complete this post, here is the solution I found :
 http://surunairdejava.blogspot.com/2008/09/wicket-checkbox-abstractcheckboxmodel.html

 Sorry it's in french but the code is easy to understand...

 Cedric


 On Wed, Sep 24, 2008 at 2:46 PM, Igor Vaynberg [EMAIL PROTECTED] wrote:
 see abstractcheckboxmodel

 -igor

 On Wed, Sep 24, 2008 at 11:37 AM, Cédric Thiébault
 [EMAIL PROTECTED] wrote:
 Hi,

 I'm trying to use a checkbox to set an enum value on my form object
 but I always get a type mismatch error (boolean is not an enum and
 vice versa).

 My form object has an enum and I want to display a list of checkboxes
 to allow the user to select the value.
 I don't want to use a radio because my enum can be null and I can't
 unselect my radio group once a radio is selected.

 I tried to extends Checkbox to convert teh boolean to the specified
 enum... it works only in one way (to set the enum value) but it does
 not work when my enum has a value and the checkbox need to render
 itself (the value must be a boolean).


 public class CheckBoxEnum extends CheckBox {

  private final Enum? enumValue;

  public CheckBoxEnum(String id, IModel model, String property,
 Enum? enumValue) {
super(id, new PropertyModel(model, property));
this.enumValue = enumValue;
  }

  @Override
  protected void convertInput() {
String value = getValue();
if (value != null  BooleanUtils.toBoolean(value))
 setConvertedInput(enumValue);
  }
 }

 Any ideas ?

 Thanks

 Cedric

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



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



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



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




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



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



Re: Checkbox and enum value

2008-09-26 Thread francisco treacy
* i meant enum class

On Fri, Sep 26, 2008 at 7:51 PM, francisco treacy
[EMAIL PROTECTED] wrote:
 Also, you could have a varargs feature so that users could specify
 exactly what they want without having to instantiate an array.

 yes, of course there is place for improvements...
 public EnumCheckGroup(String id, T... values)

 Why not just pass the enum class into the constructor?

 if i pass the enum object itself, how do i actually get the values?

 francisco


 On Fri, Sep 26, 2008 at 4:43 PM, francisco treacy
 [EMAIL PROTECTED] wrote:
 i'm sorry i didn't see this post before-- i came up with a solution a
 couple of weeks ago.

 i called it EnumCheckGroup (that is, i went for CheckGroup rather than
 CheckBox).

 usage:

 for a given enum:

public static enum Niveau {
etage, mezzanine, sous_sol;
}

   form.add(new EnumCheckGroupPlan.Niveau(niveaux,
 Plan.Niveau.values()));


  span wicket:id=niveaux
   span wicket:id=items
   input type=checkbox wicket:id=check /
   span wicket:id=label/spanbr /
   /span
   /span


 impl:

 public class EnumCheckGroupT extends EnumT extends CheckGroupT {

   public EnumCheckGroup(String id, T[] values) {
   super(id);

   ListViewT listview = new ListViewT(items,
 Arrays.asList(values)) {
   protected void populateItem(ListItemT item) {
   item.add(new CheckT(check, item.getModel()));
   item.add(new Label(label, new
 ResourceModel(item.getModelObject().name(;
   };
   }.setReuseItems(true);

   add(listview);

   }

 }

 obviously you must have the keys in your properties file, such as:

 etage=Étage
 mezzanine=Mezzanine
 sous_sol=Sous-sol


 francisco


 On Fri, Sep 26, 2008 at 4:29 PM, Cédric Thiébault
 [EMAIL PROTECTED] wrote:
 Thanks Igor, it was exactly what i needed :-)

 To complete this post, here is the solution I found :
 http://surunairdejava.blogspot.com/2008/09/wicket-checkbox-abstractcheckboxmodel.html

 Sorry it's in french but the code is easy to understand...

 Cedric


 On Wed, Sep 24, 2008 at 2:46 PM, Igor Vaynberg [EMAIL PROTECTED] wrote:
 see abstractcheckboxmodel

 -igor

 On Wed, Sep 24, 2008 at 11:37 AM, Cédric Thiébault
 [EMAIL PROTECTED] wrote:
 Hi,

 I'm trying to use a checkbox to set an enum value on my form object
 but I always get a type mismatch error (boolean is not an enum and
 vice versa).

 My form object has an enum and I want to display a list of checkboxes
 to allow the user to select the value.
 I don't want to use a radio because my enum can be null and I can't
 unselect my radio group once a radio is selected.

 I tried to extends Checkbox to convert teh boolean to the specified
 enum... it works only in one way (to set the enum value) but it does
 not work when my enum has a value and the checkbox need to render
 itself (the value must be a boolean).


 public class CheckBoxEnum extends CheckBox {

  private final Enum? enumValue;

  public CheckBoxEnum(String id, IModel model, String property,
 Enum? enumValue) {
super(id, new PropertyModel(model, property));
this.enumValue = enumValue;
  }

  @Override
  protected void convertInput() {
String value = getValue();
if (value != null  BooleanUtils.toBoolean(value))
 setConvertedInput(enumValue);
  }
 }

 Any ideas ?

 Thanks

 Cedric

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



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



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



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




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




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



Re: Checkbox and enum value

2008-09-26 Thread James Carman
Yeah, check out:

https://wicketopia.svn.sourceforge.net/svnroot/wicketopia/trunk/wicketopia/src/main/java/org/wicketopia/component/choice/EnumDropDownChoice.java


On Fri, Sep 26, 2008 at 7:44 PM, Igor Vaynberg [EMAIL PROTECTED] wrote:
 Class ? extends Enum ?  enumClass;
 enumClass.getEnumConstants();

 -igor

 On Fri, Sep 26, 2008 at 4:32 PM, Cédric Thiébault
 [EMAIL PROTECTED] wrote:
 Thanks for the input... I've updated my code :)

 James, I have the same question as Francisco: how do you get the
 values from the class of an enum?

 Cedric


 On Fri, Sep 26, 2008 at 6:57 PM, francisco treacy
 [EMAIL PROTECTED] wrote:
 * i meant enum class

 On Fri, Sep 26, 2008 at 7:51 PM, francisco treacy
 [EMAIL PROTECTED] wrote:
 Also, you could have a varargs feature so that users could specify
 exactly what they want without having to instantiate an array.

 yes, of course there is place for improvements...
 public EnumCheckGroup(String id, T... values)

 Why not just pass the enum class into the constructor?

 if i pass the enum object itself, how do i actually get the values?

 francisco


 On Fri, Sep 26, 2008 at 4:43 PM, francisco treacy
 [EMAIL PROTECTED] wrote:
 i'm sorry i didn't see this post before-- i came up with a solution a
 couple of weeks ago.

 i called it EnumCheckGroup (that is, i went for CheckGroup rather than
 CheckBox).

 usage:

 for a given enum:

public static enum Niveau {
etage, mezzanine, sous_sol;
}

   form.add(new EnumCheckGroupPlan.Niveau(niveaux,
 Plan.Niveau.values()));


  span wicket:id=niveaux
   span wicket:id=items
   input type=checkbox wicket:id=check 
 /
   span wicket:id=label/spanbr /
   /span
   /span


 impl:

 public class EnumCheckGroupT extends EnumT extends CheckGroupT {

   public EnumCheckGroup(String id, T[] values) {
   super(id);

   ListViewT listview = new ListViewT(items,
 Arrays.asList(values)) {
   protected void populateItem(ListItemT item) {
   item.add(new CheckT(check, item.getModel()));
   item.add(new Label(label, new
 ResourceModel(item.getModelObject().name(;
   };
   }.setReuseItems(true);

   add(listview);

   }

 }

 obviously you must have the keys in your properties file, such as:

 etage=Étage
 mezzanine=Mezzanine
 sous_sol=Sous-sol


 francisco


 On Fri, Sep 26, 2008 at 4:29 PM, Cédric Thiébault
 [EMAIL PROTECTED] wrote:
 Thanks Igor, it was exactly what i needed :-)

 To complete this post, here is the solution I found :
 http://surunairdejava.blogspot.com/2008/09/wicket-checkbox-abstractcheckboxmodel.html

 Sorry it's in french but the code is easy to understand...

 Cedric


 On Wed, Sep 24, 2008 at 2:46 PM, Igor Vaynberg [EMAIL PROTECTED] 
 wrote:
 see abstractcheckboxmodel

 -igor

 On Wed, Sep 24, 2008 at 11:37 AM, Cédric Thiébault
 [EMAIL PROTECTED] wrote:
 Hi,

 I'm trying to use a checkbox to set an enum value on my form object
 but I always get a type mismatch error (boolean is not an enum and
 vice versa).

 My form object has an enum and I want to display a list of checkboxes
 to allow the user to select the value.
 I don't want to use a radio because my enum can be null and I can't
 unselect my radio group once a radio is selected.

 I tried to extends Checkbox to convert teh boolean to the specified
 enum... it works only in one way (to set the enum value) but it does
 not work when my enum has a value and the checkbox need to render
 itself (the value must be a boolean).


 public class CheckBoxEnum extends CheckBox {

  private final Enum? enumValue;

  public CheckBoxEnum(String id, IModel model, String property,
 Enum? enumValue) {
super(id, new PropertyModel(model, property));
this.enumValue = enumValue;
  }

  @Override
  protected void convertInput() {
String value = getValue();
if (value != null  BooleanUtils.toBoolean(value))
 setConvertedInput(enumValue);
  }
 }

 Any ideas ?

 Thanks

 Cedric

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



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



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



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




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




 

Checkbox and enum value

2008-09-24 Thread Cédric Thiébault
Hi,

I'm trying to use a checkbox to set an enum value on my form object
but I always get a type mismatch error (boolean is not an enum and
vice versa).

My form object has an enum and I want to display a list of checkboxes
to allow the user to select the value.
I don't want to use a radio because my enum can be null and I can't
unselect my radio group once a radio is selected.

I tried to extends Checkbox to convert teh boolean to the specified
enum... it works only in one way (to set the enum value) but it does
not work when my enum has a value and the checkbox need to render
itself (the value must be a boolean).


public class CheckBoxEnum extends CheckBox {

  private final Enum? enumValue;

  public CheckBoxEnum(String id, IModel model, String property,
Enum? enumValue) {
super(id, new PropertyModel(model, property));
this.enumValue = enumValue;
  }

  @Override
  protected void convertInput() {
String value = getValue();
if (value != null  BooleanUtils.toBoolean(value))
setConvertedInput(enumValue);
  }
}

Any ideas ?

Thanks

Cedric

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



Re: Checkbox and enum value

2008-09-24 Thread Igor Vaynberg
see abstractcheckboxmodel

-igor

On Wed, Sep 24, 2008 at 11:37 AM, Cédric Thiébault
[EMAIL PROTECTED] wrote:
 Hi,

 I'm trying to use a checkbox to set an enum value on my form object
 but I always get a type mismatch error (boolean is not an enum and
 vice versa).

 My form object has an enum and I want to display a list of checkboxes
 to allow the user to select the value.
 I don't want to use a radio because my enum can be null and I can't
 unselect my radio group once a radio is selected.

 I tried to extends Checkbox to convert teh boolean to the specified
 enum... it works only in one way (to set the enum value) but it does
 not work when my enum has a value and the checkbox need to render
 itself (the value must be a boolean).


 public class CheckBoxEnum extends CheckBox {

  private final Enum? enumValue;

  public CheckBoxEnum(String id, IModel model, String property,
 Enum? enumValue) {
super(id, new PropertyModel(model, property));
this.enumValue = enumValue;
  }

  @Override
  protected void convertInput() {
String value = getValue();
if (value != null  BooleanUtils.toBoolean(value))
 setConvertedInput(enumValue);
  }
 }

 Any ideas ?

 Thanks

 Cedric

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



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