validation - 服务器端验证有效,但不显示错误消息

标签 validation struts2

我有这个表格:

    <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/

相关文章:

javascript - 如果验证成功则重定向,否则停留在同一页面上

c# - "at least one is required"情况的 MVC3 自定义验证属性

java - 跳过 Struts2 中某些字段的验证

java - Struts 2 execAndWait + Spring 事务管理集成

java - 在 Web 应用程序中显示来自本地计算机的 JFree 图表图像

java - Struts 2 jquery sj :select and json result

java - struts 2 中的数据库访问

mysql - 从jsp页面备份数据库

javascript - JS 电话号码验证-匹配字符串

regex - 工作正则表达式在 Laravel 验证中不起作用