jstuardo
jstuardo

Reputation: 4426

Server side validation works, but it does not show error message

I have this form:

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

This validators:

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

And this definition:

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

This works perfectly client side. But when I remove validate="true" from the form in order to test server side, valdation occus and the form loads again, but no error message appears.

Other question regarding the same: I am not using JSON validation, but the normal client side validation. Why it does not work when I remove the definition?

I guess it is because maybe jsonValidationWorkflowStack inherits from other validation interceptor. If it is, perhaps it is convenient to define the other one, instead of jsonValidationWorkflowStack.

Upvotes: 2

Views: 1193

Answers (1)

Lukasz Lenart
Lukasz Lenart

Reputation: 1017

Your input result is a redirect and during redirect all request attributes (also messages) are gone, you must use MessageStoreInterceptor to persist them between requests.

See also Struts 2 Validation using Message Store Interceptor

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

Upvotes: 3

Related Questions