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]