Struts2 form validation gets indefinite loops in web browsers

Continue on the last email:

So if user input something wrong, I want to show the original form.jsp
page with all the parameters extracted from the database along with
error messages. So I need to go to the prepareAction first to gets these
parameters, and then display them in form.jsp page. I tried to write
things like:

<result name="input"> prepare.action </result>

However, it doesn't work. So I used the redirectAction type. 

But this caused 2 problems:

1. when validating user input, the logic causes a indefinite loop. The
browser will detect this and stop forwarding after third loop.

2. error message lost during the redirectAction. As the actionError
stored in a map in session, this object gets lost during the forwarding.
I have to write this interceptor to keep actionError message in the
session. 

The root to all these trouble is just because I want to display error
message in the same page - form.jsp. I want user inputs stay in the
input fields, and error messages shows above the fields. If I can
persuade myself to display error messages on another jsp page, there
wouldn't be so much trouble. But just to wonder, is it possible to
achieve what I desired? Or is there any better design than what I did. 

Thank you very much for any help I can get. 

Cheers,
Jipu


-----Original Message-----
From: Jipu Jiang [mailto:j.ji...@nesc.gla.ac.uk] 
Sent: 17 September 2009 11:17
To: Struts Users Mailing List
Subject: RE: form validation gets indefinite loops in web browsers

Hi Dale, 

Thanks for reply. I have a form that needs parameters from an action. So
to see the JSP form, I'll have to go to the action first to prepare
these parameters for the form, and then the JSP form will render these
parameters. I'll show some sample code here.

PrepareAction.java

List<Parameter> parameters = new ArrayList<Parameter>();
Public String execute() throws Exception {
        Parameters = parameterService.getParameters(); // the service
will then gets parameters from database.
        Return SUCCESS;
}


Struts.xml

<action name="prepare" class="XXX">
        <result name="success">form.jsp</result>
        <result name="input" type="redirectAction"> prepare </result>
        <result name="error">error.jsp</result> 
</action>

Form.jsp

<s:iterator value="parameters">
        

</s:iterator>


What I want to achieve is to display the error messages along with the
submission page if user input something wrong. It would be better if
what user input can also stay on the submission page. 

-----Original Message-----
From: Dale Newfield [mailto:d...@newfield.org] 
Sent: 16 September 2009 17:55
To: Struts Users Mailing List
Subject: Re: form validation gets indefinite loops in web browsers

Jipu Jiang wrote:
>       <result name="input" type="redirectAction"> prepare </result>

Why are you redirecting?

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to