You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Andrew Foltan (afoltan)" <af...@cisco.com> on 2009/04/06 21:27:47 UTC

Unable to get 'ScopedModelDriven' to work for session scope

Hello Struts2 Users,

 

  I am attempting to utilize the ScopedModelDriven interceptor to manage
user input across multiple form submits, in the style of a simple wizard
with sequential pages of input.  I have declared my Action class
('ScopedModelDrivenAction ') to implement 'ScopedModelDriven' and
provided the necessary setter/getters.  My param mapping is functioning
properly to support ModelDriven approach, as evidenced by the previous
step input available through <s:property...> in subsequent step.

 

  My issue seems to be when I apply the "<param
name="scope">session</param>" to the interceptor, it has no effect.  

 

  I have created a simplistic example below and included all relevant
code.  I have the feeling I am close, but the solution is eluding me.  I
have been through all the documentation I can find on
"ScopedModelDriven", including the "Struts 2 in Action" book I
purchased.  Unfortunately I can find no complete working example of this
feature.  

 

Any help is greatly appreciated.

 

Cheers,

                Andy

 

 


Struts.XML:


 

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC

        "-//Apache Software Foundation//DTD Struts Configuration
2.0//EN"

        "http://struts.apache.org/dtds/struts-2.0.dtd">

 

<struts>

 

                <package name="test" namespace="/srsm"
extends="struts-default">

 

                                <interceptors>

                                                <interceptor
name="alias"

 
class="com.opensymphony.xwork2.interceptor.AliasInterceptor" />

                                                <interceptor
name="autowiring"

 
class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterc
eptor" />

                                                <interceptor
name="chain"

 
class="com.opensymphony.xwork2.interceptor.ChainingInterceptor" />

                                                <interceptor
name="conversionError"

 
class="org.apache.struts2.interceptor.StrutsConversionErrorInterceptor"
/>

                                                <interceptor
name="createSession"

 
class="org.apache.struts2.interceptor.CreateSessionInterceptor" />

                                                <interceptor
name="debugging"

 
class="org.apache.struts2.interceptor.debugging.DebuggingInterceptor" />

                                                <interceptor
name="externalRef"

 
class="com.opensymphony.xwork2.interceptor.ExternalReferencesInterceptor
" />

                                                <interceptor
name="execAndWait"

 
class="org.apache.struts2.interceptor.ExecuteAndWaitInterceptor" />

                                                <interceptor
name="exception"

 
class="com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor"
/>

                                                <interceptor
name="fileUpload"

 
class="org.apache.struts2.interceptor.FileUploadInterceptor" />

                                                <interceptor name="i18n"

 
class="com.opensymphony.xwork2.interceptor.I18nInterceptor" />

                                                <interceptor
name="logger"

 
class="com.opensymphony.xwork2.interceptor.LoggingInterceptor" />

                                                <interceptor
name="modelDriven"

 
class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor" />

                                                <interceptor
name="scopedModelDriven"

 
class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"
/>

                                                <interceptor
name="params"

 
class="com.opensymphony.xwork2.interceptor.ParametersInterceptor" />

                                                <interceptor
name="prepare"

 
class="com.opensymphony.xwork2.interceptor.PrepareInterceptor" />

                                                <interceptor
name="staticParams"

 
class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"
/>

                                                <interceptor
name="scope"

 
class="org.apache.struts2.interceptor.ScopeInterceptor" />

                                                <interceptor
name="servletConfig"

 
class="org.apache.struts2.interceptor.ServletConfigInterceptor" />

                                                <interceptor
name="sessionAutowiring"

 
class="org.apache.struts2.spring.interceptor.SessionContextAutowiringInt
erceptor" />

                                                <interceptor
name="timer"

 
class="com.opensymphony.xwork2.interceptor.TimerInterceptor" />

                                                <interceptor
name="token"

 
class="org.apache.struts2.interceptor.TokenInterceptor" />

                                                <interceptor
name="tokenSession"

 
class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor" />

                                                <interceptor
name="validation"

 
class="org.apache.struts2.interceptor.validation.AnnotationValidationInt
erceptor" />

                                                <interceptor
name="workflow"

 
class="com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor"
/>

                                                <interceptor
name="store"

 
class="org.apache.struts2.interceptor.MessageStoreInterceptor" />

                                                <interceptor
name="checkbox"

 
class="org.apache.struts2.interceptor.CheckboxInterceptor" />

                                                <interceptor
name="profiling"

 
class="org.apache.struts2.interceptor.ProfilingActivationInterceptor" />

                                                <interceptor
name="roles"

 
class="org.apache.struts2.interceptor.RolesInterceptor" />

 

                                                <interceptor-stack
