You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Łukasz Jazgar <lu...@gmail.com> on 2009/03/23 22:53:21 UTC

Binding of Boolean parameter

Hi all,

I am a newbie in Tapestry. Please, help me to understand, how binding of
parameters works. I'll show my problem on very simplified example.

There is a component:

public class BooleanComponent {

    @Parameter
    private Boolean value;

    boolean beginRender(MarkupWriter writer) {
        writer.write(""+value);
        return false;
    }
}

Component has one parameter of type Boolean, and all what component does
is rendering value of this parameter.

This component is placed on Page:
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;
    }
}

Page has property of type Boolean passed to component by parameter.

When I show the page with parameter "yes" or "no", everything goes
according to my expectations. Property of page and parameter of
component are binded, so they have same value, true or false.

But, when I show page with any other value, property of page gets null
value, but parameter of component gets false, not null. Why?
What am I doing wrong?


Regards
Lukasz


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Binding of Boolean parameter

Posted by Lukasz Jazgar <lu...@gmail.com>.
2009/3/24 Ville Virtanen <vi...@cerion.fi>:
>
> Also the line
>
> writer.write(""+value);
>
> could be to blame?
>
> try something like
>
> if(value == null) {
>  writer.write("null");
> } else if (value.booleanValue() == true) {
>  writer.write("true");
> } else {
>  writer.write("false");
> }
>
Your code gives the same result as ""+value and String.valueOf(value)
(as suggests Thiago). It doesn't matter. And that's not the point.

> If it still does not work I suggest that you create JIRA issue and attach
> .tml and .java files that replicate this with explanation.

Yes. I'll do it.

Thanks a lot.

Lukasz

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Binding of Boolean parameter

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, Mar 24, 2009 at 5:27 AM, Ville Virtanen
<vi...@cerion.fi> wrote:

> Also the line
> writer.write(""+value);

What about writer.write(String.valueOf(value))? Anyway, conversions
from almost any type to String are best handled by String.valueOf().

-- 
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Binding of Boolean parameter

Posted by Ville Virtanen <vi...@cerion.fi>.
Also the line

writer.write(""+value);

could be to blame?

try something like 

if(value == null) {
  writer.write("null");
} else if (value.booleanValue() == true) {
  writer.write("true");
} else {
  writer.write("false");
}

If it still does not work I suggest that you create JIRA issue and attach
.tml and .java files that replicate this with explanation.

 - Ville


Łukasz Jazgar wrote:
> 
> 5.0.18
> 
> 2009/3/24 Ville Virtanen <vi...@cerion.fi>:
>>
>> What version are you using?
>>
>>  - Ville
>>
>>
>> Łukasz Jazgar wrote:
>>>
>>> 2009/3/24 Ville Virtanen <vi...@cerion.fi>:
>>>>
>>>> Hi,
>>>>
>>>> double check that the boolean is not primitive _anywhere_, as then
>>>> assigning
>>>> null to it would coerse the value to false witch is the default in Java
>>>> if
>>>> it is unknown.
>>>
>>> I checked it 10 times before. Parameter of component and property of
>>> page are not primitive Booleans.
>>>
>>> Similar behaviour I see in oposite direction. When I set value of
>>> component parameter to null, page property gets false, not null.
>>>
>>>>
>>>> The other option is that the type coersion system in T5 handles null
>>>> values
>>>> incorrectly?
>>>
>>> Is it possible, that so base functionality is buggy in stable release
>>> (5.0.18) and nobody noticed it before? Neither unit tests? I can't
>>> belive. I still think it's my fault and my lack of understanding.
>>>
>>>
>>> Łukasz
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Binding-of-Boolean-parameter-tp22670091p22675837.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Binding-of-Boolean-parameter-tp22670091p22675928.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Binding of Boolean parameter

Posted by Lukasz Jazgar <lu...@gmail.com>.
5.0.18

