浏览 2547 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2006-09-04
<ww:form name="helloWorldForm" action="helloMatrixSubmit"> <ww:textfield name="counterBean.userName" label="Enter your name" /> public class CounterBean { private static int count = 0; private String userName; public int getCount(); { return count; } public void increment(); { count++; } public String getUserName(); { return userName; } public void setUserName(String userName); { this.userName = userName; } } HelloMatrixAction public class HelloMatrixAction extends ActionSupport { /** Spring managed bean reference */ private CounterBean counterBean; /** * IoC setter for the spring managed CounterBean. * * @param counterBean */ public void setCounterBean(CounterBean counterBean); { this.counterBean = counterBean; } private String hello; private String message; public String getHello(); { return hello; } public void setHello(String hello); { this.hello = hello; } public String getMessage(); { return message; } public int getCount(); { return counterBean.getCount();; } /** * A default implementation that does nothing an returns "success". * * @return {@link #SUCCESS} */ public String execute(); throws Exception { System.out.println(this.getHello(););; return SUCCESS; } /** * Sample sayHello method. * * @return {@link #SUCCESS} */ public String sayHello(); throws Exception { ActionContext ctx = ActionContext.getContext();; Map map=ctx.getParameters();; String[] strs=(String[]);map.get("hello");; System.out.println(counterBean.getUserName(););; System.out.println(this.getHello(););; message = "users already took the red pill..."; counterBean.increment();; return "he"; } } 在xwork.xml中 <action name="helloMatrix" class="com.foo.example.HelloMatrixAction"> <result name="success">/WEB-INF/pages/hellomatrix.jsp</result> <param name="hello">kkk</param> </action> <action name="helloMatrixSubmit" class="com.foo.example.HelloMatrixAction" method="sayHello"> <!--<interceptor-ref name="validationWorkflowStack"/>--> <param name="hello">eee</param> <interceptor-ref name="params" /> <interceptor-ref name="model-driven" /> <result name="input">/WEB-INF/pages/hellomatrix.jsp</result> <result name="error">/WEB-INF/pages/hellomatrix.jsp</result> <result name="he" type="dispatcher"> <param name="location">/WEB-INF/pages/hellomatrix.jsp</param> </result> <result name="success" type="freemarker">/WEB-INF/pages/hellomatrix-success.ftl</result> </action> helloMatrix和helloMatrixSubmit是同一个类,但在走helloMatrix时hello被赋上初值“kkk”但当提交表单时走的是helloMatrixSubmit这时hello的值为null不知道是为什么。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2006-09-04
getCounterBean
|
|
返回顶楼 | |
发表时间:2006-09-04
我的意思是 我通过<param name="hello">eee</param>
给hello赋初值不好用 |
|
返回顶楼 | |
发表时间:2006-09-04
interceptor 配置问题
第一个使用了默认的拦截器 第二个自己配置的,没有包含设置静态参数的拦截器 |
|
返回顶楼 | |
发表时间:2006-09-04
谢谢,加了个<interceptor-ref name="static-params"/>好用了
|
|
返回顶楼 | |
发表时间:2006-09-04
因为你在<action name="helloMatrixSubmit" class="com.foo.example.HelloMatrixAction" method="sayHello">
<!--<interceptor-ref name="validationWorkflowStack"/>--> <param name="hello">eee</param> <interceptor-ref name="params" /> <interceptor-ref name="model-driven" /> 这里声明了interceptor,这样默认的 interceptor stack的default就失效了。 而default里面包含了static params的interceptor。 也就是说,你的问题其实是interceptor设置引起的。 |
|
返回顶楼 | |