You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Dmitriy Vsekhvalnov <dv...@gmail.com> on 2010/10/14 10:00:41 UTC

Component to format null values

Hello all,

i'm looking to some approach to render property value or some default string
if value is null.

Something like:
   <t:formatnull value="contract.name" />

I have no problem to implement such component,but i want this to work with
property chains as well:

  <t:formatnull value="contract.manager.address.city.name" />

where i want default string to be rendered, if any of intermediate values
evaluated to null. Now i'm getting NPE.

Is there are any service in tapestry which i can use for property
expressions evaluation or any other ideas?

Thanks.

Re: Component to format null values

Posted by Andreas Andreou <an...@di.uoa.gr>.
http://tapestry.apache.org/tapestry5.1/guide/propexp.html
The  "safe dereference operator"

On Thu, Oct 14, 2010 at 12:03, Muhammad Mohsen <m....@gmail.com> wrote:
> Excuse me, I'm not questioning the functioning of your mentioned solution
> but where in the documentation is that ? I wanna read more about this.
> Thanks
>
> On Thu, Oct 14, 2010 at 10:21 AM, Jim O'Callaghan <jc...@yahoo.co.uk>wrote:
>
>> I think you can use the format:
>>
>> <t:formatnull value="${contract?.manager?.address?.city?.name}" />
>>
>> ... where if any of the hierarchy is null is will stop trying to evaluate
>> methods / properties on subordinates, avoiding your NPE.
>>
>> Regards,
>> Jim.
>>
>> -----Original Message-----
>> From: Dmitriy Vsekhvalnov [mailto:dvsekhvalnov@gmail.com]
>> Sent: 14 October 2010 09:01
>> To: users@tapestry.apache.org
>> Subject: Component to format null values
>>
>> Hello all,
>>
>> i'm looking to some approach to render property value or some default
>> string
>> if value is null.
>>
>> Something like:
>>   <t:formatnull value="contract.name" />
>>
>> I have no problem to implement such component,but i want this to work with
>> property chains as well:
>>
>>  <t:formatnull value="contract.manager.address.city.name" />
>>
>> where i want default string to be rendered, if any of intermediate values
>> evaluated to null. Now i'm getting NPE.
>>
>> Is there are any service in tapestry which i can use for property
>> expressions evaluation or any other ideas?
>>
>> Thanks.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> --
> *Regards,*
> *Muhammad Gelbana
> Java Software Programmer*
>



-- 
Andreas Andreou - andyhot@apache.org - http://blog.andyhot.gr
Tapestry PMC / Tacos developer
Open Source / JEE Consulting

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


Re: Component to format null values

Posted by Muhammad Mohsen <m....@gmail.com>.
Excuse me, I'm not questioning the functioning of your mentioned solution
but where in the documentation is that ? I wanna read more about this.
Thanks

On Thu, Oct 14, 2010 at 10:21 AM, Jim O'Callaghan <jc...@yahoo.co.uk>wrote:

> I think you can use the format:
>
> <t:formatnull value="${contract?.manager?.address?.city?.name}" />
>
> ... where if any of the hierarchy is null is will stop trying to evaluate
> methods / properties on subordinates, avoiding your NPE.
>
> Regards,
> Jim.
>
> -----Original Message-----
> From: Dmitriy Vsekhvalnov [mailto:dvsekhvalnov@gmail.com]
> Sent: 14 October 2010 09:01
> To: users@tapestry.apache.org
> Subject: Component to format null values
>
> Hello all,
>
> i'm looking to some approach to render property value or some default
> string
> if value is null.
>
> Something like:
>   <t:formatnull value="contract.name" />
>
> I have no problem to implement such component,but i want this to work with
> property chains as well:
>
>  <t:formatnull value="contract.manager.address.city.name" />
>
> where i want default string to be rendered, if any of intermediate values
> evaluated to null. Now i'm getting NPE.
>
> Is there are any service in tapestry which i can use for property
> expressions evaluation or any other ideas?
>
> Thanks.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
*Regards,*
*Muhammad Gelbana
Java Software Programmer*