name="customStack">

 
<interceptor-ref name="exception" />

 
<interceptor-ref name="alias" />

 
<interceptor-ref name="servletConfig" />

 
<interceptor-ref name="prepare" />

 
<interceptor-ref name="i18n" />

 
<interceptor-ref name="chain" />

 
<interceptor-ref name="debugging" />

 
<interceptor-ref name="profiling" />

 
<interceptor-ref name="scopedModelDriven">

 
<param name="scope">session</param>

 
</interceptor-ref>

 
<interceptor-ref name="modelDriven" />

 
<interceptor-ref name="fileUpload" />

 
<interceptor-ref name="checkbox" />

 
<interceptor-ref name="staticParams" />

 
<interceptor-ref name="params">

 
<param name="excludeParams">dojo\..*</param>

 
</interceptor-ref>

 
<interceptor-ref name="conversionError" />

 
<interceptor-ref name="validation">

 
<param name="excludeMethods">input,back,cancel,browse</param>

 
</interceptor-ref>

 
<interceptor-ref name="workflow">

 
<param name="excludeMethods">input,back,cancel,browse</param>

 
</interceptor-ref>

                                                </interceptor-stack>

                                </interceptors>

 

                                <action name="ScopedModelDrivenSubmit2"
class="test.struts.ScopedModelDrivenAction">

                                                <interceptor-ref
name="customStack" />

 
<result>/srsm/test/ScopedModelDrivenResults.jsp</result>

                                </action>

 

                                <action name="ScopedModelDrivenSubmit1"
class="test.struts.ScopedModelDrivenAction">

                                                <interceptor-ref
name="customStack" />

 
<result>/srsm/test/ScopedModelDrivenForm2.jsp</result>

                                </action>

 

                </package>

 

</struts>

 

 


ScopedModelDrivenAction.java:


 

package test.struts;

 

import com.opensymphony.xwork2.ActionSupport;

import com.opensymphony.xwork2.interceptor.ScopedModelDriven;

 

public class ScopedModelDrivenAction extends ActionSupport implements

        ScopedModelDriven<UserModel> {


 

                private static final long serialVersionUID = 1L;

 

                private UserModel user = new UserModel();

 

                public void setUser(UserModel usr) {

                                user = usr;

                }

 

                public UserModel getUser() {

                                return user;

                }

 

                /**

                 * Implementation for ScopedModelDriven

                 */

                private String scope = "";

 

                @Override

                public String getScopeKey() {

                                return scope;

                }

 

                @Override

                public void setModel(UserModel arg0) {

                                user = arg0;

                }

 

                @Override

                public void setScopeKey(String arg0) {

                                scope = arg0;

                }

 

                @Override

                public UserModel getModel() {

                                return user;

                }

 

}

 

 


UserModel.java:


 

package test.struts;

 

public class UserModel {

 

                private String firstname = "";

                private String lastname = "";

 

                public void setFirstname(String fn) {

                                firstname = fn;

                }

 

                public void setLastname(String ln) {

                                lastname = ln;

                }

 

                public String getFirstname() {

                                return firstname;

                }

 

                public String getLastname() {

                                return lastname;

                }

 

}

 


RE: Unable to get 'ScopedModelDriven' to work for session scope

Posted by Martin Gainty <mg...@hotmail.com>.
pls check to see if ParameterFilter is blocking your params e.g.
 <action ....>
   ...
   <interceptor-ref name="parameterFilter">
     <param name="blocked">blocked_parameter</param>
     <param name="allowed">allowed_parameter</param>
   </interceptor-ref>
   ...
 </action>
http://struts.apache.org/2.0.14/docs/parameter-filter-interceptor.html

?
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung / Note de déni et de confidentialité 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.






