You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Erickson <ha...@ratemod.com> on 2005/09/19 02:08:31 UTC

Validator woes, modifying the input forward on the fly?

Hi I have a situation like this:
User clicks on /viewUser.do?id=4 action, which loads the specific user with
id4 to be viewed.
On that page is a form, the form is submitted, if some part of the xml
validation fails I need to return back to /viewUser.do?id=4.  It would be
ideal if the information from the form could be retained.  I can set my
input forward to be: input="/viewUser.do" but somehow I need to access that
and add the parameter id=4 to it after the xml validation takes place, but
before the new page is requested.  Is there any possible way to do this?

Thanks,
David


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


RE: Validator woes, modifying the input forward on the fly?

Posted by David Erickson <ha...@ratemod.com>.
> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] On Behalf Of Laurie Harper
> Sent: Sunday, September 18, 2005 7:26 PM
> To: user@struts.apache.org
> Subject: Re: Validator woes, modifying the input forward on the fly?
> 
> David Erickson wrote:
> > Hi I have a situation like this:
> > User clicks on /viewUser.do?id=4 action, which loads the specific user
> with
> > id4 to be viewed.
> > On that page is a form, the form is submitted, if some part of the xml
> > validation fails I need to return back to /viewUser.do?id=4.  It would
> be
> > ideal if the information from the form could be retained.  I can set my
> > input forward to be: input="/viewUser.do" but somehow I need to access
> that
> > and add the parameter id=4 to it after the xml validation takes place,
> but
> > before the new page is requested.  Is there any possible way to do this?
> 
> The parameter is stored into the request when it is first submitted, so
> provided you haven't told Struts to redirect to the input page (it'll
> use a forward by default) the parameter -- and any others submitted from
> your form -- should still be in the request. So, you shouldn't need to
> do anything yourself to have the data available when the input page is
> redisplayed.

I guess a better explanation is due.  Ok the user sees /viewUser.do?id=4
which in my action pulls the User object with ID 4 from the db, places it in
to the request, then loads the .viewUser tiles definition and displays the
data. In that page is a form that submits to /addEmailAddress.do.  If the
xml validation fails on submitting it then pulls the input forward from
addEmailAddress.do, which I tried setting to input=".viewUser", the tiles
definition.  After a failure validating, my jsp reports an error finding the
user object, because when you submit you are getting a new request, and the
user object is no longer loaded into the request object.  I also tried
setting the input element to be input="/viewUser.do", which runs the action
again, but doesn't have the id=4 parameter I need to specify which user
object to load out of the database.  Make sense?  So essentially what I am
looking for is a way to modify the input forward that is used when
validation fails.  I tried this in the validate method of my form, however
it says configuration locked if I do a setInput(), and if I do
getInputForward then modify it, it doesn't seem to do anything.. (probably
returning a copy).  So.. if anyone has any ideas.. :)

Thanks,
David 


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


Re: Validator woes, modifying the input forward on the fly?

Posted by Laurie Harper <la...@holoweb.net>.
David Erickson wrote:
> Hi I have a situation like this:
> User clicks on /viewUser.do?id=4 action, which loads the specific user with
> id4 to be viewed.
> On that page is a form, the form is submitted, if some part of the xml
> validation fails I need to return back to /viewUser.do?id=4.  It would be
> ideal if the information from the form could be retained.  I can set my
> input forward to be: input="/viewUser.do" but somehow I need to access that
> and add the parameter id=4 to it after the xml validation takes place, but
> before the new page is requested.  Is there any possible way to do this?

The parameter is stored into the request when it is first submitted, so 
provided you haven't told Struts to redirect to the input page (it'll 
use a forward by default) the parameter -- and any others submitted from 
your form -- should still be in the request. So, you shouldn't need to 
do anything yourself to have the data available when the input page is 
redisplayed.

What is the behaviour you're seeing? Describing in more detail what 
you're seeing and what you were expecting to see, along with posting the 
relevant parts of the config files, should help someone to spot what's 
wrong.

L.


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


RE: Validator woes, modifying the input forward on the fly?

