[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tapestry-user
Subject:    Re: Navigate in the object graph in tapestry!!!
From:       Eduardo Valentim <valentim.eduardo () gmail ! com>
Date:       2006-04-28 17:37:19
Message-ID: 1146245839.3220.31.camel () manibu ! intranet ! cesar ! org ! br
[Download RAW message or body]

Andy,

       I have the same issue, but a have found a solution (I think).

       I made a little modification in this class
http://fisheye5.cenqua.com/viewrep/xwork/src/java/com/opensymphony/xwork/util/InstantiatingNullHandler.java \
from WebWork to work for me and override the method readCompiled from the class \
org.apache.tapestry.services.impl.ExpressionEvaluatorImpl as follow:

public class CustomExpressionEvaluatorImpl extends
ExpressionEvaluatorImpl {

    private static InstantiatingNullHandler handler;

    private InstantiatingNullHandler getHandler() {
        if (handler == null) {
            nhandler = new InstantiatingNullHandler();
        }

        return handler;
    }

    public Object readCompiled(Object target, Object expression) {
        if (target != null) {
            OgnlRuntime.setNullHandler(target.getClass, getHandler());
        }

        return super.readCompiled(target, expression);
    }

}

and to put this class to work I have to override the service point
tapestry.ognl.ExpressionEvaluator. 

<implementation service-id="tapestry.ognl.ExpressionEvaluator">
    <invoke-factory service-id="hivemind.BuilderFactory" model="singleton" >
        <construct class="package.CustomExpressionEvaluatorImpl" >
            <set-object property="applicationSpecification" \
                value="infrastructure:applicationSpecification" />
            <set-configuration configuration-id="PropertyAccessors" \
property="contributions" />  </construct>
    </invoke-factory>
</implementation>

See this link http://jakarta.apache.org/hivemind/override.html that
describe how to do this.

finally, whe my application loads, all is fine, but all this
configuration fails when I request the first page of application because
Hivemind say that CustomExpressionEvaluatorImpl dont have an property
called applicationSpecification but ExpressionEvaluatorImpl have a
method setApplicationSpecification() and I don't know what's happen.

I need a little help here, and this issue is solved. ;)

Thanks in Advances.

Eduardo Valentim

On Mon, 2006-04-24 at 22:57 +0300, andyhot@di.uoa.gr wrote:
> I remember last year, someone wanted to do the same thing...
> and he succeeded by patching ognl.
> 
> Looking at the link you provided, it seems that one can simply do
> a OgnlRuntime.setNullHandler. Have you tried that?
> 
> However, an additional configuration point for this ognl 
> setting would be nice...
> According to
> http://jakarta.apache.org/tapestry/tapestry/hivedocs/module/tapestry.ognl.html
> we only support custom property accessors.
> Please add a bug report for this...
> 
> > From  Angelo Luis <angelomysql@gmail.com>:
> 
> > In webwork if the property is null the ww construct the object, and i think
> > that's use OGNL to do this,
> > http://www.opensymphony.com/ognl/html/DeveloperGuide/nullHandler.html ...
> > 
> > 
> > This is the part of WW in Action (Manning) that talk about that... Maybe,
> > Tapestry implement htis some day (as soon as possible, hehe)
> > 
> > As you become more familiar with writing WebWork applications, you'll often
> > find
> > yourself setting the values of properties using complex expressions. For
> > instance,
> > if you need to write a page that asks for Kermit's name, his father's name,
> > and his
> > grandfather's name, you can do one of two things:
> > &#65533; Set the properties name, fatherName, and grandfatherName in your action,
> > and then write code that creates three Muppets, sets their names, and
> > reconnects
> > their relationships.
> > &#65533; Set the properties kermit.name, kermit.father.name, and
> > kermit.father.father.name, and include a single Muppet object, kermit, in
> > your action.
> > Clearly, the second choice is simple: It involves only one property in your
> > action
> > instead of three, and it doesn't require you to reconstruct the objects. But
> > how?
> > Recall that there is no constructor in Muppet that places stubs for the
> > father property,
> > which means that attempting to set kermit.father.name with a value will
> > result in a NullPointerException.
> > This is where OGNL steps in. It provides a way to swap in a null object with
> > a
> > real object whenever access to a property on a null object is detected. With
> > Web-
> > Work's assistance, OGNL essentially constructs the object graph of the
> > son-fathergrandfather relationship automatically, reducing the code you need
> > to write.
> > 
> > On 4/24/06, Geoff Longman <glongman@gmail.com> wrote:
> > > 
> > > The ognl expression translates into java calls.
> > > 
> > > So client.address.street would translate into
> > > 
> > > getClient().getAddress().getStreet()
> > > 
> > > if getClient() or getAddress() return null, boom you get an NPE.
> > > 
> > > I doubt that if webwork is using OGNL that the behaviour there is any
> > > different from what I have described.
> > > 
> > > Geoff
> > > 
> > > On 4/24/06, Angelo Luis <angelomysql@gmail.com> wrote:
> > > > I have a Client that have a Adrress and i want to navigate in the object
> > > > graph in that way : client.address.street, without have a null pointer
> > > > exception... how can i do that...
> > > > 
> > > > I  kwon that i can do that with webwork. is that a way to do in
> > > tapestry???
> > > > Both (tapestry and ww) uses OGNL, so ....
> > > > 
> > > > PS; sorry for my english!
> > > > 
> > > > 
> > > 
> > > 
> > > --
> > > The Spindle guy. http://spindle.sf.net
> > > Blog:                  http://jroller.com/page/glongman
> > > Other interests:  http://www.squidoo.com/spaceelevator/
> > > 
> > > ---------------------------------------------------------------------
> > > 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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic