tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lukasz Jazgar (JIRA)" <j...@apache.org>
Subject [jira] Reopened: (TAP5-595) Binding of Boolean parameter - Coercion null -> false
Date Fri, 01 May 2009 14:07:30 GMT

     [ https://issues.apache.org/jira/browse/TAP5-595?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Lukasz Jazgar reopened TAP5-595:
--------------------------------


Should probably?! It's gently said.
For me, it's serious bug, which cause that framework is not coherent.
Why any coercion is done, when type of actual parameter is same as type of formal parameter?
Why Boolean is treated differently than Integer, Double, String and any other Object?

Such a surprising behavior cause only discouragement of using Tapestry.

Finnally, what can do developer like me, who want to make GUI to existing code of all lower
layers (logic, DAO, database), which heavily uses Boolean type to represent 3-values (yes,
no, no data). Rewriting this code (eg to use char) is not possible now. It's too much work.
And it would be making code less elegant. Boolean type is more natural in this case.
Maybe I should leave this old code with Booleans and write only GUI with chars? But it needs
a lot of junk code translating complex data structures. It's also not good solution.

Another problem
How can be written components like "3-values If" or "3-values checkbox" similar to existing
2-values components? Its not possible now.

I think, this bug is really worth correcting.

I understand your worry for stability of existing applications, but there is a solution.
Additional configuration parameter (e.g. COERCE_BOOLEAN_CORRECTLY) can be made. Old applications
will work with "false", new ones will be written with "true". Default value? As you wish.
For example now - false, in next major release - true, somewhen in the future parameter can
be removed completely.

Or maybe making alternate TypeCoercer is a solution?

Anyway, it can be corrected without danger of destabilizing existing applications and it is
worth doing it.


If you will decide not to correct it, please, at least write in documentation in article "Parameter
Type Coercions" big red inscription - "Do not use Booleans!!!! Booleans are evil!!!" ;). It
can protect others against fall into trap, like me. 

PS.
Is it possible to override existing TypeCoerce to easily change this behavior? How to do it?
Thanks in advance for any advice.


> Binding of Boolean parameter - Coercion null -> false
> -----------------------------------------------------
>
>                 Key: TAP5-595
>                 URL: https://issues.apache.org/jira/browse/TAP5-595
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-core
>    Affects Versions: 5.1.0.4, 5.0.18
>            Reporter: Lukasz Jazgar
>            Assignee: Howard M. Lewis Ship
>
> Null value of Boolean (non-primitive type) property is coerced to false, when passed
to parameter of type Boolean.
> There is a example below showing this behavior:
> Component with Boolean parameter.
> BooleanComponent.java:
> public class BooleanComponent {
>    @Parameter
>    private Boolean value;
>    boolean beginRender(MarkupWriter writer) {
>        if (value!=null)
>            writer.write("Component's parameter value:" + value);
>        else
>            writer.write("Component's parameter value is NULL);
>        return false;
>    }
> }
> Page passing property of type Boolean as a parameter to component BooleanComponent.
> BooleanTestPage.tml:
> <html xmlns="http://www.w3.org/1999/xhtml"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
>     xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance
> http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd"
>        >
>    <body>
>        PageProperty: ${boolProperty} <br/>
>        BooleanComponent: <t:booleanComponent t:value="boolProperty"/>
>    </body>
> </html>
> BooleanTestPage.java:
> public class BooleanTestPage {
>    @Property
>    private Boolean boolProperty;
>    void onActivate(String yesNoNullStr) {
>        if (yesNoNullStr.equalsIgnoreCase("yes"))
>            boolProperty = true;
>        else if (yesNoNullStr.equalsIgnoreCase("no"))
>            boolProperty = false;
>        else
>            boolProperty = null;
>    }
> }
> Observed behavior:
> 1.
> http://localhost:8080/web/booleanTestPage/yes
> Result:
>        PageProperty: true
>        BooleanComponent: Component's parameter value: true
> OK
> 2.
> http://localhost:8080/web/booleanTestPage/no
> Result:
>        PageProperty: false
>        BooleanComponent: Component's parameter value: false
> OK
> 3.
> http://localhost:8080/web/booleanTestPage/null
> Result:
>        PageProperty:
>        BooleanComponent: Component's parameter value: false    <---------------!!!!!!!
> Why value of component parameter is false. Shouldn't be null?

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


Mime
View raw message