Here it is. "getSession()" is returning a thread local session object. The
Manager class is a class encapsulating data access.

from member declarations:
// MODEL OBJECT 
        private Requirement model = new Requirement();
        public Object getCurrentObject(){return this.model;} 

load action method:
        /**
         * Loads a Requirement.
         */
        public String doLoad() throws Exception
        {
                try
                {
                        IUserInfo userInfo = getUserInfo();
                        Session session = getSession();
                        RequirementManager mgr = new
RequirementManager(session);
                        if (currentId != null)
                                model = mgr.load(currentId, userInfo);
                        updateModelInStack();
                }
                catch (LogicException e)
                {
                        if (e.getErrorMessages() != null)
                                this.setActionErrors(e.getErrorMessages());
                        else
                                addActionError(e.getMessage());
                        return ERROR;
                }
                catch(Exception e)
                {
                        log.error(e);
                        this.addActionError(e.getMessage());
                        return ERROR;
                }
                log.debug("did load");
                return SUCCESS;
        }

The LogicException is a specialized exception from the manager class that
queues up its own error messages, and passes them into the action if
necessary. Note that the current code includes a call to
"updateModelInStack", which manually pushes the model object back to the top
of the stack. Without that call, the updated model isn't on the stack.


Let me know if this clarifies things.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jason
Carreira
Sent: Wednesday, November 12, 2003 12:40 PM
To: [EMAIL PROTECTED]
Subject: RE: [OS-webwork] Further weirdness with the valuestack and
modeldriven

Please post your Action code... I'm suspecting it's 4)

> -----Original Message-----
> From: Drew McAuliffe [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, November 12, 2003 3:36 PM
> To: [EMAIL PROTECTED]
> Subject: [OS-webwork] Further weirdness with the valuestack and 
> modeldriven
> 
> 
> In a recent message, I described a problem I had with the model object 
> of a ModelDriven action. The model object is pushed onto the top of 
> the stack by the ModelDrivenInterceptor but after updates to the model 
> in the action, the value at the top of the stack isn't the same as the 
> updated model.
> 
> I've tried to push the updated value back onto the stack, with the 
> push() method in two different ways:
> 1) By updating the modeldriveninterceptor to push on both "before" and 
> (new) "after". This is done as follows:
>     protected void after(ActionInvocation dispatcher, String
> result) throws Exception {
>       pushModel(dispatcher);
>     }
> 
>     protected void before(ActionInvocation invocation) throws 
> Exception {
>       pushModel(invocation);
>     }
>     
>     private void pushModel(ActionInvocation invocation)
>     {
>               Action action = invocation.getProxy().getAction();
> 
>               if (action instanceof ModelDriven) {
>                       ModelDriven modelDriven = (ModelDriven) action;
>                       OgnlValueStack stack = invocation.getStack();
>                       stack.push(modelDriven.getModel());
>               }
>       
>     }
> 2) Call "push(model)" directly in the action after a load.
> 
> The first approach doesn't seem to work, probably because I'm dealing 
> with the input params on "after" incorrectly. The second approach does 
> work. So, some questions:
> 
> 1) Is there something wrong with how I've rigged the 
> modeldriveninterceptor to work that would prevent it from pushing 
> properly?
> 2) Does it make sense to try to push in both "before" and "after" in 
> the modeldriveninterceptor anyway, or is this violating some part of 
> the design of the interceptor?
> 3) If I go the second route, with a "push" call in the action, do I 
> need to call "pop" first to get the old model object off of the stack?
> 4) Or, all of this aside, is there something I'm missing about why the 
> top of the stack isn't staying in synch with the model object? It 
> looks like "pop" is just adding an element to an array at element 0, 
> so I would think that it would be putting it there by reference. But 
> the "add" method of ArrayList (which CompoundRoot extends) does call 
> "arraycopy", which might be what's causing things (perhaps) to be 
> copied by value instead of reference. Not sure, though, if that's 
> what's causing the overall problem.
> 
> Thanks,
> 
> Drew
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email sponsored by: ApacheCon 2003,
> 16-19 November in Las Vegas. Learn firsthand the latest developments 
> in Apache, PHP, Perl, XML, Java, MySQL, WebDAV, and more! 
> http://www.apachecon.com/ 
> _______________________________________________
> Opensymphony-webwork mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork
> 




-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork

Reply via email to