I just noticed it :-(.  Thanks very much. This is exactly what I am looking for
but did not find it in the ebooks I bought. This will be one of my wicket bible 
pieces and probably I would keep complaining to get more messages from saints.
Apologies in advance.

>have you noticed that no one else is finding this particularly hard?
>
>class dataconverter implements imodel {
>  final imodel model;
>
>  public dataconverter(imodel model) { this.model=model; }
>  public void detach() { model.detach(); }
>
>  public Object getObject() { return convertToComponent(model.getobject()); }
>  public void setObject() { model.setObject(convertFromComponent(object); }
>
>  protected abstract Object convertToComponent(Object o);
>  protected abstract Object convertFromComponent(Object o);
>}
>
>add(new CheckBox("foo") {
>    protected imodel initmodel() {
>        return new dataconverter(super.initmodel()){
>          protected Object convertToComponent(Object o) {
>               if (o.tostring().equals("y")) { return true; } else
>{return false; }
>           }
>          protected Object convertFromComponent(Object o) {
>            if (((boolean)o)==true) { return "y"; } else { return "n"; }
>         }
>    }
>}
>
>now it looks just like the converter...all it takes is a little bit of
>thinking and a little less complaining.
>
>-igor
>
>
>On Tue, Mar 25, 2008 at 4:21 PM,  <[EMAIL PROTECTED]> wrote:
>> Mine is not working.  I feel these "basic" data manipulation tasks
>>  are little to "heavy" in Wicket. Some built-in custom/helper classes
>>  could help a bit. I found I am writing many of these kind of custom
>>  class to do basic conversion and still have to worry if I am doing right,
>>  like the detach() method Igor just pointed out.
>>
>>
>>
>>  >wondering if that really always works.
>>  >looking at the current getConverter doc:
>>  >
>>  >/**
>>  >     * CheckBox will by default always just use the boolean converter
>>  >because the implementation
>>  >     * expects that the string is can be converted to a boolean [EMAIL 
>> PROTECTED]
>>  >Strings#isTrue(String)}
>>  >     *
>>  >     * @see org.apache.wicket.Component#getConverter(java.lang.Class)
>>  >     */
>>  >    public IConverter getConverter(Class type)
>>  >    {
>>  >        return BooleanConverter.INSTANCE;
>>  >    }
>>  >
>>  >but i guess yours works by accident because
>>  >Strings#isTrue(String) returns the right value for Y or N
>>  >
>>  >Also with generics i believe we have this:
>>  >
>>  >public class Checkbox extends FormComponent<Boolean>
>>  >
>>  >so the model type is hard to a boolean.
>>  >
>>  >johan
>>  >
>>  >
>>  >On Tue, Mar 25, 2008 at 11:30 PM, <[EMAIL PROTECTED]> wrote:
>>  >
>>  >> I just tested and it worked. Thanks very much.
>>  >> Pardon me for being stubbon here. For a simple
>>  >> convertion like this, So much has to be created so it seems a little 
>heavy
>>  >> weight.
>>  >>  For this one,
>>  >> first a subclass of Checkbox (possibly creating multiple constructors)
>>  >> overide initmodel and separate custom model class  just to convert
>>  >> a simple data object to another.  I'd still prefer the direct converter
>>  >> method.
>>  >> Even though one could see it as in business domain, this kind of
>>  >> conversion
>>  >> is generic enough to be put in the convert phase. Also, I saw you 
>saying
>>  >> about
>>  >> the detach() method, it could add some performance overhead, I guess.
>>  >> Could you show me what I am doing wrong below for the converter method?
>>  >> If this works, I'd even suggest to make it in the wicket core 
>release:-)
>>  >> by adding a method such as
>>  >> new CheckBox(id).setTrueFalse("y","n"),  you get the idea.
>>  >>
>>  >> public class CheckBoxYN extends CheckBox{
>>  >>
>>  >>    public CheckBoxYN(String id){
>>  >>        super(id);
>>  >>    }
>>  >>
>>  >>    @Override
>>  >>    public final IConverter getConverter(Class arg0){
>>  >>        IConverter icYN = new IConverter(){
>>  >>
>>  >>            public Object convertToObject(String arg0, Locale arg1) {
>>  >>               if (arg0.equals("true")){
>>  >>                   return 'Y';
>>  >>               }else{
>>  >>                   return 'N';
>>  >>               }
>>  >>
>>  >>            }
>>  >>
>>  >>            public String convertToString(Object arg0, Locale arg1) {
>>  >>                if(arg0.toString().equals('Y')){
>>  >>                    return "true";
>>  >>
>>  >>                }else{
>>  >>                    return "false";
>>  >>                }
>>  >>
>>  >>            }
>>  >>
>>  >>        };
>>  >>        return icYN;
>>  >>    }
>>  >>
>>  >> }
>>  >>
>>  >>
>>  >>
>>  >> >what i have shown you will work independently of the fact that you are
>>  >> >sure or not :)
>>  >> >
>>  >> >-igor
>>  >> >
>>  >> >
>>  >> >On Tue, Mar 25, 2008 at 2:51 PM,  <[EMAIL PROTECTED]> wrote:
>>  >> >> I am not sure how this would solve my problem
>>  >> >>  I intend to only use
>>  >> >>  new CheckBox("checked")  without adding any other arguments
>>  >> >>  since I expect it to resolve the form's compoundpropertymodel
>>  >> >>  whose object is entitybean with "checked" as column name.
>>  >> >>
>>  >> >>
>>  >> >>
>>  >> >>
>>  >> >>
>>  >> >>
>>  >> >>  >or you can simply do:
>>  >> >>  >
>>  >> >>  >class YesNoCheckBox extends CheckBox {
>>  >> >>  >
>>  >> >>  >  protected IModel initModel() {
>>  >> >>  >     return new CheckBoxYesNoModel(super.initModel());
>>  >> >>  >  }
>>  >> >>  >}
>>  >> >>  >
>>  >> >>  >-igor
>>  >> >>  >
>>  >> >>  >On Tue, Mar 25, 2008 at 2:29 PM,  <[EMAIL PROTECTED]> wrote:
>>  >> >>  >> Use model decorator sometimes seems troublesome.
>>  >> >>  >>  I need to use a form containing a lot of checkboxes and other
>>  >> types
>>  >> >>  >>  with compoundproperty model with a entity bean, say record.
>>  >> >>  >>  Most formcoponent ids are identical to their record property 
>name,
>>  >> >>  >>  such as Textfield("firstName") and record also has "firstName"
>>  >> >>  >>  if I use the extra decorator indirection for checkbox,
>>  >> >>  >>  I'd have to use
>>  >> >>  >>  CheckBox("checked",new CustomerModel(new
>>  >> >PropertyModel(record,"checked"))
>>  >> >>  >>  or is there a better/convenient way to do this?
>>  >> >>  >>
>>  >> >>  >>
>>  >> >>  >>
>>  >> >>  >>  >you forgot the important detach() { room.detach(); }
>>  >> >>  >>  >
>>  >> >>  >>
>>  >> >>  >> >-igor
>>  >> >>  >>  >
>>  >> >>  >>  >
>>  >> >>  >>  >On Tue, Mar 25, 2008 at 1:52 PM, Timo Rantalaiho
>>  >> ><[EMAIL PROTECTED]>
>>  >> >>  >>  >wrote:
>>  >> >>  >>  >>
>>  >> >>  >>
>>  >> >>  >>
>>  >> >>  >> >> On Tue, 25 Mar 2008, [EMAIL PROTECTED] wrote:
>>  >> >>  >>  >>  > Is there built-in mechanism to auto convert the checkbox
>>  >> model
>>  >> >value
>>  >> >>  >>  >>  > to be a character set Y/N  or Yes/No or any other pairs?
>>  >> >>  >>  >>  > This is frequently used pattern.
>>  >> >>  >>  >>
>>  >> >>  >>  >>  Probably you could set your own IConverter on the component
>>  >> >>  >>  >>  corresponding the checkbox. The converter can then be 
>reused
>>  >> >>  >>  >>  as needed.
>>  >> >>  >>  >>
>>  >> >>  >>  >>  I've typically (if not always) used checkboxes with custom
>>  >> models
>>  >> >>  >>  >>  directly toggling things in domain objects, e.g.
>>  >> >>  >>  >>
>>  >> >>  >>  >>  class RoomReservedModel extends Model {
>>  >> >>  >>  >>   private IModel room;
>>  >> >>  >>  >>
>>  >> >>  >>  >>   public RoomReservedModel(IModel room) {
>>  >> >>  >>  >>       this.room = room;
>>  >> >>  >>  >>   }
>>  >> >>  >>  >>
>>  >> >>  >>  >>   @Override
>>  >> >>  >>  >>   public void setObject(Object object) {
>>  >> >>  >>  >>       room().setReserved((Boolean) object);
>>  >> >>  >>  >>   }
>>  >> >>  >>  >>
>>  >> >>  >>  >>   @Override
>>  >> >>  >>  >>   public Object getObject() {
>>  >> >>  >>  >>       return room().isReserved();
>>  >> >>  >>  >>   }
>>  >> >>  >>  >>
>>  >> >>  >>  >>   private Room room() {
>>  >> >>  >>  >>       return (Room) room.getObject();
>>  >> >>  >>  >>   }
>>  >> >>  >>  >>  }
>>  >> >>  >>  >>
>>  >> >>  >>  >>  Best wishes,
>>  >> >>  >>  >>  Timo
>>  >> >>  >>  >>
>>  >> >>  >>  >>  --
>>  >> >>  >>  >>  Timo Rantalaiho
>>  >> >>  >>  >>  Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>>  >> >>  >>  >>
>>  >> >>  >>  >>
>>  >> >---------------------------------------------------------------------
>>  >> >>  >>  >>  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]
>>  >> >
>>  >>
>>  >> ---------------------------------------------------------------------
>>  >> 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]

Reply via email to