|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
时间:2006-03-31
我依照文档给表单做了验证,它似乎可以验证了,可是验证一旦通不过,之后的输入就再不能正确运行了。
我写的是一个简单的例子:只有一个输入框,判断输入值跳转。 如果我刚刚启动服务器,而输入不为空的话都能按照配置跳转,一旦输入为空,就不行了 start.jsp [code:1] <%@ taglib prefix="ww" uri="webwork"%> <html> <head> <title>Start Hello Page</title> </head> <body> <ww:form action="helloAction" method="post" label="Hello Action" validate="true"> <ww:fielderror> <ww:label> Input: <ww:textfield name="textfield"></ww:textfield> </ww:label> </ww:fielderror> <ww:submit></ww:submit> </ww:form> </body> </html> [/code:1] 请先看 Action action 的实例从 spring 得来 [code:1]public class HelloAction extends ActionSupport implements Action, ModelDriven { private HelloModel model = new HelloModel(); private HelloModel springBean; @Override public String execute() throws Exception { if (springBean!=null) { System.out.println(springBean.getTextfield()); } else { System.out.println("Get Null Bean From Spring"); } System.out.println(model.getTextfield()); if (model.getTextfield().equalsIgnoreCase("dispatcher")) { return "dispatcher"; } else if (model.getTextfield().equalsIgnoreCase("redirect")) { return "redirect"; } else if (model.getTextfield().equalsIgnoreCase("chain")) { return "chain"; } else { return "redirect"; } } public Object getModel() { return model; } public HelloModel getSpringBean() { return springBean; } public void setSpringBean(HelloModel springBean) { this.springBean = springBean; } }[/code:1] xwork.xml [code:1] <!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.1.dtd"> <xwork> <include file="webwork-default.xml" /> <!-- <include file="config-browser.xml" /> <include file="xwork-continuations.xml" /> <include file="xwork-tags.xml" /> <include file="xwork-validation.xml" /> <include file="xwork-actionchaining.xml" /> <include file="xwork-ajax.xml" /> <include file="xwork-fileupload.xml" /> <include file="xwork-person.xml" /> <include file="xwork-wait.xml" /> <include file="xwork-token.xml" /> <include file="xwork-model-driven.xml" /> <include file="xwork-filedownload.xml" /> --> <package name="default" namespace="/" extends="webwork-default"> <default-interceptor-ref name="completeStack" /> </package> <package name="simple" namespace="/webwork" extends="webwork-default"> <action name="helloAction" class="helloWebWork"> <!-- <interceptor-ref name="completeStack" /> --> <result name="dispatcher" type="dispatcher"> <!-- <param name="location">/return.ftl?message=${currentSimple.message}</param> --> <param name="location">dispatcher.jsp</param> <!-- <param name="charSet">UTF-8</param> <param name="namespace">/webwork</param> --> </result> <result name="redirect" type="redirect"> <param name="location">redirect.jsp?textfield=${model.textfield}</param> </result> <result name="chain" type="chain"> <param name="actionName">chainAction</param> <param name="namespace">/webwork</param> </result> <result name="input">input.jsp</result> </action> <action name="chainAction" class="chainWebWork"> <result name="success"> <param name="location">chain.jsp</param> </result> </action> </package> </xwork>[/code:1] spring 配置 [code:1] <bean name="helloBean" class="creatxr.simple.webwork.model.HelloModel"> <property name="textfield"> <value>Spring Bean Message</value> </property> </bean> <bean name="helloWebWork" class="creatxr.simple.webwork.HelloAction" singleton="true"> <property name="springBean"> <ref bean="helloBean" /> </property> </bean> <bean name="chainWebWork" class="creatxr.simple.webwork.ChainAction" singleton="true" />[/code:1] HelloAction-validation.xml [code:1] <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> <validators> <field name="textfield"> <field-validator type="requiredstring"> <param name="trim">true</param> <message>You must enter a value for textfield.</message> </field-validator> </field> </validators> [/code:1] 声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
时间:2006-03-31
引用 <result name="input">input.jsp</result>
少了type="dispatcher" ?? |
|
| 返回顶楼 | |
|
时间:2006-03-31
nihongye 写道 引用 <result name="input">input.jsp</result>
少了type="dispatcher" ?? 而且,就算象你这么写也是一样的。 还有一点奇怪,访问一次校验没通过后,以后不管怎样,每点一次就多一行的校验没通过的提示语句 |
|
| 返回顶楼 | |
|
时间:2006-04-02
造化天尊 写道 spring 配置 [code:1] <bean name="helloBean" class="creatxr.simple.webwork.model.HelloModel"> <property name="textfield"> <value>Spring Bean Message</value> </property> </bean> <bean name="helloWebWork" class="creatxr.simple.webwork.HelloAction" singleton="true"> <property name="springBean"> <ref bean="helloBean" /> </property> </bean> <bean name="chainWebWork" class="creatxr.simple.webwork.ChainAction" singleton="true" />[/code:1] [/code] Spring要singleton="false"。 WebWork的Action是per-request的,所以必须用prototype方式构造。否则状态信息会保持,hasActionErrors()就会总是true。 |
|
| 返回顶楼 | |
|
时间:2006-04-03
Tin 写道 造化天尊 写道 spring 配置 [code:1] <bean name="helloBean" class="creatxr.simple.webwork.model.HelloModel"> <property name="textfield"> <value>Spring Bean Message</value> </property> </bean> <bean name="helloWebWork" class="creatxr.simple.webwork.HelloAction" singleton="true"> <property name="springBean"> <ref bean="helloBean" /> </property> </bean> <bean name="chainWebWork" class="creatxr.simple.webwork.ChainAction" singleton="true" />[/code:1] [/code] Spring要singleton="false"。 WebWork的Action是per-request的,所以必须用prototype方式构造。否则状态信息会保持,hasActionErrors()就会总是true。 我是这样设置的 singleton="false" 但是我那里还是和楼主一样的错误就是每提交一遍,错误提示信息就增加一行,不知道何原因! |
|
| 返回顶楼 | |
|
时间:2007-09-05
我也遇到了这个问题,没提交一次空的表单就多一行验证错误信息。。。
不知道楼主最后怎么解决的? |
|
| 返回顶楼 | |
|
时间:2007-09-06
楼主的action写的很不好,应该覆盖validate()方法,出错addActionerrors(),这样有错才会返回input
按习惯的做法,我发帖一般都是回复新手帖... |
|
| 返回顶楼 | |
|
时间:2007-09-06
nihongye 写道 引用 <result name="input">input.jsp</result>
少了type="dispatcher" ?? 借楼主的帖子请教个问题 我的验证中有这么一句 <result name="input" type="dispatcher">xxx.action</result> 出现404错误 而直接敲url就没有问题 不知道是什么原因 我用的是webwork2.2.5 |
|
| 返回顶楼 | |
|
时间:2007-09-06
type="dispatcher"改成type="chain"
|
|
| 返回顶楼 | |
|
时间:2007-09-06
tonyyl 写道 type="dispatcher"改成type="chain"
对于webwork中dispatcher 我的理解是这样的:RequestDispatcher只能够对jsp servlet等进行分发 如果我们按照type="dispatcher"的方式分发xxx.action,容器会把他作为一个servlet去处理,而:RequestDispatcher方式并不经过filter所以会出现404错误。而采用chain方式是webwork内部实现了转发的功能 |
|
| 返回顶楼 | |










