[ 
https://issues.apache.org/jira/browse/WW-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17334898#comment-17334898
 ] 

Patrice DUROUX commented on WW-5126:
------------------------------------

Hi,

First my report was about the documentation. Looking at Model Driven 
documentation, it was not very clear to me about the Struts process:. My 
thinking was that the stack (and so the push to it) was for the context of the 
view (result) and so will be done just before going to it after everything is 
done regarding the action bean. After some failures,  I went to read the Model 
Driven Interceptor documentation then. And here it was more clear to me when 
was done the push looking at the paragraph related to 
{{refreshModelBeforeResult.}} So I tried to use it but without any success.

Finally everything was very clear once looking at the interceptor code and 
noticed that the refresh is based on equals() which will never help in my case 
where the model object pushed on the top of the stack before the call to the 
action execute() is partially feed by the client query (mainly its id property) 
and this object will then not be replaced by the other one given by the merge 
after the action execution. The two objects are equals based on their id (as a 
JPA manner) and the merged object will not refresh the one at the stack top.

So to remove extra <s:push value="model" /> in lot of views, I have implemented 
an interceptor to solve this on my side and simplified these views.

Thanks

> inconsistancy between Model Driven and Model Driven Interceptor documentations
> ------------------------------------------------------------------------------
>
>                 Key: WW-5126
>                 URL: https://issues.apache.org/jira/browse/WW-5126
>             Project: Struts 2
>          Issue Type: Improvement
>            Reporter: Patrice DUROUX
>            Assignee: Yasser Zamani
>            Priority: Minor
>             Fix For: 2.5.27, 2.6
>
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> Hi,
>  
> The Model Driven documentation says:
> If an action class implements the interface 
> {{com.opensymphony.xwork2.ModelDriven}} then it needs to return an object 
> from the {{getModel()}} method. Struts will then populate the fields of this 
> object with the request parameters, and *this object will be placed on top of 
> the stack once the action is executed*. Validation will also be performed on 
> this model object, instead of the action. Please read about 
> [VisitorFieldValidator 
> Annotation|https://github.com/apache/struts-site/blob/master/source/core-developers/visitor-field-validator-annotation.html]
>  which can help you validate model's fields.
> where as the Model Driven Interceptor documentation says:
> h2. Parameters
>  * {{refreshModelBeforeResult}} - *set to true if you want the model to be 
> refreshed on the value stack after action execution and before result 
> execution*. The setting is useful if you want to change the model instance 
> during the action execution phase, like when loading it from the data layer. 
> This will result in {{getModel()}} being called at least twice.
>  
> Looking into the code shows that the default parameter value is false.
> Moreover the interceptor refresh process is based on call to the {{equals}} 
> method and this method may have been redefined, in a JPA context for 
> instance. The replacement is then not systematic and may not be done.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to