You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Shawn Church <sh...@boxity.com> on 2004/04/05 18:27:16 UTC
NPE during Conditional evaluation
What is the best way to support attributes which may be null within a
conditional? For example:
<span jwcid="@Foreach" source="ognl:fooList" value="ognl:fooBean">
<span jwcid="@Conditional" condition='ognl:fooBean.Bar.equals("abc")'>
If fooBean.Bar is null, then the page render fails with an NPE. I've
tried moving the conditional to the .page file, like:
<component id="isAbc" type="Conditional">
<binding name="condition"
expression='fooBean, fooBean.Bar, fooBean.Bar.equals("abc")'/>
</component>
I hoped the expression would stop evaluating if a null Bar was
encountered, but it fails the same way.
I couldn't find anything in Tapestry which implements the ognl
NullHandler interface, but maybe I could use that. This is more of an
ognl rather than a Tapestry issue, but I think this may be a fairly
common situation.
Shawn
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: NPE during Conditional evaluation
Posted by Shawn Church <sh...@boxity.com>.
Jamie,
Thanks, I wasn't sure of the ognl syntax. This seems to work fine.
Shawn
Quoting Jamie Orchard-Hays <ja...@dang.com>:
> You could try:
> <span jwcid="@Conditional" condition='ognl:fooBean.Barfoo eq null ?
> false :
> Bean.Bar.equals("abc")'>
>
>
>
> ----- Original Message -----
> From: "Shawn Church" <sh...@boxity.com>
> To: "Tapestry users" <ta...@jakarta.apache.org>
> Sent: Monday, April 05, 2004 12:27 PM
> Subject: NPE during Conditional evaluation
>
>
> > What is the best way to support attributes which may be null within
> a
> > conditional? For example:
> >
> > <span jwcid="@Foreach" source="ognl:fooList" value="ognl:fooBean">
> > <span jwcid="@Conditional"
> condition='ognl:fooBean.Bar.equals("abc")'>
> >
> > If fooBean.Bar is null, then the page render fails with an NPE.
> I've
> > tried moving the conditional to the .page file, like:
> >
> > <component id="isAbc" type="Conditional">
> > <binding name="condition"
> > expression='fooBean, fooBean.Bar,
> fooBean.Bar.equals("abc")'/>
> > </component>
> >
> > I hoped the expression would stop evaluating if a null Bar was
> > encountered, but it fails the same way.
> >
> > I couldn't find anything in Tapestry which implements the ognl
> > NullHandler interface, but maybe I could use that. This is more of
> an
> > ognl rather than a Tapestry issue, but I think this may be a
> fairly
> > common situation.
> >
> > Shawn
> >
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: NPE during Conditional evaluation
Posted by Jamie Orchard-Hays <ja...@dang.com>.
You could try:
<span jwcid="@Conditional" condition='ognl:fooBean.Barfoo eq null ? false :
Bean.Bar.equals("abc")'>
----- Original Message -----
From: "Shawn Church" <sh...@boxity.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Monday, April 05, 2004 12:27 PM
Subject: NPE during Conditional evaluation
> What is the best way to support attributes which may be null within a
> conditional? For example:
>
> <span jwcid="@Foreach" source="ognl:fooList" value="ognl:fooBean">
> <span jwcid="@Conditional" condition='ognl:fooBean.Bar.equals("abc")'>
>
> If fooBean.Bar is null, then the page render fails with an NPE. I've
> tried moving the conditional to the .page file, like:
>
> <component id="isAbc" type="Conditional">
> <binding name="condition"
> expression='fooBean, fooBean.Bar, fooBean.Bar.equals("abc")'/>
> </component>
>
> I hoped the expression would stop evaluating if a null Bar was
> encountered, but it fails the same way.
>
> I couldn't find anything in Tapestry which implements the ognl
> NullHandler interface, but maybe I could use that. This is more of an
> ognl rather than a Tapestry issue, but I think this may be a fairly
> common situation.
>
> Shawn
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: NPE during Conditional evaluation
Posted by Jamie Orchard-Hays <ja...@dang.com>.
I think this would also work
<span jwcid="@Conditional" condition='ognl: ("abc").equals(fooBean.Bar)'>
Jamie
----- Original Message -----
From: "Shawn Church" <sh...@boxity.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Monday, April 05, 2004 12:27 PM
Subject: NPE during Conditional evaluation
> What is the best way to support attributes which may be null within a
> conditional? For example:
>
> <span jwcid="@Foreach" source="ognl:fooList" value="ognl:fooBean">
> <span jwcid="@Conditional" condition='ognl:fooBean.Bar.equals("abc")'>
>
> If fooBean.Bar is null, then the page render fails with an NPE. I've
> tried moving the conditional to the .page file, like:
>
> <component id="isAbc" type="Conditional">
> <binding name="condition"
> expression='fooBean, fooBean.Bar, fooBean.Bar.equals("abc")'/>
> </component>
>
> I hoped the expression would stop evaluating if a null Bar was
> encountered, but it fails the same way.
>
> I couldn't find anything in Tapestry which implements the ognl
> NullHandler interface, but maybe I could use that. This is more of an
> ognl rather than a Tapestry issue, but I think this may be a fairly
> common situation.
>
> Shawn
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: NPE during Conditional evaluation
Posted by Jonny Wray <jo...@yahoo.com>.
Well, the code to register all the classes of a particular package is
below. I see your approach with pages, and it may well work in some
situations. In my case, I have some of my own services that use ognl
for graph navigation, and so the ognl expression is not using a page as
its base object. So, I need to register my domain objects. I could just
register the ones I need, but this way is safer.
Anyway, here's the method that gets called from the servlet init
method:
private void registerNullObjectHandler() throws ServletException {
try {
String resource =
this.getClass().getClassLoader().getResource(PACKAGE + PACKAGE_SEP +
CLASS).toExternalForm();
int start = resource.indexOf(PREFIX) + PREFIX.length();
int stop = resource.indexOf("!");
String fileName = resource.substring(start, stop);
JarFile jarFile = new JarFile(fileName);
Enumeration enum = jarFile.entries();
while(enum.hasMoreElements()){
String entry = enum.nextElement().toString();
if(entry.startsWith(PACKAGE.replace(PACKAGE_SEP, RESOURCE_SEP)) &&
entry.endsWith(DOT_CLASS)){
String className = entry.substring(0,
entry.lastIndexOf(DOT_CLASS)).replace(RESOURCE_SEP, PACKAGE_SEP);
log.debug("Registering null object handler for "+className);
OgnlRuntime.setNullHandler(Class.forName(className), new
NullObjectHandler());
}
}
}
catch (IOException e) {
log.error("Unable to initialize servlet", e);
throw new ServletException(e);
}
catch (ClassNotFoundException e) {
log.error("Unable to initialize servlet", e);
throw new ServletException(e);
}
}
--- Shawn Church <sh...@boxity.com> wrote:
> I would be interested if you don't mind posting it. I can think of a
>
> couple of approaches off-hand, but it sounds like you've already
> thought it through.
>
> Since Tapestry maintains a page cache, I wonder if it could be in
> control of the OGNL registrations. There wouldn't be a need to
> register non-page classes, and the decision of whether to register a
> handler could be controlled by an application property.
>
> Shawn
>
>
> Quoting Jonny Wray <jo...@yahoo.com>:
>
> >
> > Exactly, I wanted a solution that would just work and I didn't have
> > to
> > worry about it for every attribute access.
> >
> > The registering does work on an explicit class by class basis. It
> was
> > a
> > bit of a pain. I wanted to register every class in my domain model,
> > and
> > there's no (easy) way of getting a list of all classes in a
> package.
> > I
> > did work out a solution for that which I can post if you're
> > interested.
> > If you've only got a few classes it might just be easier to do them
> > explicitly.
> >
> > Jonny
> >
> > --- Shawn Church <sh...@boxity.com> wrote:
> > > Jonny,
> > >
> > > I will give this a try. Jamie's solution works on-demand, but it
> > > might
> > > make sense to have the option of setting a handler at the
> > application
> > >
> > > level. It looks like this works by registering each class
> > > explicitly,
> > > right?
> > >
> > > Why doesn't Tapestry catch the exception thrown by OGNL? I
> suppose
> >
> > > overriding Conditional may also be an option (so it can handle
> the
> >
> > > exceptions more gracefully).
> > >
> > > Shawn
> > >
> > >
> > > Quoting Jonny Wray <jo...@yahoo.com>:
> > >
> > > >
> > > > Shawn,
> > > >
> > > > my solution to the problem of handling null object is to
> register
> > a
> > > > null handler with the ognl runtime via:
> > > >
> > > > OgnlRuntime.setNullHandler(Class, NullObjectHandler)
> > > >
> > > > I do this in the init method of my own extension of
> > > > ApplicationServlet.
> > > > The NullObjectHandler returns an empty map, which then stops
> the
> > > > ognl
> > > > graph traversal.
> > > >
> > > > I would like to hear other people's solutions though, as I
> never
> > > > really
> > > > liked this one.
> > > >
> > > > Jonny
> > > >
> > > > --- Shawn Church <sh...@boxity.com> wrote:
> > > > > What is the best way to support attributes which may be null
> > > within
> > > > a
> > > > >
> > > > > conditional? For example:
> > > > >
> > > > > <span jwcid="@Foreach" source="ognl:fooList"
> > > value="ognl:fooBean">
> > > > > <span jwcid="@Conditional"
> > > > > condition='ognl:fooBean.Bar.equals("abc")'>
> > > > >
> > > > > If fooBean.Bar is null, then the page render fails with an
> NPE.
> >
> > > > I've
> > > > >
> > > > > tried moving the conditional to the .page file, like:
> > > > >
> > > > > <component id="isAbc" type="Conditional">
> > > > > <binding name="condition"
> > > > > expression='fooBean, fooBean.Bar,
> > > > > fooBean.Bar.equals("abc")'/>
> > > > > </component>
> > > > >
> > > > > I hoped the expression would stop evaluating if a null Bar
> was
> >
> > > > > encountered, but it fails the same way.
> > > > >
> > > > > I couldn't find anything in Tapestry which implements the
> ognl
> >
> > > > > NullHandler interface, but maybe I could use that. This is
> > more
> > > > of
> > > > > an
> > > > > ognl rather than a Tapestry issue, but I think this may be a
> > > fairly
> > > >
> > > > > common situation.
> > > > >
> > > > > Shawn
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > >
> >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail:
> > > > tapestry-user-unsubscribe@jakarta.apache.org
> > > > > For additional commands, e-mail:
> > > > > tapestry-user-help@jakarta.apache.org
> > > > >
> > > >
> > > >
> > > >
> > >
> >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> > > tapestry-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
> > > > tapestry-user-help@jakarta.apache.org
> > > >
> > >
> > >
> > >
> > >
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > tapestry-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> > > tapestry-user-help@jakarta.apache.org
> > >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > tapestry-user-help@jakarta.apache.org
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: NPE during Conditional evaluation
Posted by Shawn Church <sh...@boxity.com>.
I would be interested if you don't mind posting it. I can think of a
couple of approaches off-hand, but it sounds like you've already
thought it through.
Since Tapestry maintains a page cache, I wonder if it could be in
control of the OGNL registrations. There wouldn't be a need to
register non-page classes, and the decision of whether to register a
handler could be controlled by an application property.
Shawn
Quoting Jonny Wray <jo...@yahoo.com>:
>
> Exactly, I wanted a solution that would just work and I didn't have
> to
> worry about it for every attribute access.
>
> The registering does work on an explicit class by class basis. It was
> a
> bit of a pain. I wanted to register every class in my domain model,
> and
> there's no (easy) way of getting a list of all classes in a package.
> I
> did work out a solution for that which I can post if you're
> interested.
> If you've only got a few classes it might just be easier to do them
> explicitly.
>
> Jonny
>
> --- Shawn Church <sh...@boxity.com> wrote:
> > Jonny,
> >
> > I will give this a try. Jamie's solution works on-demand, but it
> > might
> > make sense to have the option of setting a handler at the
> application
> >
> > level. It looks like this works by registering each class
> > explicitly,
> > right?
> >
> > Why doesn't Tapestry catch the exception thrown by OGNL? I suppose
>
> > overriding Conditional may also be an option (so it can handle the
>
> > exceptions more gracefully).
> >
> > Shawn
> >
> >
> > Quoting Jonny Wray <jo...@yahoo.com>:
> >
> > >
> > > Shawn,
> > >
> > > my solution to the problem of handling null object is to register
> a
> > > null handler with the ognl runtime via:
> > >
> > > OgnlRuntime.setNullHandler(Class, NullObjectHandler)
> > >
> > > I do this in the init method of my own extension of
> > > ApplicationServlet.
> > > The NullObjectHandler returns an empty map, which then stops the
> > > ognl
> > > graph traversal.
> > >
> > > I would like to hear other people's solutions though, as I never
> > > really
> > > liked this one.
> > >
> > > Jonny
> > >
> > > --- Shawn Church <sh...@boxity.com> wrote:
> > > > What is the best way to support attributes which may be null
> > within
> > > a
> > > >
> > > > conditional? For example:
> > > >
> > > > <span jwcid="@Foreach" source="ognl:fooList"
> > value="ognl:fooBean">
> > > > <span jwcid="@Conditional"
> > > > condition='ognl:fooBean.Bar.equals("abc")'>
> > > >
> > > > If fooBean.Bar is null, then the page render fails with an NPE.
>
> > > I've
> > > >
> > > > tried moving the conditional to the .page file, like:
> > > >
> > > > <component id="isAbc" type="Conditional">
> > > > <binding name="condition"
> > > > expression='fooBean, fooBean.Bar,
> > > > fooBean.Bar.equals("abc")'/>
> > > > </component>
> > > >
> > > > I hoped the expression would stop evaluating if a null Bar was
>
> > > > encountered, but it fails the same way.
> > > >
> > > > I couldn't find anything in Tapestry which implements the ognl
>
> > > > NullHandler interface, but maybe I could use that. This is
> more
> > > of
> > > > an
> > > > ognl rather than a Tapestry issue, but I think this may be a
> > fairly
> > >
> > > > common situation.
> > > >
> > > > Shawn
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> > > tapestry-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
> > > > tapestry-user-help@jakarta.apache.org
> > > >
> > >
> > >
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > tapestry-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> > > tapestry-user-help@jakarta.apache.org
> > >
> >
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > tapestry-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: NPE during Conditional evaluation
Posted by Jonny Wray <jo...@yahoo.com>.
Exactly, I wanted a solution that would just work and I didn't have to
worry about it for every attribute access.
The registering does work on an explicit class by class basis. It was a
bit of a pain. I wanted to register every class in my domain model, and
there's no (easy) way of getting a list of all classes in a package. I
did work out a solution for that which I can post if you're interested.
If you've only got a few classes it might just be easier to do them
explicitly.
Jonny
--- Shawn Church <sh...@boxity.com> wrote:
> Jonny,
>
> I will give this a try. Jamie's solution works on-demand, but it
> might
> make sense to have the option of setting a handler at the application
>
> level. It looks like this works by registering each class
> explicitly,
> right?
>
> Why doesn't Tapestry catch the exception thrown by OGNL? I suppose
> overriding Conditional may also be an option (so it can handle the
> exceptions more gracefully).
>
> Shawn
>
>
> Quoting Jonny Wray <jo...@yahoo.com>:
>
> >
> > Shawn,
> >
> > my solution to the problem of handling null object is to register a
> > null handler with the ognl runtime via:
> >
> > OgnlRuntime.setNullHandler(Class, NullObjectHandler)
> >
> > I do this in the init method of my own extension of
> > ApplicationServlet.
> > The NullObjectHandler returns an empty map, which then stops the
> > ognl
> > graph traversal.
> >
> > I would like to hear other people's solutions though, as I never
> > really
> > liked this one.
> >
> > Jonny
> >
> > --- Shawn Church <sh...@boxity.com> wrote:
> > > What is the best way to support attributes which may be null
> within
> > a
> > >
> > > conditional? For example:
> > >
> > > <span jwcid="@Foreach" source="ognl:fooList"
> value="ognl:fooBean">
> > > <span jwcid="@Conditional"
> > > condition='ognl:fooBean.Bar.equals("abc")'>
> > >
> > > If fooBean.Bar is null, then the page render fails with an NPE.
> > I've
> > >
> > > tried moving the conditional to the .page file, like:
> > >
> > > <component id="isAbc" type="Conditional">
> > > <binding name="condition"
> > > expression='fooBean, fooBean.Bar,
> > > fooBean.Bar.equals("abc")'/>
> > > </component>
> > >
> > > I hoped the expression would stop evaluating if a null Bar was
> > > encountered, but it fails the same way.
> > >
> > > I couldn't find anything in Tapestry which implements the ognl
> > > NullHandler interface, but maybe I could use that. This is more
> > of
> > > an
> > > ognl rather than a Tapestry issue, but I think this may be a
> fairly
> >
> > > common situation.
> > >
> > > Shawn
> > >
> > >
> > >
> > >
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > tapestry-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> > > tapestry-user-help@jakarta.apache.org
> > >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > tapestry-user-help@jakarta.apache.org
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: NPE during Conditional evaluation
Posted by Shawn Church <sh...@boxity.com>.
Jonny,
I will give this a try. Jamie's solution works on-demand, but it might
make sense to have the option of setting a handler at the application
level. It looks like this works by registering each class explicitly,
right?
Why doesn't Tapestry catch the exception thrown by OGNL? I suppose
overriding Conditional may also be an option (so it can handle the
exceptions more gracefully).
Shawn
Quoting Jonny Wray <jo...@yahoo.com>:
>
> Shawn,
>
> my solution to the problem of handling null object is to register a
> null handler with the ognl runtime via:
>
> OgnlRuntime.setNullHandler(Class, NullObjectHandler)
>
> I do this in the init method of my own extension of
> ApplicationServlet.
> The NullObjectHandler returns an empty map, which then stops the
> ognl
> graph traversal.
>
> I would like to hear other people's solutions though, as I never
> really
> liked this one.
>
> Jonny
>
> --- Shawn Church <sh...@boxity.com> wrote:
> > What is the best way to support attributes which may be null within
> a
> >
> > conditional? For example:
> >
> > <span jwcid="@Foreach" source="ognl:fooList" value="ognl:fooBean">
> > <span jwcid="@Conditional"
> > condition='ognl:fooBean.Bar.equals("abc")'>
> >
> > If fooBean.Bar is null, then the page render fails with an NPE.
> I've
> >
> > tried moving the conditional to the .page file, like:
> >
> > <component id="isAbc" type="Conditional">
> > <binding name="condition"
> > expression='fooBean, fooBean.Bar,
> > fooBean.Bar.equals("abc")'/>
> > </component>
> >
> > I hoped the expression would stop evaluating if a null Bar was
> > encountered, but it fails the same way.
> >
> > I couldn't find anything in Tapestry which implements the ognl
> > NullHandler interface, but maybe I could use that. This is more
> of
> > an
> > ognl rather than a Tapestry issue, but I think this may be a fairly
>
> > common situation.
> >
> > Shawn
> >
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > tapestry-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: NPE during Conditional evaluation
Posted by Jonny Wray <jo...@yahoo.com>.
Shawn,
my solution to the problem of handling null object is to register a
null handler with the ognl runtime via:
OgnlRuntime.setNullHandler(Class, NullObjectHandler)
I do this in the init method of my own extension of ApplicationServlet.
The NullObjectHandler returns an empty map, which then stops the ognl
graph traversal.
I would like to hear other people's solutions though, as I never really
liked this one.
Jonny
--- Shawn Church <sh...@boxity.com> wrote:
> What is the best way to support attributes which may be null within a
>
> conditional? For example:
>
> <span jwcid="@Foreach" source="ognl:fooList" value="ognl:fooBean">
> <span jwcid="@Conditional"
> condition='ognl:fooBean.Bar.equals("abc")'>
>
> If fooBean.Bar is null, then the page render fails with an NPE. I've
>
> tried moving the conditional to the .page file, like:
>
> <component id="isAbc" type="Conditional">
> <binding name="condition"
> expression='fooBean, fooBean.Bar,
> fooBean.Bar.equals("abc")'/>
> </component>
>
> I hoped the expression would stop evaluating if a null Bar was
> encountered, but it fails the same way.
>
> I couldn't find anything in Tapestry which implements the ognl
> NullHandler interface, but maybe I could use that. This is more of
> an
> ognl rather than a Tapestry issue, but I think this may be a fairly
> common situation.
>
> Shawn
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org