You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Marcos Chicote <to...@gmail.com> on 2007/07/26 13:54:34 UTC

Re: [T4]Handling Nulls in OGNL expressions

Hi Andreas!
When I emailed to Tapestry's list I was prototyping a project. Now I'm
actually developing it and I'm very interested in getting this service
working.

Did you find some code where you used this feature?

Thanks!

Marcos

On 6/29/07, Marcos Chicote <to...@gmail.com> wrote:
>
> Thanks Andreas.
> I have to do some more reading then.
>
> I you have some code that I can use as an example I would be really
> grateful.
>
> Thanks!
>
> Marcos
>
> On 6/29/07, Andreas Andreou <an...@di.uoa.gr> wrote:
> >
> > O/H Marcos Chicote έγραψε:
> > > Thanks Andreas.
> > > Before mailing to this list, I tried looking at the ognl documentation
> > > and I
> > > found the NullHandler interface but I wasn't sure how it worked with
> > > Tapestry or if it was possible to do it another way without altering
> > the
> > > BOs.
> > >
> > > Correct me if I'm wrong but what I understand is that Tapestry already
> > > implements a Hivemind service that does the null handling. All I have
> > > to do
> > > is make my BOs implement NullHandler interface. Am I right?
> > Hmmm, not really... Tapestry simply provides that point so that your
> > have a global
> > way of registring handlers - so, making your BOs implement NullHandler
> > is not enough
> >
> > Also, i'm not sure if that's the correct approach - seems it polutes
> > your BOs
> >
> > I think I'd create a service that would be able to null-handle your
> > specific objects, and
> > esp. of all those objects have a common superclass, i'd be able to
> > register them all at once.
> >
> > I'll dig in for some code - it's been a while since i last used this
> >
> > >
> > > Thanks a lot!
> > >
> > > Marcos
> > >
> > > On 6/29/07, Andreas Andreou <an...@di.uoa.gr> wrote:
> > >>
> > >>
> > >>
> > http://tapestry.apache.org/tapestry4.1/tapestry-framework/hivedoc/config/tapestry.ognl.NullHandlers.html
> > >>
> > >>
> > >> the way it works, is that you associate implementations of
> > >> http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/NullHandler.html
> > >> with class types whose methods (or properties) may return null
> > >>
> > >> O/H Marcos Chicote έγραψε:
> > >> > Hi!
> > >> > I have a Table component (actually I have TableRows, TableView, and
> > >> all
> > >> > those other components that form a Table) and one of the columns in
> > >> > TableView is declared like this: columnName:
> > object1.object2.property.
> > >> >
> > >> > As you can see this can throw NullPointerException if either
> > >> object1 or
> > >> > object2 are null.
> > >> >
> > >> > To solve this problem, I have to alternatives:
> > >> > a) Use a Block component called columnNameColumnValue an inside the
> > >> > block an
> > >> > Insert component with a value asociated with the page's class that
> > >> > handles
> > >> > nulls
> > >> > b) Declare the column like: columnName:object1.propertyObject2.
> > (that
> > >> > it a
> > >> > getPropertyObject2 method in object1 class that handles nulls).
> > >> >
> > >> > Is there a better way to solve this?? I would love something like a
> > >> > prefix
> > >> > that allows me to specify that whenever a NPE is found, a blank
> > >> space is
> > >> > rendered. Is something like that possible?
> > >> >
> > >> > I'm ussing Tapestry 4.1.1.
> > >> >
> > >> > Btw, great work with Tap4.1.2, congratulations!
> > >> >
> > >> > Thanks!
> > >> >
> > >>
> > >> --
> > >> Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
> > >> Tapestry / Tacos developer
> > >> Open Source / J2EE Consulting
> > >>
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > >> For additional commands, e-mail: users-help@tapestry.apache.org
> > >>
> > >>
> >
> > --
> > Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
> > Tapestry / Tacos developer
> > Open Source / J2EE Consulting
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>

Re: [T4]Handling Nulls in OGNL expressions

Posted by Martino Piccinato <ma...@gmail.com>.
Hi,

please take my words with a grain of salt because I've never used this
in production but in my opiinon this should be the way to proceed:

have a look at this tapestry configuration point:

http://tapestry.apache.org/tapestry4.1/tapestry-framework/hivedoc/config/tapestry.ognl.PropertyAccessors.html

here you can configure your OGNL PropertyAccessor that returns null on nulls.

This is the interface you have to implement, even though you can just
override the get method of the default implementation for objects.

http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/PropertyAccessor.html