RE: Component to format null values

Posted by Jim O'Callaghan <jc...@yahoo.co.uk>.
You're welcome Dmitriy.  One thing I should have said was that my example
${...} forced coercion to a String, which may / may not be required in your
case.

Regards,
Jim.

-----Original Message-----
From: Dmitriy Vsekhvalnov [mailto:dvsekhvalnov@gmail.com] 
Sent: 14 October 2010 11:27
To: Tapestry users
Subject: Re: Component to format null values

you opened my eyes. Thanks.

On Thu, Oct 14, 2010 at 12:21 PM, Jim O'Callaghan
<jc...@yahoo.co.uk>wrote:

> I think you can use the format:
>
> <t:formatnull value="${contract?.manager?.address?.city?.name}" />
>
> ... where if any of the hierarchy is null is will stop trying to evaluate
> methods / properties on subordinates, avoiding your NPE.
>
> Regards,
> Jim.
>
> -----Original Message-----
> From: Dmitriy Vsekhvalnov [mailto:dvsekhvalnov@gmail.com]
> Sent: 14 October 2010 09:01
> To: users@tapestry.apache.org
> Subject: Component to format null values
>
> Hello all,
>
> i'm looking to some approach to render property value or some default
> string
> if value is null.
>
> Something like:
>   <t:formatnull value="contract.name" />
>
> I have no problem to implement such component,but i want this to work with
> property chains as well:
>
>  <t:formatnull value="contract.manager.address.city.name" />
>
> where i want default string to be rendered, if any of intermediate values
> evaluated to null. Now i'm getting NPE.
>
> Is there are any service in tapestry which i can use for property
> expressions evaluation or any other ideas?
>
> Thanks.
>
>
> ---------------------------------------------------------------------
> 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: Component to format null values

Posted by Dmitriy Vsekhvalnov <dv...@gmail.com>.
you opened my eyes. Thanks.

On Thu, Oct 14, 2010 at 12:21 PM, Jim O'Callaghan <jc...@yahoo.co.uk>wrote:

> I think you can use the format:
>
> <t:formatnull value="${contract?.manager?.address?.city?.name}" />
>
> ... where if any of the hierarchy is null is will stop trying to evaluate
> methods / properties on subordinates, avoiding your NPE.
>
> Regards,
> Jim.
>
> -----Original Message-----
> From: Dmitriy Vsekhvalnov [mailto:dvsekhvalnov@gmail.com]
> Sent: 14 October 2010 09:01
> To: users@tapestry.apache.org
> Subject: Component to format null values
>
> Hello all,
>
> i'm looking to some approach to render property value or some default
> string
> if value is null.
>
> Something like:
>   <t:formatnull value="contract.name" />
>
> I have no problem to implement such component,but i want this to work with
> property chains as well:
>
>  <t:formatnull value="contract.manager.address.city.name" />
>
> where i want default string to be rendered, if any of intermediate values
> evaluated to null. Now i'm getting NPE.
>
> Is there are any service in tapestry which i can use for property
> expressions evaluation or any other ideas?
>
> Thanks.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

RE: Component to format null values

Posted by Jim O'Callaghan <jc...@yahoo.co.uk>.
I think you can use the format:

<t:formatnull value="${contract?.manager?.address?.city?.name}" />

... where if any of the hierarchy is null is will stop trying to evaluate
methods / properties on subordinates, avoiding your NPE.

Regards,
Jim.

-----Original Message-----
From: Dmitriy Vsekhvalnov [mailto:dvsekhvalnov@gmail.com] 
Sent: 14 October 2010 09:01
To: users@tapestry.apache.org
Subject: Component to format null values

Hello all,

i'm looking to some approach to render property value or some default string
if value is null.

Something like:
   <t:formatnull value="contract.name" />

I have no problem to implement such component,but i want this to work with
property chains as well:

  <t:formatnull value="contract.manager.address.city.name" />

where i want default string to be rendered, if any of intermediate values
evaluated to null. Now i'm getting NPE.

Is there are any service in tapestry which i can use for property
expressions evaluation or any other ideas?

Thanks.


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