hi,

i need to display/update some boolean properties in my domain model.
to achieve that i'm using a custom AjaxEditableChoiceLabel (from
wicket extensions) in my user interface.

why dropdown and not checkbox? well, because in fact there are 3
choices for this property in the database: true (yes), false (no),
null (unknown). my problem comes here: i'm having a bad time figuring
out how to "translate" between Boolean.TRUE, Boolean.FALSE, null  and
yes, no, unknown.

at first i thought it should be enough with a converter, so i overrode
that in my custom dropdown:

        class CustomAjaxEditableChoiceLabel extends AjaxEditableChoiceLabel {
                        
                public CustomAjaxEditableChoiceLabel(String id) {
                        super(id, Arrays.asList(Boolean.TRUE, Boolean.FALSE, 
null));
                }
                
        @Override
        protected void onEdit(AjaxRequestTarget target) {
                if (VdWebSession.get().isAuthenticated()) {
                        super.onEdit(target);
                }
        }
                @Override
                protected void onSubmit(AjaxRequestTarget target) {
                        super.onSubmit(target);
                        repo.persist((Doctor)getParent().getModelObject());
                }
                
                @Override
                public IConverter getConverter(Class type) {
                        return new CustomBooleanConverter();
                }
                        
        }


...and the converter

public class CustomBooleanConverter implements IConverter
{
        @Override
        public Object convertToObject(String string, Locale locale) {
                if (string.equals("yes")) {
                        return Boolean.TRUE;
                } else if (string.equals("no")) {
                        return Boolean.TRUE;
                } else {
                        return null;
                }
                
        }
        
        @Override
        public String convertToString(Object object, Locale locale) {
                if (object == null) {
                        return "unknown";
                }
                Boolean b = (Boolean) object;
                if (b) {
                        return "yes";
                } else {
                        return "no";
                }
        }

}


and i'm instantiating the component like this:

setModel(new CompoundPropertyModel(doctor));
(...)
add(new CustomAjaxEditableChoiceLabel("free").setOutputMarkupId(true));

this is working very well, except for the labels when i enter the
dropdown mode.... i still see "true", "false", (blank). i want my
labels also to be displayed when entering in "edit mode".

i read about IChoiceRenderer and i even implemented one, but i can't
use it with the CompoundPropertyModel (?).... cause in my component
constructor i can't do
super(id, Arrays.asList(Boolean.TRUE, Boolean.FALSE, null), new
CustomDropDownRenderer());
 (i need to pass in a Model, which is not updated as it is with the
compound one. or how would you do?)

i would really appreciate some hints/ pointers; i've lost time with
this "little" issue. thanks in advance!

francisco

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

Reply via email to