[ 
https://issues.apache.org/jira/browse/WICKET-330?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12476204
 ] 

Martin Benda commented on WICKET-330:
-------------------------------------

A CheckBox can have only o Boolean model (CheckBox extends 
FormComponent<Boolean>) and I believe that wicket converters are designed to 
convert model Object to its String display representation and vice versa, not 
boolean <-> model objects. That's why they have a locale as the second 
conversion parameter. IMHO wicket converters should be completely decoupled 
from database or any other backend system. Models are responsible to 
communicate with database and they should handle conversions like 1 <-> 
Boolean.TRUE and 0 <-> Boolean.FALSE.

I believe that this could be the fix, it works for me:

public class CheckBox extends FormComponent<Boolean> implements 
IOnChangeListener
{
    ....
    @Override
    protected String getModelValue() {
        return Boolean.toString(Boolean.TRUE.equals(getModelObject()));
    }
    ...
}


> CheckBox incorrectly converts its model value when a custom Boolean converter 
> is installed
> ------------------------------------------------------------------------------------------
>
>                 Key: WICKET-330
>                 URL: https://issues.apache.org/jira/browse/WICKET-330
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 2.0
>            Reporter: Martin Benda
>
> When I use a custom localized Boolean converter (using my custom 
> IConverterLocator) that converts "Ano" to true and "Ne" to false (Czech words 
> for "yes" and "no") the CheckBox with 'true' getModelObject() will render 
> unchecked. The problem is that CheckBox uses Strings.isTrue() to convert a 
> value returned by getModelObjectAsString() which uses converters. The result 
> is that true is incorrectly converted to false...
> true -> convertToString() -> "Ano" -> Strings.isTrue() -> false

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to