2009/3/24 Ville Virtanen <vi...@cerion.fi>:
>
> What version are you using?
>
>  - Ville
>
>
> Łukasz Jazgar wrote:
>>
>> 2009/3/24 Ville Virtanen <vi...@cerion.fi>:
>>>
>>> Hi,
>>>
>>> double check that the boolean is not primitive _anywhere_, as then
>>> assigning
>>> null to it would coerse the value to false witch is the default in Java
>>> if
>>> it is unknown.
>>
>> I checked it 10 times before. Parameter of component and property of
>> page are not primitive Booleans.
>>
>> Similar behaviour I see in oposite direction. When I set value of
>> component parameter to null, page property gets false, not null.
>>
>>>
>>> The other option is that the type coersion system in T5 handles null
>>> values
>>> incorrectly?
>>
>> Is it possible, that so base functionality is buggy in stable release
>> (5.0.18) and nobody noticed it before? Neither unit tests? I can't
>> belive. I still think it's my fault and my lack of understanding.
>>
>>
>> Łukasz
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Binding-of-Boolean-parameter-tp22670091p22675837.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Binding of Boolean parameter

Posted by Ville Virtanen <vi...@cerion.fi>.
What version are you using?

 - Ville


Łukasz Jazgar wrote:
> 
> 2009/3/24 Ville Virtanen <vi...@cerion.fi>:
>>
>> Hi,
>>
>> double check that the boolean is not primitive _anywhere_, as then
>> assigning
>> null to it would coerse the value to false witch is the default in Java
>> if
>> it is unknown.
> 
> I checked it 10 times before. Parameter of component and property of
> page are not primitive Booleans.
> 
> Similar behaviour I see in oposite direction. When I set value of
> component parameter to null, page property gets false, not null.
> 
>>
>> The other option is that the type coersion system in T5 handles null
>> values
>> incorrectly?
> 
> Is it possible, that so base functionality is buggy in stable release
> (5.0.18) and nobody noticed it before? Neither unit tests? I can't
> belive. I still think it's my fault and my lack of understanding.
> 
> 
> Łukasz
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Binding-of-Boolean-parameter-tp22670091p22675837.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Binding of Boolean parameter

Posted by Lukasz Jazgar <lu...@gmail.com>.
2009/3/24 Ville Virtanen <vi...@cerion.fi>:
>
> Hi,
>
> double check that the boolean is not primitive _anywhere_, as then assigning
> null to it would coerse the value to false witch is the default in Java if
> it is unknown.

I checked it 10 times before. Parameter of component and property of
page are not primitive Booleans.

Similar behaviour I see in oposite direction. When I set value of
component parameter to null, page property gets false, not null.

>
> The other option is that the type coersion system in T5 handles null values
> incorrectly?

Is it possible, that so base functionality is buggy in stable release
(5.0.18) and nobody noticed it before? Neither unit tests? I can't
belive. I still think it's my fault and my lack of understanding.


Łukasz

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Binding of Boolean parameter

Posted by Ville Virtanen <vi...@cerion.fi>.
Hi,

double check that the boolean is not primitive _anywhere_, as then assigning
null to it would coerse the value to false witch is the default in Java if
it is unknown.

The other option is that the type coersion system in T5 handles null values
incorrectly?

 - Ville


Łukasz Jazgar wrote:
> 
> 
> Hi all,
> 
> I am a newbie in Tapestry. Please, help me to understand, how binding of
> parameters works. I'll show my problem on very simplified example.
> 
> There is a component:
> 
> public class BooleanComponent {
> 
>     @Parameter
>     private Boolean value;
> 
>     boolean beginRender(MarkupWriter writer) {
>         writer.write(""+value);
>         return false;
>     }
> }
> 
> Component has one parameter of type Boolean, and all what component does
> is rendering value of this parameter.
> 
> This component is placed on Page:
> 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;
>     }
> }
> 
> Page has property of type Boolean passed to component by parameter.
> 
> When I show the page with parameter "yes" or "no", everything goes
> according to my expectations. Property of page and parameter of
> component are binded, so they have same value, true or false.
> 
> But, when I show page with any other value, property of page gets null
> value, but parameter of component gets false, not null. Why?
> What am I doing wrong?
> 
> 
> Regards
> Lukasz
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Binding-of-Boolean-parameter-tp22670091p22675016.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org