> Subject: Unable to get 'ScopedModelDriven' to work for session scope
> Date: Mon, 6 Apr 2009 15:27:47 -0400
> From: afoltan@cisco.com
> To: user@struts.apache.org
> 
> Hello Struts2 Users,
> 
>  
> 
>   I am attempting to utilize the ScopedModelDriven interceptor to manage
> user input across multiple form submits, in the style of a simple wizard
> with sequential pages of input.  I have declared my Action class
> ('ScopedModelDrivenAction ') to implement 'ScopedModelDriven' and
> provided the necessary setter/getters.  My param mapping is functioning
> properly to support ModelDriven approach, as evidenced by the previous
> step input available through <s:property...> in subsequent step.
> 
>  
> 
>   My issue seems to be when I apply the "<param
> name="scope">session</param>" to the interceptor, it has no effect.  
> 
>  
> 
>   I have created a simplistic example below and included all relevant
> code.  I have the feeling I am close, but the solution is eluding me.  I
> have been through all the documentation I can find on
> "ScopedModelDriven", including the "Struts 2 in Action" book I
> purchased.  Unfortunately I can find no complete working example of this
> feature.  
> 
>  
> 
> Any help is greatly appreciated.
> 
>  
> 
> Cheers,
> 
>                 Andy
> 
>  
> 
>  
> 
> 
> Struts.XML:
> 
> 
>  
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> 
> <!DOCTYPE struts PUBLIC
> 
>         "-//Apache Software Foundation//DTD Struts Configuration
> 2.0//EN"
> 
>         "http://struts.apache.org/dtds/struts-2.0.dtd">
> 
>  
> 
> <struts>
> 
>  
> 
>                 <package name="test" namespace="/srsm"
> extends="struts-default">
> 
>  
> 
>                                 <interceptors>
> 
>                                                 <interceptor
> name="alias"
> 
>  
> class="com.opensymphony.xwork2.interceptor.AliasInterceptor" />
> 
>                                                 <interceptor
> name="autowiring"
> 
>  
> class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterc
> eptor" />
> 
>                                                 <interceptor
> name="chain"
> 
>  
> class="com.opensymphony.xwork2.interceptor.ChainingInterceptor" />
> 
>                                                 <interceptor
> name="conversionError"
> 
>  
> class="org.apache.struts2.interceptor.StrutsConversionErrorInterceptor"
> />
> 
>                                                 <interceptor
> name="createSession"
> 
>  
> class="org.apache.struts2.interceptor.CreateSessionInterceptor" />
> 
>                                                 <interceptor
> name="debugging"
> 
>  
> class="org.apache.struts2.interceptor.debugging.DebuggingInterceptor" />
> 
>                                                 <interceptor
> name="externalRef"
> 
>  
> class="com.opensymphony.xwork2.interceptor.ExternalReferencesInterceptor
> " />
> 
>                                                 <interceptor
> name="execAndWait"
> 
>  
> class="org.apache.struts2.interceptor.ExecuteAndWaitInterceptor" />
> 
>                                                 <interceptor
> name="exception"
> 
>  
> class="com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor"
> />
> 
>                                                 <interceptor
> name="fileUpload"
> 
>  
> class="org.apache.struts2.interceptor.FileUploadInterceptor" />
> 
>                                                 <interceptor name="i18n"
> 
>  
> class="com.opensymphony.xwork2.interceptor.I18nInterceptor" />
> 
>                                                 <interceptor
> name="logger"
> 
>  
> class="com.opensymphony.xwork2.interceptor.LoggingInterceptor" />
> 
>                                                 <interceptor
> name="modelDriven"
> 
>  
> class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor" />
> 
>                                                 <interceptor
> name="scopedModelDriven"
> 
>  
> class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"
> />
> 
>                                                 <interceptor
> name="params"
> 
>  
> class="com.opensymphony.xwork2.interceptor.ParametersInterceptor" />
> 
>                                                 <interceptor
> name="prepare"
> 
>  
> class="com.opensymphony.xwork2.interceptor.PrepareInterceptor" />
> 
>                                                 <interceptor
> name="staticParams"
> 
>  
> class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"
> />
> 
>                                                 <interceptor
> name="scope"
> 
>  
> class="org.apache.struts2.interceptor.ScopeInterceptor" />
> 
>                                                 <interceptor
> name="servletConfig"
> 
>  
> class="org.apache.struts2.interceptor.ServletConfigInterceptor" />
> 
>                                                 <interceptor
> name="sessionAutowiring"
> 
>  
> class="org.apache.struts2.spring.interceptor.SessionContextAutowiringInt
> erceptor" />
> 
>                                                 <interceptor
> name="timer"
> 
>  
> class="com.opensymphony.xwork2.interceptor.TimerInterceptor" />
> 
>                                                 <interceptor
> name="token"
> 
>  
> class="org.apache.struts2.interceptor.TokenInterceptor" />
> 
>                                                 <interceptor
> name="tokenSession"
> 
>  
> class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor" />
> 
>                                                 <interceptor
> name="validation"
> 
>  
> class="org.apache.struts2.interceptor.validation.AnnotationValidationInt
> erceptor" />
> 
>                                                 <interceptor
> name="workflow"
> 
>  
> class="com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor"
> />
> 
>                                                 <interceptor
> name="store"
> 
>  
> class="org.apache.struts2.interceptor.MessageStoreInterceptor" />
> 
>                                                 <interceptor
> name="checkbox"
> 
>  
> class="org.apache.struts2.interceptor.CheckboxInterceptor" />
> 
>                                                 <interceptor
> name="profiling"
> 
>  
> class="org.apache.struts2.interceptor.ProfilingActivationInterceptor" />
> 
>                                                 <interceptor
> name="roles"
> 
>  
> class="org.apache.struts2.interceptor.RolesInterceptor" />
> 
>  
> 
>                                                 <interceptor-stack
> name="customStack">
> 
>  
> <interceptor-ref name="exception" />
> 
>  
> <interceptor-ref name="alias" />
> 
>  
> <interceptor-ref name="servletConfig" />
> 
>  
> <interceptor-ref name="prepare" />
> 
>  
> <interceptor-ref name="i18n" />
> 
>  
> <interceptor-ref name="chain" />
> 
>  
> <interceptor-ref name="debugging" />
> 
>  
> <interceptor-ref name="profiling" />
> 
>  
> <interceptor-ref name="scopedModelDriven">
> 
>  
> <param name="scope">session</param>
> 
>  
> </interceptor-ref>
> 
>  
> <interceptor-ref name="modelDriven" />
> 
>  
> <interceptor-ref name="fileUpload" />
> 
>  
> <interceptor-ref name="checkbox" />
> 
>  
> <interceptor-ref name="staticParams" />
> 
>  
> <interceptor-ref name="params">
> 
>  
> <param name="excludeParams">dojo\..*</param>
> 
>  
> </interceptor-ref>
> 
>  
> <interceptor-ref name="conversionError" />
> 
>  
> <interceptor-ref name="validation">
> 
>  
> <param name="excludeMethods">input,back,cancel,browse</param>
> 
>  
> </interceptor-ref>
> 
>  
> <interceptor-ref name="workflow">
> 
>  
> <param name="excludeMethods">input,back,cancel,browse</param>
> 
>  
> </interceptor-ref>
> 
>                                                 </interceptor-stack>
> 
>                                 </interceptors>
> 
>  
> 
>                                 <action name="ScopedModelDrivenSubmit2"
> class="test.struts.ScopedModelDrivenAction">
> 
>                                                 <interceptor-ref
> name="customStack" />
> 
>  
> <result>/srsm/test/ScopedModelDrivenResults.jsp</result>
> 
>                                 </action>
> 
>  
> 
>                                 <action name="ScopedModelDrivenSubmit1"
> class="test.struts.ScopedModelDrivenAction">
> 
>                                                 <interceptor-ref
> name="customStack" />
> 
>  
> <result>/srsm/test/ScopedModelDrivenForm2.jsp</result>
> 
>                                 </action>
> 
>  
> 
>                 </package>
> 
>  
> 
> </struts>
> 
>  
> 
>  
> 
> 
> ScopedModelDrivenAction.java:
> 
> 
>  
> 
> package test.struts;
> 
>  
> 
> import com.opensymphony.xwork2.ActionSupport;
> 
> import com.opensymphony.xwork2.interceptor.ScopedModelDriven;
> 
>  
> 
> public class ScopedModelDrivenAction extends ActionSupport implements
> 
>         ScopedModelDriven<UserModel> {
> 
> 
>  
> 
>                 private static final long serialVersionUID = 1L;
> 
>  
> 
>                 private UserModel user = new UserModel();
> 
>  
> 
>                 public void setUser(UserModel usr) {
> 
>                                 user = usr;
> 
>                 }
> 
>  
> 
>                 public UserModel getUser() {
> 
>                                 return user;
> 
>                 }
> 
>  
> 
>                 /**
> 
>                  * Implementation for ScopedModelDriven
> 
>                  */
> 
>                 private String scope = "";
> 
>  
> 
>                 @Override
> 
>                 public String getScopeKey() {
> 
>                                 return scope;
> 
>                 }
> 
>  
> 
>                 @Override
> 
>                 public void setModel(UserModel arg0) {
> 
>                                 user = arg0;
> 
>                 }
> 
>  
> 
>                 @Override
> 
>                 public void setScopeKey(String arg0) {
> 
>                                 scope = arg0;
> 
>                 }
> 
>  
> 
>                 @Override
> 
>                 public UserModel getModel() {
> 
>                                 return user;
> 
>                 }
> 
>  
> 
> }
> 
>  
> 
>  
> 
> 
> UserModel.java:
> 
> 
>  
> 
> package test.struts;
> 
>  
> 
> public class UserModel {
> 
>  
> 
>                 private String firstname = "";
> 
>                 private String lastname = "";
> 
>  
> 
>                 public void setFirstname(String fn) {
> 
>                                 firstname = fn;
> 
>                 }
> 
>  
> 
>                 public void setLastname(String ln) {
> 
>                                 lastname = ln;
> 
>                 }
> 
>  
> 
>                 public String getFirstname() {
> 
>                                 return firstname;
> 
>                 }
> 
>  
> 
>                 public String getLastname() {
> 
>                                 return lastname;
> 
>                 }
> 
>  
> 
> }
> 
>  
> 

_________________________________________________________________
Rediscover Hotmail®: Now available on your iPhone or BlackBerry
http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Mobile1_042009