On 7/30/07, Marcos Chicote <to...@gmail.com> wrote:
> I wouldn't mind implementing a hivemind service if I could solve the problem
> this way, but I don't know how to implement the behaviour that I want. I
> want exactly what you discribe happens in WebObjets: if at any point in the
> ognl chain a null object is invoked, the hole expression evaluates to null
> (or "").
>
> Could anyone help me on doing this?
>
> I have a hivemind service that captures null using interface NullHandler,
> but now I'm stuck!
>
> Thanks!
>
> Marcos
>
> On 7/29/07, Damien Uern <da...@synect.com> wrote:
> >
> > (Sorry for top posting, but everybody else seems to do it on this list)
> >
> > Anyway, the null pointer exception in a long property access chain was
> > one of the issues I had with OGNL a while ago and have basically just
> > learned to live with it. It is highly annoying. One of the things I
> > preferred with Apple's WebObjects (which used NSKeyValueCoding for
> > property access expressions) was that if any object in the chain was
> > null, it just returned null. So if you have the expression:
> >
> > a.b.c.d
> >
> > where c is null, the entire expression would evaluate to null. Having to
> > implement some sort of hivemind null pointer handling service just to
> > get this sort of behaviour just screams "over designed" to me.
> >
> > (Not that I'm knocking OGNL/Tapestry in general, I still prefer using it
> > over WebObjects for a variety of reasons).
> >
> > Damien
> >
> > Martino Piccinato wrote:
> > > In my opinion is all that you want is not having NullPointerException it
> > > would be better to implement MethodAccessor and/or PropertyAccessor,
> > that
> > > would return null if the target object is null, then you could simply
> > check
> > > expressions returning nulls and returning your message, or maybe have a
> > > special component doing this.
> > >
> > > Tapestry has configuration point also for default Method/Property
> > accessors.
> > >
> > >
> > > On 7/26/07, Marcos Chicote <to...@gmail.com> wrote:
> > >> Responding to my own mail...
> > >>
> > >> I found an old Andreas mail to the lis (
> > >>
> > http://mail-archives.apache.org/mod_mbox/tapestry-dev/200606.mbox/%3C29991907.1149520711057.JavaMail.jira@brutus%3E
> > >> )
> > >>
> > >> that explained how to do this.
> > >>
> > >> I'll sumarize my ideas so that I can check if they are correct and
> > maybe
> > >> it
> > >> will result usefull to the next person that wants to do this.
> > >>
> > >> The idea is to define a class that implements NullHandler (
> > >> http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/NullHandler.html).
> > >> That class job is to handle null's when an specific class access to
> > >> property
> > >> returns null.
> > >> To make tapestry use your NullHandler you define something like this in
> > >> your hivemind configuration file:
> > >>
> > >>     <contribution configuration-id="tapestry.ognl.NullHandlers">
> > >>         <null-handler class="classThatImplementsNullHandler"
> > >>             object="instance:classToCaptureNulls"/>
> > >>     </contribution>
> > >>
> > >> where classToCaptureNulls represents the name of the class who's nulls
> > you
> > >>
> > >> want to handle and classThatImplementsNullHandler represents the class
> > >> that
> > >> knows how to deal with nulls in classToCaptureNulls.
> > >>
> > >> Now that I have this working I would like to know how to use it :D
> > >>
> > >> I mean, if I have a long ognl expression like obj1.obj2.obj3.obj4 and
> > >> access
> > >> to obj2 in obj1 return null, I would like to show an "obj2 not
> > available"
> > >> message on screen.
> > >>
> > >> Can anyone help me on how to use this service?
> > >>
> > >> Thanks!
> > >>
> > >> Marcos
> > >>
> > >> On 7/26/07, Marcos Chicote <to...@gmail.com> wrote:
> > >>> Hi Andreas!
> > >>> When I emailed to Tapestry's list I was prototyping a project. Now I'm
> > >>> actually developing it and I'm very interested in getting this service
> > >>> working.
> > >>>
> > >>> Did you find some code where you used this feature?
> > >>>
> > >>> Thanks!
> > >>>
> > >>> Marcos
> > >>>
> > >>> On 6/29/07, Marcos Chicote <to...@gmail.com> wrote:
> > >>>> Thanks Andreas.
> > >>>> I have to do some more reading then.
> > >>>>
> > >>>> I you have some code that I can use as an example I would be really
> > >>>> grateful.
> > >>>>
> > >>>> Thanks!
> > >>>>
> > >>>> Marcos
> > >>>>
> > >>>> On 6/29/07, Andreas Andreou < andyhot@di.uoa.gr> wrote:
> > >>>>> O/H Marcos Chicote έγραψε:
> > >>>>>> Thanks Andreas.
> > >>>>>> Before mailing to this list, I tried looking at the ognl
> > >>>>> documentation
> > >>>>>> and I
> > >>>>>> found the NullHandler interface but I wasn't sure how it worked
> > >> with
> > >>>>>> Tapestry or if it was possible to do it another way without
> > >> altering
> > >>>>> the
> > >>>>>> BOs.
> > >>>>>>
> > >>>>>> Correct me if I'm wrong but what I understand is that Tapestry
> > >>>>> already
> > >>>>>> implements a Hivemind service that does the null handling. All I
> > >>>>> have
> > >>>>>> to do
> > >>>>>> is make my BOs implement NullHandler interface. Am I right?
> > >>>>> Hmmm, not really... Tapestry simply provides that point so that your
> > >>>>> have a global
> > >>>>> way of registring handlers - so, making your BOs implement
> > >> NullHandler
> > >>>>> is not enough
> > >>>>>
> > >>>>> Also, i'm not sure if that's the correct approach - seems it polutes
> > >>>>> your BOs
> > >>>>>
> > >>>>> I think I'd create a service that would be able to null-handle your
> > >>>>> specific objects, and
> > >>>>> esp. of all those objects have a common superclass, i'd be able to
> > >>>>> register them all at once.
> > >>>>>
> > >>>>> I'll dig in for some code - it's been a while since i last used this
> > >>>>>
> > >>>>>> Thanks a lot!
> > >>>>>>
> > >>>>>> Marcos
> > >>>>>>
> > >>>>>> On 6/29/07, Andreas Andreou <an...@di.uoa.gr> wrote:
> > >>>>>>>
> > >>>>>>>
> > >>>>>
> > http://tapestry.apache.org/tapestry4.1/tapestry-framework/hivedoc/config/tapestry.ognl.NullHandlers.html
> > >>>>>>>
> > >>>>>>> the way it works, is that you associate implementations of
> > >>>>>>>
> > >> http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/NullHandler.html
> > >>>>>>> with class types whose methods (or properties) may return null
> > >>>>>>>
> > >>>>>>> O/H Marcos Chicote έγραψε:
> > >>>>>>>> Hi!
> > >>>>>>>> I have a Table component (actually I have TableRows, TableView,
> > >>>>> and
> > >>>>>>> all
> > >>>>>>>> those other components that form a Table) and one of the
> > >> columns
> > >>>>> in
> > >>>>>>>> TableView is declared like this: columnName:
> > >>>>> object1.object2.property.
> > >>>>>>>> As you can see this can throw NullPointerException if either
> > >>>>>>> object1 or
> > >>>>>>>> object2 are null.
> > >>>>>>>>
> > >>>>>>>> To solve this problem, I have to alternatives:
> > >>>>>>>> a) Use a Block component called columnNameColumnValue an inside
> > >>>>> the
> > >>>>>>>> block an
> > >>>>>>>> Insert component with a value asociated with the page's class
> > >>>>> that
> > >>>>>>>> handles
> > >>>>>>>> nulls
> > >>>>>>>> b) Declare the column like: columnName:object1.propertyObject2.
> > >>>>> (that
> > >>>>>>>> it a
> > >>>>>>>> getPropertyObject2 method in object1 class that handles nulls).
> > >>>>>>>> Is there a better way to solve this?? I would love something
> > >> like
> > >>>>> a
> > >>>>>>>> prefix
> > >>>>>>>> that allows me to specify that whenever a NPE is found, a blank
> > >>>>>>> space is
> > >>>>>>>> rendered. Is something like that possible?
> > >>>>>>>>
> > >>>>>>>> I'm ussing Tapestry 4.1.1.
> > >>>>>>>>
> > >>>>>>>> Btw, great work with Tap4.1.2, congratulations!
> > >>>>>>>>
> > >>>>>>>> Thanks!
> > >>>>>>>>
> > >>>>>>> --
> > >>>>>>> Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
> > >>>>>>> Tapestry / Tacos developer
> > >>>>>>> Open Source / J2EE Consulting
> > >>>>>>>
> > >>>>>>>
> > >>>>>>>
> > >> ---------------------------------------------------------------------
> > >>>>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > >>>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
> > >>>>>>>
> > >>>>>>>
> > >>>>> --
> > >>>>> Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
> > >>>>> Tapestry / Tacos developer
> > >>>>> Open Source / J2EE Consulting
> > >>>>>
> > >>>>>
> > >>>>>
> > >> ---------------------------------------------------------------------
> > >>>>> 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: [T4]Handling Nulls in OGNL expressions

