You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mark Steyn <Ma...@premiumtv.co.uk> on 2007/11/19 16:41:04 UTC

[s2] Prepare and Parameter Interceptors

I'm trying to use the Prepare interceptor in conjunction with the
Parameters interceptor to create objects from persistent storage before
Struts 2 sets their properties based on values posted from a form, as
suggested in
http://struts.apache.org/2.0.11/docs/prepare-interceptor.html

 

My understanding of the steps involved is as follows:

 

1. The ParametersInterceptor creates objects based on the values posted
to the form.

2. The prepare method called by the PrepareInterceptor replaces those
objects with objects instantiated from a database.

3. The ParametersInterceptor is called again, updating the objects
constructed from the database with the values posted in the form.

 

The first 2 steps work fine, but not the 3rd.

 

The Parameters interceptor is definitely being called before and after
the Prepare interceptor, but the second call doesn't set the properties
of the objects created in step 2.

 

The intercept stack for the my is:

 

            <interceptor-ref name="fileUpload"/>

            <interceptor-ref name="params">

                <param name="ordered">true</param>

            </interceptor-ref>

            <interceptor-ref name="database"/>

            <interceptor-ref name="prepare"/>  

            <interceptor-ref name="params">

                <param name="ordered">true</param>

            </interceptor-ref>

 

Am I overlooking something, or is there something else I need to do?

 

Thanks,

Mark


Re: [s2] Prepare and Parameter Interceptors

Posted by Gary Affonso <gl...@greywether.com>.
You've got the interceptor setup order correct.  You haven't really 
provided enough info to really identify another other problems (we'd 
need to see the form fields, the action, and the object being exposed 
and hydrated in the action.)

But here are some things you can try...

1) turn on debugging for *both* struts and xwork...

<logger name="org.apache.struts2"><level value="DEBUG"/></logger>
<logger name="com.opensymphony.xwork2"><level value="DEBUG"/></logger>

... and then submit your form to your action.  This will give you 
detailed info as s2/xwork attempt to find and set values on your properties.

2) Be sure that your action has provided a setter for the recently 
hydrated object.

3) Be sure your form fields reference the hydrated object and its 
properties with a valid OGNL expression...

<input type="hidden" name="myObject.myProperty" value="foo" />

(note the "myObject." prefix)

4) An alternative to steps #2 and #3 is ModelDriven
A waste of effort, IMO, but that's another way you can expose your 
recently hydrated object to the form.  You would not need the 
"myObject." prefix on your fieldnames or a setter in the Action for that 
object if you use ModelDriven.

---

If none of that does the trick, you'll need to provide more detail, I'm 
out of guesses. :-)

- Gary

Mark Steyn wrote:
> I'm trying to use the Prepare interceptor in conjunction with the
> Parameters interceptor to create objects from persistent storage before
> Struts 2 sets their properties based on values posted from a form, as
> suggested in
> http://struts.apache.org/2.0.11/docs/prepare-interceptor.html
> 
>  
> 
> My understanding of the steps involved is as follows:
> 
>  
> 
> 1. The ParametersInterceptor creates objects based on the values posted
> to the form.
> 
> 2. The prepare method called by the PrepareInterceptor replaces those
> objects with objects instantiated from a database.
> 
> 3. The ParametersInterceptor is called again, updating the objects
> constructed from the database with the values posted in the form.
> 
>  
> 
> The first 2 steps work fine, but not the 3rd.
> 
>  
> 
> The Parameters interceptor is definitely being called before and after
> the Prepare interceptor, but the second call doesn't set the properties
> of the objects created in step 2.
> 
>  
> 
> The intercept stack for the my is:
> 
>  
> 
>             <interceptor-ref name="fileUpload"/>
> 
>             <interceptor-ref name="params">
> 
>                 <param name="ordered">true</param>
> 
>             </interceptor-ref>
> 
>             <interceptor-ref name="database"/>
> 
>             <interceptor-ref name="prepare"/>  
> 
>             <interceptor-ref name="params">
> 
>                 <param name="ordered">true</param>
> 
>             </interceptor-ref>
> 
>  
> 
> Am I overlooking something, or is there something else I need to do?
> 
>  
> 
> Thanks,
> 
> Mark
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org