2

我有这个表格:

    <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" 以测试服务器端时,valdation occus 并且表单再次加载,但没有出现错误消息。

关于相同的其他问题:我没有使用 JSON 验证,而是使用普通的客户端验证。为什么当我删除定义时它不起作用?

我猜这是因为 jsonValidationWorkflowStack 可能继承自其他验证拦截器。如果是的话,也许定义另一个比较方便,而不是jsonValidationWorkflowStack。

4

1 回答 1

3

您的input结果是重定向,并且在重定向期间所有请求属性(也包括消息)都消失了,您必须使用 MessageStoreInterceptor 在请求之间保留它们。

参见Struts 2 Validation using Message Store Interceptor

http://struts.apache.org/development/2.x/docs/message-store-interceptor.html

于 2013-04-11T06:03:31.310 回答