Question

I have created the index.jsp which send action request

 <meta http-equiv="REFRESH" content="0;url=./radioButton.action">

After completing this the request is forwarded to radio.jsp. In this one i am showing country, state list etc.. (so i am redirecting for this from index.jsp). Now i am imposing validations to this form. i have created the .xml correctly for validation.When the validation fail it will be redirected to ./radioButton.action

  <result name="input" type="redirectAction">radioButton</result>

I have created one interceptor which extends MethodFilterInterceptor, for this to keep the action errors in session scope which having the follow logic in after() method.

if (fieldErrors != null && fieldErrors.size() > 0)
        {
            Iterator it = fieldErrors.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry pairs = (Map.Entry)it.next();
                System.out.println(pairs.getKey() + " = " + pairs.getValue().toString());
            }
            session.put(FIELD_ERRORS_KEY, fieldErrors);
        }

 public static final String FIELD_ERRORS_KEY    = "RedirectMessageInterceptor_FieldErrors";

i have configured the interceptor in my .xml as below

<interceptors>
    <interceptor name="redirectMessage"  class="com.daya.message.RedirectMessageInterceptor" />

       <interceptor-stack name="sessionStack">
        <interceptor-ref name="redirectMessage" />
            <interceptor-ref name="defaultStack" />
       </interceptor-stack>
  </interceptor-stack>
</interceptors>

I am getting the error message on my console befor putting into session scope. The output printed in console is

userName = [User Name is required to login]
password = [Password is required to login]

I am using the below tag to display the field error

<s:fielderror></s:fielderror>

But in the jsp after redirect (when validation failed) messages are not getting display.

Client side validation is working well. I disabled javascript for checking server side validation

Was it helpful?

Solution

As Struts providing a way handle this using MessageStoreInterceptor but i don't know why you are doing it manually.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top