Posted by Marcos Chicote <to...@gmail.com>.
I wouldn't mind implementing a hivemind service if I could solve the problem
this way, but I don't know how to implement the behaviour that I want. I
want exactly what you discribe happens in WebObjets: if at any point in the
ognl chain a null object is invoked, the hole expression evaluates to null
(or "").

Could anyone help me on doing this?

I have a hivemind service that captures null using interface NullHandler,
but now I'm stuck!

Thanks!

Marcos

On 7/29/07, Damien Uern <da...@synect.com> wrote:
>
> (Sorry for top posting, but everybody else seems to do it on this list)
>
> Anyway, the null pointer exception in a long property access chain was
> one of the issues I had with OGNL a while ago and have basically just
> learned to live with it. It is highly annoying. One of the things I
> preferred with Apple's WebObjects (which used NSKeyValueCoding for
> property access expressions) was that if any object in the chain was
> null, it just returned null. So if you have the expression:
>
> a.b.c.d
>
> where c is null, the entire expression would evaluate to null. Having to
> implement some sort of hivemind null pointer handling service just to
> get this sort of behaviour just screams "over designed" to me.
>
> (Not that I'm knocking OGNL/Tapestry in general, I still prefer using it
> over WebObjects for a variety of reasons).
>
> Damien
>
> Martino Piccinato wrote:
> > In my opinion is all that you want is not having NullPointerException it
> > would be better to implement MethodAccessor and/or PropertyAccessor,
> that
> > would return null if the target object is null, then you could simply
> check
> > expressions returning nulls and returning your message, or maybe have a
> > special component doing this.
> >
> > Tapestry has configuration point also for default Method/Property
> accessors.
> >
> >
> > On 7/26/07, Marcos Chicote <to...@gmail.com> wrote:
> >> Responding to my own mail...
> >>
> >> I found an old Andreas mail to the lis (
> >>
> http://mail-archives.apache.org/mod_mbox/tapestry-dev/200606.mbox/%3C29991907.1149520711057.JavaMail.jira@brutus%3E
> >> )
> >>
> >> that explained how to do this.
> >>
> >> I'll sumarize my ideas so that I can check if they are correct and
> maybe
> >> it
> >> will result usefull to the next person that wants to do this.
> >>
> >> The idea is to define a class that implements NullHandler (
> >> http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/NullHandler.html).
> >> That class job is to handle null's when an specific class access to
> >> property
> >> returns null.
> >> To make tapestry use your NullHandler you define something like this in
> >> your hivemind configuration file:
> >>
> >>     <contribution configuration-id="tapestry.ognl.NullHandlers">
> >>         <null-handler class="classThatImplementsNullHandler"
> >>             object="instance:classToCaptureNulls"/>
> >>     </contribution>
> >>
> >> where classToCaptureNulls represents the name of the class who's nulls
> you
> >>
> >> want to handle and classThatImplementsNullHandler represents the class
> >> that
> >> knows how to deal with nulls in classToCaptureNulls.
> >>
> >> Now that I have this working I would like to know how to use it :D
> >>
> >> I mean, if I have a long ognl expression like obj1.obj2.obj3.obj4 and
> >> access
> >> to obj2 in obj1 return null, I would like to show an "obj2 not
> available"
> >> message on screen.
> >>
> >> Can anyone help me on how to use this service?
> >>
> >> Thanks!
> >>
> >> Marcos
> >>
> >> On 7/26/07, Marcos Chicote <to...@gmail.com> wrote:
> >>> Hi Andreas!
> >>> When I emailed to Tapestry's list I was prototyping a project. Now I'm
> >>> actually developing it and I'm very interested in getting this service
> >>> working.
> >>>
> >>> Did you find some code where you used this feature?
> >>>
> >>> Thanks!
> >>>
> >>> Marcos
> >>>
> >>> On 6/29/07, Marcos Chicote <to...@gmail.com> wrote:
> >>>> Thanks Andreas.
> >>>> I have to do some more reading then.
> >>>>
> >>>> I you have some code that I can use as an example I would be really
> >>>> grateful.
> >>>>
> >>>> Thanks!
> >>>>
> >>>> Marcos
> >>>>
> >>>> On 6/29/07, Andreas Andreou < andyhot@di.uoa.gr> wrote:
> >>>>> O/H Marcos Chicote έγραψε:
> >>>>>> Thanks Andreas.
> >>>>>> Before mailing to this list, I tried looking at the ognl
> >>>>> documentation
> >>>>>> and I
> >>>>>> found the NullHandler interface but I wasn't sure how it worked
> >> with
> >>>>>> Tapestry or if it was possible to do it another way without
> >> altering
> >>>>> the
> >>>>>> BOs.
> >>>>>>
> >>>>>> Correct me if I'm wrong but what I understand is that Tapestry
> >>>>> already
> >>>>>> implements a Hivemind service that does the null handling. All I
> >>>>> have
> >>>>>> to do
> >>>>>> is make my BOs implement NullHandler interface. Am I right?
> >>>>> Hmmm, not really... Tapestry simply provides that point so that your
> >>>>> have a global
> >>>>> way of registring handlers - so, making your BOs implement
> >> NullHandler
> >>>>> is not enough
> >>>>>
> >>>>> Also, i'm not sure if that's the correct approach - seems it polutes
> >>>>> your BOs
> >>>>>
> >>>>> I think I'd create a service that would be able to null-handle your
> >>>>> specific objects, and
> >>>>> esp. of all those objects have a common superclass, i'd be able to
> >>>>> register them all at once.
> >>>>>
> >>>>> I'll dig in for some code - it's been a while since i last used this
> >>>>>
> >>>>>> Thanks a lot!
> >>>>>>
> >>>>>> Marcos
> >>>>>>
> >>>>>> On 6/29/07, Andreas Andreou <an...@di.uoa.gr> wrote:
> >>>>>>>
> >>>>>>>
> >>>>>
> http://tapestry.apache.org/tapestry4.1/tapestry-framework/hivedoc/config/tapestry.ognl.NullHandlers.html
> >>>>>>>
> >>>>>>> the way it works, is that you associate implementations of
> >>>>>>>
> >> http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/NullHandler.html
> >>>>>>> with class types whose methods (or properties) may return null
> >>>>>>>
> >>>>>>> O/H Marcos Chicote έγραψε:
> >>>>>>>> Hi!
> >>>>>>>> I have a Table component (actually I have TableRows, TableView,
> >>>>> and
> >>>>>>> all
> >>>>>>>> those other components that form a Table) and one of the
> >> columns
> >>>>> in
> >>>>>>>> TableView is declared like this: columnName:
> >>>>> object1.object2.property.
> >>>>>>>> As you can see this can throw NullPointerException if either
> >>>>>>> object1 or
> >>>>>>>> object2 are null.
> >>>>>>>>
> >>>>>>>> To solve this problem, I have to alternatives:
> >>>>>>>> a) Use a Block component called columnNameColumnValue an inside
> >>>>> the
> >>>>>>>> block an
> >>>>>>>> Insert component with a value asociated with the page's class
> >>>>> that
> >>>>>>>> handles
> >>>>>>>> nulls
> >>>>>>>> b) Declare the column like: columnName:object1.propertyObject2.
> >>>>> (that
> >>>>>>>> it a
> >>>>>>>> getPropertyObject2 method in object1 class that handles nulls).
> >>>>>>>> Is there a better way to solve this?? I would love something
> >> like
> >>>>> a
> >>>>>>>> prefix
> >>>>>>>> that allows me to specify that whenever a NPE is found, a blank
> >>>>>>> space is
> >>>>>>>> rendered. Is something like that possible?
> >>>>>>>>
> >>>>>>>> I'm ussing Tapestry 4.1.1.
> >>>>>>>>
> >>>>>>>> Btw, great work with Tap4.1.2, congratulations!
> >>>>>>>>
> >>>>>>>> Thanks!
> >>>>>>>>
> >>>>>>> --
> >>>>>>> Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
> >>>>>>> Tapestry / Tacos developer
> >>>>>>> Open Source / J2EE Consulting
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >> ---------------------------------------------------------------------
> >>>>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >>>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
> >>>>>>>
> >>>>>>>
> >>>>> --
> >>>>> Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
> >>>>> Tapestry / Tacos developer
> >>>>> Open Source / J2EE Consulting
> >>>>>
> >>>>>
> >>>>>
> >> ---------------------------------------------------------------------
> >>>>> 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: [T4]Handling Nulls in OGNL expressions

