The approach I am taking is from the Struts 2 FAQ...

http://struts.apache.org/2.x/docs/how-do-we-repopulate-controls-when-validation-fails.html

Why should it be avoided?


> Date: Thu, 26 Jun 2008 08:32:37 +0200
> From: [EMAIL PROTECTED]
> To: user@struts.apache.org
> Subject: Re: Struts 2 - Repopulate controls when validation fails
> 
> Hi,
> 
> As I know, use of s:action tag should be avoided, the better option is
> to use Preparable interface, you can use prepare<MethodName>() method
> also.
> http://struts.apache.org/2.x/docs/prepare-interceptor.html
> 
> 
> Regards
> -- 
> Lukasz
> http://www.lenart.org.pl/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> From: [EMAIL PROTECTED]
> To: user@struts.apache.org
> Subject: RE: Struts 2 - Repopulate controls when validation fails
> Date: Thu, 26 Jun 2008 02:17:36 +0000
> 
> 
> Trying again to give out my pseudo JSP...
> 
> s:form name="myAction"
> s:textfield name="foo0"/
> s:action name="languages" executeResult="true"/
> s:textfield name="foo1"/
> s:submit/
> /s:form
> 
> > From: [EMAIL PROTECTED]
> > To: user@struts.apache.org
> > Subject: Struts 2 - Repopulate controls when validation fails
> > Date: Thu, 26 Jun 2008 02:14:28 +0000
> > 
> > 
> > I'm following the "How do we repopulate controls when validation fails" FAQ 
> > located at...
> > 
> > http://struts.apache.org/2.x/docs/how-do-we-repopulate-controls-when-validation-fails.html
> > 
> > Of the two methods it suggests I am trying to use the 'action tag' method. 
> > Using the simple example from the FAQ works fine, but once I move beyond 
> > the simple and try to drop my "Languages" control inside the  tag of 
> > another action I have problems.
> > 
> > Here's my pseudo JSP (note MyAction)...
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > MyAction implements validateable and I am validating foo0 and foo1 inside 
> > the validate() method. Here's my validate() code...
> > 
> > public void validate() {
> > if (foo0 == null || foo0.length() == 0)
> >   addFieldError("foo0", "Foo0 is required");
> > else
> >   foo0 = foo0 + " VALIDATED";
> > 
> > if (foo1 == null || foo1.length() == 0)
> >   addFieldError("foo1", "Foo1 is required");
> > else
> >   foo1 = foo1 + " VALIDATED";               
> > }
> > 
> > The important thing to note about my validation code is that when the 
> > validation succeeds the data entered by the user is updated with the word 
> > "VALIDATED". This may seem like an odd thing to do, but it's part of the 
> > requirements of the project I'm working on.
> > 
> > Visiting http://localhost/MyAction/myAction_input.action works great. The 
> > page draws, foo0 is empty, the languages control has languages to choose 
> > from, foo1 is empty, the submit button appears. Submitting the form is when 
> > I get into problems. Here are three submit paths and their results...
> > 
> > 1. foo0 is empty, foo1 is empty. click submit. RESULT - foo0 is empty. foo1 
> > is empty. SUCCESS!
> > 2. foo0 = 'A', foo1 is empty. click submit. RESULT - page redraws. foo0 = 
> > 'A VALIDATED'. foo1 is empty. SUCCESS!
> > 3. foo0 is empty, foo1 = 'A'. click submit. RESULT - page redraws. foo0 is 
> > empty. foo1 = 'A'. FAIL! - foo1 should say 'A VALIDATED'
> > 
> > For some reason MyAction.setFoo1() is being invoked *again* after I set 
> > foo1 to 'A VALIDATED' in my validate() code. Why is that happening? I know 
> > it has something to do with the Languages control that appears before the 
> > foo1 text field, because when I remove the Languages control everything 
> > works as expected.
> > 
> > Anyone have any ideas about what the Languages control is doing that is 
> > causing my foo1 field to get reset to the original submit value? I'd really 
> > like to be able to use the 'action tags' approach for repopulating 
> > controls, but 'dropping wherever', as suggested in the FAQ (see link 
> > above), does not seem to be as easy as it sounds.
> > 
> > Thanks.
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> >  
> > 
> > _________________________________________________________________
> > The other season of giving begins 6/24/08. Check out the i’m Talkathon.
> > http://www.imtalkathon.com?source=TXT_EML_WLH_SeasonOfGiving
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> 
> _________________________________________________________________
> The i’m Talkathon starts 6/24/08.  For now, give amongst yourselves.
> http://www.imtalkathon.com?source=TXT_EML_WLH_LearnMore_GiveAmongst

_________________________________________________________________
Earn cashback on your purchases with Live Search - the search that pays you 
back!
http://search.live.com/cashback/?&pkw=form=MIJAAF/publ=HMTGL/crea=earncashback

Reply via email to