我有这个表格:
<s:form
action="conexion" validate="true" theme="css_xhtml">
<s:textfield name="username" key="profile.rut" labelposition="left" />
<s:password name="password" key="profile.password" labelposition="left" />
<s:submit id="boton_ingreso" align="left" cssClass="send" value="Entrar" />
</s:form>
此验证器:
<validators>
<field name="username">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>*</message>
</field-validator>
<field-validator type="rutValidator">
<param name="trim">true</param>
<message>*</message>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>*</message>
</field-validator>
</field>
</validators>
这个定义:
<action name="conexion" class="agenda.SecurityAction">
<interceptor-ref name="profiling">
<param name="profilingKey">profilingKey</param>
</interceptor-ref>
<interceptor-ref name="jsonValidationWorkflowStack"/>
<result name="success" type="tiles">/profile.tiles</result>
<result name="error" type="redirectAction">
<param name="actionName">cliente</param>
</result>
<result name="input" type="redirectAction">
<param name="actionName">cliente</param>
</result>
</action>
这在客户端完美运行。但是,当我从表单中删除 validate="true"以测试服务器端时,会发生验证并再次加载表单,但不会出现错误消息。
与此相关的其他问题:我没有使用 JSON 验证,而是使用正常的客户端验证。为什么删除定义后不起作用?
我猜这是因为 jsonValidationWorkflowStack 继承自其他验证拦截器。如果是,也许定义另一个更方便,而不是 jsonValidationWorkflowStack。
最佳答案
您的输入
结果是重定向,并且在重定向期间所有请求属性(还有消息)都消失了,您必须使用 MessageStoreInterceptor 在请求之间保留它们。
另请参阅Struts 2 Validation using Message Store Interceptor
http://struts.apache.org/development/2.x/docs/message-store-interceptor.html
关于validation - 服务器端验证有效,但不显示错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15939346/