Posted by Damien Uern <da...@synect.com>.
(Sorry for top posting, but everybody else seems to do it on this list)

Anyway, the null pointer exception in a long property access chain was 
one of the issues I had with OGNL a while ago and have basically just 
learned to live with it. It is highly annoying. One of the things I 
preferred with Apple's WebObjects (which used NSKeyValueCoding for 
property access expressions) was that if any object in the chain was 
null, it just returned null. So if you have the expression:

a.b.c.d

where c is null, the entire expression would evaluate to null. Having to 
implement some sort of hivemind null pointer handling service just to 
get this sort of behaviour just screams "over designed" to me.

(Not that I'm knocking OGNL/Tapestry in general, I still prefer using it 
over WebObjects for a variety of reasons).

Damien

Martino Piccinato wrote:
> In my opinion is all that you want is not having NullPointerException it
> would be better to implement MethodAccessor and/or PropertyAccessor, that
> would return null if the target object is null, then you could simply check
> expressions returning nulls and returning your message, or maybe have a
> special component doing this.
> 
> Tapestry has configuration point also for default Method/Property accessors.
> 
> 
> On 7/26/07, Marcos Chicote <to...@gmail.com> wrote:
>> Responding to my own mail...
>>
>> I found an old Andreas mail to the lis (
>> http://mail-archives.apache.org/mod_mbox/tapestry-dev/200606.mbox/%3C29991907.1149520711057.JavaMail.jira@brutus%3E
>> )
>>
>> that explained how to do this.
>>
>> I'll sumarize my ideas so that I can check if they are correct and maybe
>> it
>> will result usefull to the next person that wants to do this.
>>
>> The idea is to define a class that implements NullHandler (
>> http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/NullHandler.html).
>> That class job is to handle null's when an specific class access to
>> property
>> returns null.
>> To make tapestry use your NullHandler you define something like this in
>> your hivemind configuration file:
>>
>>     <contribution configuration-id="tapestry.ognl.NullHandlers">
>>         <null-handler class="classThatImplementsNullHandler"
>>             object="instance:classToCaptureNulls"/>
>>     </contribution>
>>
>> where classToCaptureNulls represents the name of the class who's nulls you
>>
>> want to handle and classThatImplementsNullHandler represents the class
>> that
>> knows how to deal with nulls in classToCaptureNulls.
>>
>> Now that I have this working I would like to know how to use it :D
>>
>> I mean, if I have a long ognl expression like obj1.obj2.obj3.obj4 and
>> access
>> to obj2 in obj1 return null, I would like to show an "obj2 not available"
>> message on screen.
>>
>> Can anyone help me on how to use this service?
>>
>> Thanks!
>>
>> Marcos
>>
>> On 7/26/07, Marcos Chicote <to...@gmail.com> wrote:
>>> Hi Andreas!
>>> When I emailed to Tapestry's list I was prototyping a project. Now I'm
>>> actually developing it and I'm very interested in getting this service
>>> working.
>>>
>>> Did you find some code where you used this feature?
>>>
>>> Thanks!
>>>
>>> Marcos
>>>
>>> On 6/29/07, Marcos Chicote <to...@gmail.com> wrote:
>>>> Thanks Andreas.
>>>> I have to do some more reading then.
>>>>
>>>> I you have some code that I can use as an example I would be really
>>>> grateful.
>>>>
>>>> Thanks!
>>>>
>>>> Marcos
>>>>
>>>> On 6/29/07, Andreas Andreou < andyhot@di.uoa.gr> wrote:
>>>>> O/H Marcos Chicote έγραψε:
>>>>>> Thanks Andreas.
>>>>>> Before mailing to this list, I tried looking at the ognl
>>>>> documentation
>>>>>> and I
>>>>>> found the NullHandler interface but I wasn't sure how it worked
>> with
>>>>>> Tapestry or if it was possible to do it another way without
>> altering
>>>>> the
>>>>>> BOs.
>>>>>>
>>>>>> Correct me if I'm wrong but what I understand is that Tapestry
>>>>> already
>>>>>> implements a Hivemind service that does the null handling. All I
>>>>> have
>>>>>> to do
>>>>>> is make my BOs implement NullHandler interface. Am I right?
>>>>> Hmmm, not really... Tapestry simply provides that point so that your
>>>>> have a global
>>>>> way of registring handlers - so, making your BOs implement
>> NullHandler
>>>>> is not enough
>>>>>
>>>>> Also, i'm not sure if that's the correct approach - seems it polutes
>>>>> your BOs
>>>>>
>>>>> I think I'd create a service that would be able to null-handle your
>>>>> specific objects, and
>>>>> esp. of all those objects have a common superclass, i'd be able to
>>>>> register them all at once.
>>>>>
>>>>> I'll dig in for some code - it's been a while since i last used this
>>>>>
>>>>>> Thanks a lot!
>>>>>>
>>>>>> Marcos
>>>>>>
>>>>>> On 6/29/07, Andreas Andreou <an...@di.uoa.gr> wrote:
>>>>>>>
>>>>>>>
>>>>> http://tapestry.apache.org/tapestry4.1/tapestry-framework/hivedoc/config/tapestry.ognl.NullHandlers.html
>>>>>>>
>>>>>>> the way it works, is that you associate implementations of
>>>>>>>
>> http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/NullHandler.html
>>>>>>> with class types whose methods (or properties) may return null
>>>>>>>
>>>>>>> O/H Marcos Chicote έγραψε:
>>>>>>>> Hi!
>>>>>>>> I have a Table component (actually I have TableRows, TableView,
>>>>> and
>>>>>>> all
>>>>>>>> those other components that form a Table) and one of the
>> columns
>>>>> in
>>>>>>>> TableView is declared like this: columnName:
>>>>> object1.object2.property.
>>>>>>>> As you can see this can throw NullPointerException if either
>>>>>>> object1 or
>>>>>>>> object2 are null.
>>>>>>>>
>>>>>>>> To solve this problem, I have to alternatives:
>>>>>>>> a) Use a Block component called columnNameColumnValue an inside
>>>>> the
>>>>>>>> block an
>>>>>>>> Insert component with a value asociated with the page's class
>>>>> that
>>>>>>>> handles
>>>>>>>> nulls
>>>>>>>> b) Declare the column like: columnName:object1.propertyObject2.
>>>>> (that
>>>>>>>> it a
>>>>>>>> getPropertyObject2 method in object1 class that handles nulls).
>>>>>>>> Is there a better way to solve this?? I would love something
>> like
>>>>> a
>>>>>>>> prefix
>>>>>>>> that allows me to specify that whenever a NPE is found, a blank
>>>>>>> space is
>>>>>>>> rendered. Is something like that possible?
>>>>>>>>
>>>>>>>> I'm ussing Tapestry 4.1.1.
>>>>>>>>
>>>>>>>> Btw, great work with Tap4.1.2, congratulations!
>>>>>>>>
>>>>>>>> Thanks!
>>>>>>>>
>>>>>>> --
>>>>>>> Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
>>>>>>> Tapestry / Tacos developer
>>>>>>> Open Source / J2EE Consulting
>>>>>>>
>>>>>>>
>>>>>>>
>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>>>>
>>>>>>>
>>>>> --
>>>>> Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
>>>>> Tapestry / Tacos developer
>>>>> Open Source / J2EE Consulting
>>>>>
>>>>>
>>>>>
>> ---------------------------------------------------------------------
>>>>> 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: [T4]Handling Nulls in OGNL expressions

