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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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/[EMAIL > PROTECTED] > >> ) > >> > >> 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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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 < [EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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 - [EMAIL PROTECTED] - http://andyhot.di.uoa.gr > >>>>>>> Tapestry / Tacos developer > >>>>>>> Open Source / J2EE Consulting > >>>>>>> > >>>>>>> > >>>>>>> > >> --------------------------------------------------------------------- > >>>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED] > >>>>>>> For additional commands, e-mail: [EMAIL PROTECTED] > >>>>>>> > >>>>>>> > >>>>> -- > >>>>> Andreas Andreou - [EMAIL PROTECTED] - http://andyhot.di.uoa.gr > >>>>> Tapestry / Tacos developer > >>>>> Open Source / J2EE Consulting > >>>>> > >>>>> > >>>>> > >> --------------------------------------------------------------------- > >>>>> To unsubscribe, e-mail: [EMAIL PROTECTED] > >>>>> For additional commands, e-mail: [EMAIL PROTECTED] > >>>>> > >>>>> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >