struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bob fuller <bobfuller30...@hotmail.com>
Subject Struts 2 - Repopulate controls when validation fails
Date Thu, 26 Jun 2008 02:14:28 GMT

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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message