Posted by Martino Piccinato <ma...@gmail.com>.
In my opinion is all that you want is not having NullPointerException it
would be better to implement MethodAccessor and/or PropertyAccessor, that
would return null if the target object is null, then you could simply check
expressions returning nulls and returning your message, or maybe have a
special component doing this.

Tapestry has configuration point also for default Method/Property accessors.


On 7/26/07, Marcos Chicote <to...@gmail.com> wrote:
>
> Responding to my own mail...
>
> I found an old Andreas mail to the lis (
> http://mail-archives.apache.org/mod_mbox/tapestry-dev/200606.mbox/%3C29991907.1149520711057.JavaMail.jira@brutus%3E
> )
>
> that explained how to do this.
>
> I'll sumarize my ideas so that I can check if they are correct and maybe
> it
> will result usefull to the next person that wants to do this.
>
> The idea is to define a class that implements NullHandler (
> http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/NullHandler.html).
> That class job is to handle null's when an specific class access to
> property
> returns null.
> To make tapestry use your NullHandler you define something like this in
> your hivemind configuration file:
>
>     <contribution configuration-id="tapestry.ognl.NullHandlers">
>         <null-handler class="classThatImplementsNullHandler"
>             object="instance:classToCaptureNulls"/>
>     </contribution>
>
> where classToCaptureNulls represents the name of the class who's nulls you
>
> want to handle and classThatImplementsNullHandler represents the class
> that
> knows how to deal with nulls in classToCaptureNulls.
>
> Now that I have this working I would like to know how to use it :D
>
> I mean, if I have a long ognl expression like obj1.obj2.obj3.obj4 and
> access
> to obj2 in obj1 return null, I would like to show an "obj2 not available"
> message on screen.
>
> Can anyone help me on how to use this service?
>
> Thanks!
>
> Marcos
>
> On 7/26/07, Marcos Chicote <to...@gmail.com> wrote:
> >
> > Hi Andreas!
> > When I emailed to Tapestry's list I was prototyping a project. Now I'm
> > actually developing it and I'm very interested in getting this service
> > working.
> >
> > Did you find some code where you used this feature?
> >
> > Thanks!
> >
> > Marcos
> >
> > On 6/29/07, Marcos Chicote <to...@gmail.com> wrote:
> > >
> > > Thanks Andreas.
> > > I have to do some more reading then.
> > >
> > > I you have some code that I can use as an example I would be really
> > > grateful.
> > >
> > > Thanks!
> > >
> > > Marcos
> > >
> > > On 6/29/07, Andreas Andreou < andyhot@di.uoa.gr> wrote:
> > > >
> > > > O/H Marcos Chicote έγραψε:
> > > > > Thanks Andreas.
> > > > > Before mailing to this list, I tried looking at the ognl
> > > > documentation
> > > > > and I
> > > > > found the NullHandler interface but I wasn't sure how it worked
> with
> > > >
> > > > > Tapestry or if it was possible to do it another way without
> altering
> > > > the
> > > > > BOs.
> > > > >
> > > > > Correct me if I'm wrong but what I understand is that Tapestry
> > > > already
> > > > > implements a Hivemind service that does the null handling. All I
> > > > have
> > > > > to do
> > > > > is make my BOs implement NullHandler interface. Am I right?
> > > > Hmmm, not really... Tapestry simply provides that point so that your
>
> > > > have a global
> > > > way of registring handlers - so, making your BOs implement
> NullHandler
> > > >
> > > > is not enough
> > > >
> > > > Also, i'm not sure if that's the correct approach - seems it polutes
>
> > > > your BOs
> > > >
> > > > I think I'd create a service that would be able to null-handle your
> > > > specific objects, and
> > > > esp. of all those objects have a common superclass, i'd be able to
> > > > register them all at once.
> > > >
> > > > I'll dig in for some code - it's been a while since i last used this
> > > >
> > > > >
> > > > > Thanks a lot!
> > > > >
> > > > > Marcos
> > > > >
> > > > > On 6/29/07, Andreas Andreou <an...@di.uoa.gr> wrote:
> > > > >>
> > > > >>
> > > > >>
> > > > http://tapestry.apache.org/tapestry4.1/tapestry-framework/hivedoc/config/tapestry.ognl.NullHandlers.html
>
> > > > >>
> > > > >>
> > > > >> the way it works, is that you associate implementations of
> > > > >>
> > > >
> http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/NullHandler.html
> > > > >> with class types whose methods (or properties) may return null
> > > > >>
> > > > >> O/H Marcos Chicote έγραψε:
> > > > >> > Hi!
> > > > >> > I have a Table component (actually I have TableRows, TableView,
> > > > and
> > > > >> all
> > > > >> > those other components that form a Table) and one of the
> columns
> > > > in
> > > > >> > TableView is declared like this: columnName:
> > > > object1.object2.property.
> > > > >> >
> > > > >> > As you can see this can throw NullPointerException if either
> > > > >> object1 or
> > > > >> > object2 are null.
> > > > >> >
> > > > >> > To solve this problem, I have to alternatives:
> > > > >> > a) Use a Block component called columnNameColumnValue an inside
>
> > > > the
> > > > >> > block an
> > > > >> > Insert component with a value asociated with the page's class
> > > > that
> > > > >> > handles
> > > > >> > nulls
> > > > >> > b) Declare the column like: columnName:object1.propertyObject2.
> > > > (that
> > > > >> > it a
> > > > >> > getPropertyObject2 method in object1 class that handles nulls).
>
> > > > >> >
> > > > >> > Is there a better way to solve this?? I would love something
> like
> > > > a
> > > > >> > prefix
> > > > >> > that allows me to specify that whenever a NPE is found, a blank
>
> > > > >> space is
> > > > >> > rendered. Is something like that possible?
> > > > >> >
> > > > >> > I'm ussing Tapestry 4.1.1.
> > > > >> >
> > > > >> > Btw, great work with Tap4.1.2, congratulations!
> > > > >> >
> > > > >> > Thanks!
> > > > >> >
> > > > >>
> > > > >> --
> > > > >> Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
> > > > >> Tapestry / Tacos developer
> > > > >> Open Source / J2EE Consulting
> > > > >>
> > > > >>
> > > > >>
> > > >
> ---------------------------------------------------------------------
> > > > >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > > > >> For additional commands, e-mail: users-help@tapestry.apache.org
> > > > >>
> > > > >>
> > > >
> > > > --
> > > > Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
> > > > Tapestry / Tacos developer
> > > > Open Source / J2EE Consulting
> > > >
> > > >
> > > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > > > For additional commands, e-mail: users-help@tapestry.apache.org
> > > >
> > > >
> > >
> >
>