Posted by David Erickson <ha...@ratemod.com>.
> On 9/19/05, David Erickson <ha...@ratemod.com> wrote:
> > > -----Original Message-----
> > > From: Wojciech Ciesielski [mailto:wciesielski@f1.pl]
> > > Use ActionRedirect class in your STRUTS Action's execute:
> > >
> > > ActionRedirect ar = new
> > > ActionRedirect(mapping.findForward("myRedirectForward");
> > > ar.addParameter("id",yourId);
> > > return ar;
> > >
> > > and it should work :]
> >
> > Right, I understand this can work, the problem is WHERE do I return an
> > ActionForward or at least get access to the ActionForward that is going
> to
> > be used when the XML Validation fails.  The validate method on the form
> > returns an ActionErrors object, not an ActionForward...
> 
> Do not use automatic validation, do not use "input" attribute. Call
> validate() manually from your action class.

Perfect, I totally forgot you can trigger the xml validation.  Thanks for
the tip!!

-David


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


Re: Validator woes, modifying the input forward on the fly?

Posted by Michael Jouravlev <jm...@gmail.com>.
On 9/19/05, David Erickson <ha...@ratemod.com> wrote:
> > -----Original Message-----
> > From: Wojciech Ciesielski [mailto:wciesielski@f1.pl]
> > Use ActionRedirect class in your STRUTS Action's execute:
> >
> > ActionRedirect ar = new
> > ActionRedirect(mapping.findForward("myRedirectForward");
> > ar.addParameter("id",yourId);
> > return ar;
> >
> > and it should work :]
> 
> Right, I understand this can work, the problem is WHERE do I return an
> ActionForward or at least get access to the ActionForward that is going to
> be used when the XML Validation fails.  The validate method on the form
> returns an ActionErrors object, not an ActionForward...

Do not use automatic validation, do not use "input" attribute. Call
validate() manually from your action class.

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


RE: Validator woes, modifying the input forward on the fly?

Posted by David Erickson <ha...@ratemod.com>.
> -----Original Message-----
> From: Wojciech Ciesielski [mailto:wciesielski@f1.pl]
> Sent: Monday, September 19, 2005 4:03 AM
> To: 'Struts Users Mailing List'
> Subject: RE: Validator woes, modifying the input forward on the fly?
> 
> > Hi I have a situation like this:
> > User clicks on /viewUser.do?id=4 action, which loads the specific user
> > with
> > id4 to be viewed.
> > On that page is a form, the form is submitted, if some part of the xml
> > validation fails I need to return back to /viewUser.do?id=4.  It would
> be
> > ideal if the information from the form could be retained.  I can set my
> > input forward to be: input="/viewUser.do" but somehow I need to access
> > that
> > and add the parameter id=4 to it after the xml validation takes place,
> but
> > before the new page is requested.  Is there any possible way to do this?
> 
> 
> Use ActionRedirect class in your STRUTS Action's execute:
> 
> ActionRedirect ar = new
> ActionRedirect(mapping.findForward("myRedirectForward");
> ar.addParameter("id",yourId);
> return ar;
> 
> and it should work :]

Right, I understand this can work, the problem is WHERE do I return an
ActionForward or at least get access to the ActionForward that is going to
be used when the XML Validation fails.  The validate method on the form
returns an ActionErrors object, not an ActionForward...

Any other ideas?
Thanks,
David


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


RE: Validator woes, modifying the input forward on the fly?

Posted by Wojciech Ciesielski <wc...@f1.pl>.
> Hi I have a situation like this:
> User clicks on /viewUser.do?id=4 action, which loads the specific user
> with
> id4 to be viewed.
> On that page is a form, the form is submitted, if some part of the xml
> validation fails I need to return back to /viewUser.do?id=4.  It would be
> ideal if the information from the form could be retained.  I can set my
> input forward to be: input="/viewUser.do" but somehow I need to access
> that
> and add the parameter id=4 to it after the xml validation takes place, but
> before the new page is requested.  Is there any possible way to do this?


Use ActionRedirect class in your STRUTS Action's execute:

ActionRedirect ar = new
ActionRedirect(mapping.findForward("myRedirectForward");
ar.addParameter("id",yourId);
return ar;

and it should work :]



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