Re: [T4]Handling Nulls in OGNL expressions

Posted by Marcos Chicote <to...@gmail.com>.
Responding to my own mail...

I found an old Andreas mail to the lis (
http://mail-archives.apache.org/mod_mbox/tapestry-dev/200606.mbox/%3C29991907.1149520711057.JavaMail.jira@brutus%3E)

that explained how to do this.

I'll sumarize my ideas so that I can check if they are correct and maybe it
will result usefull to the next person that wants to do this.

The idea is to define a class that implements NullHandler (
http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/NullHandler.html).
That class job is to handle null's when an specific class access to property
returns null.
To make tapestry use your NullHandler you define something like this in
your hivemind configuration file:

    <contribution configuration-id="tapestry.ognl.NullHandlers">
        <null-handler class="classThatImplementsNullHandler"
            object="instance:classToCaptureNulls"/>
    </contribution>

where classToCaptureNulls represents the name of the class who's nulls you
want to handle and classThatImplementsNullHandler represents the class that
knows how to deal with nulls in classToCaptureNulls.

Now that I have this working I would like to know how to use it :D

I mean, if I have a long ognl expression like obj1.obj2.obj3.obj4 and access
to obj2 in obj1 return null, I would like to show an "obj2 not available"
message on screen.

Can anyone help me on how to use this service?

Thanks!

Marcos

On 7/26/07, Marcos Chicote <to...@gmail.com> wrote:
>
> Hi Andreas!
> When I emailed to Tapestry's list I was prototyping a project. Now I'm
> actually developing it and I'm very interested in getting this service
> working.
>
> Did you find some code where you used this feature?
>
> Thanks!
>
> Marcos
>
> On 6/29/07, Marcos Chicote <to...@gmail.com> wrote:
> >
> > Thanks Andreas.
> > I have to do some more reading then.
> >
> > I you have some code that I can use as an example I would be really
> > grateful.
> >
> > Thanks!
> >
> > Marcos
> >
> > On 6/29/07, Andreas Andreou <an...@di.uoa.gr> wrote:
> > >
> > > O/H Marcos Chicote έγραψε:
> > > > Thanks Andreas.
> > > > Before mailing to this list, I tried looking at the ognl
> > > documentation
> > > > and I
> > > > found the NullHandler interface but I wasn't sure how it worked with
> > >
> > > > Tapestry or if it was possible to do it another way without altering
> > > the
> > > > BOs.
> > > >
> > > > Correct me if I'm wrong but what I understand is that Tapestry
> > > already
> > > > implements a Hivemind service that does the null handling. All I
> > > have
> > > > to do
> > > > is make my BOs implement NullHandler interface. Am I right?
> > > Hmmm, not really... Tapestry simply provides that point so that your
> > > have a global
> > > way of registring handlers - so, making your BOs implement NullHandler
> > >
> > > is not enough
> > >
> > > Also, i'm not sure if that's the correct approach - seems it polutes
> > > your BOs
> > >
> > > I think I'd create a service that would be able to null-handle your
> > > specific objects, and
> > > esp. of all those objects have a common superclass, i'd be able to
> > > register them all at once.
> > >
> > > I'll dig in for some code - it's been a while since i last used this
> > >
> > > >
> > > > Thanks a lot!
> > > >
> > > > Marcos
> > > >
> > > > On 6/29/07, Andreas Andreou <an...@di.uoa.gr> wrote:
> > > >>
> > > >>
> > > >>
> > > http://tapestry.apache.org/tapestry4.1/tapestry-framework/hivedoc/config/tapestry.ognl.NullHandlers.html
> > > >>
> > > >>
> > > >> the way it works, is that you associate implementations of
> > > >>
> > > http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/NullHandler.html
> > > >> with class types whose methods (or properties) may return null
> > > >>
> > > >> O/H Marcos Chicote έγραψε:
> > > >> > Hi!
> > > >> > I have a Table component (actually I have TableRows, TableView,
> > > and
> > > >> all
> > > >> > those other components that form a Table) and one of the columns
> > > in
> > > >> > TableView is declared like this: columnName:
> > > object1.object2.property.
> > > >> >
> > > >> > As you can see this can throw NullPointerException if either
> > > >> object1 or
> > > >> > object2 are null.
> > > >> >
> > > >> > To solve this problem, I have to alternatives:
> > > >> > a) Use a Block component called columnNameColumnValue an inside
> > > the
> > > >> > block an
> > > >> > Insert component with a value asociated with the page's class
> > > that
> > > >> > handles
> > > >> > nulls
> > > >> > b) Declare the column like: columnName:object1.propertyObject2.
> > > (that
> > > >> > it a
> > > >> > getPropertyObject2 method in object1 class that handles nulls).
> > > >> >
> > > >> > Is there a better way to solve this?? I would love something like
> > > a
> > > >> > prefix
> > > >> > that allows me to specify that whenever a NPE is found, a blank
> > > >> space is
> > > >> > rendered. Is something like that possible?
> > > >> >
> > > >> > I'm ussing Tapestry 4.1.1.
> > > >> >
> > > >> > Btw, great work with Tap4.1.2, congratulations!
> > > >> >
> > > >> > Thanks!
> > > >> >
> > > >>
> > > >> --
> > > >> Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
> > > >> Tapestry / Tacos developer
> > > >> Open Source / J2EE Consulting
> > > >>
> > > >>
> > > >>
> > > ---------------------------------------------------------------------
> > > >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > > >> For additional commands, e-mail: users-help@tapestry.apache.org
> > > >>
> > > >>
> > >
> > > --
> > > Andreas Andreou - andyhot@apache.org - http://andyhot.di.uoa.gr
> > > Tapestry / Tacos developer
> > > Open Source / J2EE Consulting
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > > For additional commands, e-mail: users-help@tapestry.apache.org
> > >
> > >
> >
>