Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validation Problem in struts2

 
anand kumarblr
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I googled net for 2 days without proper solution. so i am posting my problem here.

I have 2 methods in single action class named "CustomerSignupAction".

First method name: CreateCustomerFirst
Second method name: CreateCustomerSecond

i created 2 validation.xml
CustomerSignupAction-CreateCustomerFirst-validation.xml
CustomerSignupAction-CreateCustomerSecond-validation.xml

Also i have 2 entry for 2 methods of my action class

<action name="CreateCustomerFirst" method="CreateCustomerFirst" class="CustomerSignupAction">

<result>first.jsp</result>
</action>

<action name="CreateCustomerSecond" method="CreateCustomerSecond" class="CreateCustomerSecond">
<result name="input">first.jsp</result>
<result>second.jsp</result>
</action>

Now First i go to first.jsp through CreateCustomerFirst method and display first.jsp with some prepopulated data(Example: list of home type).

When the user does not enter any data and press submit it has to show validation message.
If i specify first.jsp in my input attribute it shows the validation message.
But the prepopulated data is vanished.
If i specify CreateCustomerFirst.action in input attribute it shows the prepopulated data.
but the validation message vanishes.
Please guide me what is the solution for this.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actions are instantiated per-request, and error messages are stored in the action. Without knowing anything more about your application flow it'll be hard to help more. Please UseCodeTags.
 
anand kumarblr
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the long question. In simple what i wanted is in Struts 2 ...

How to pre-populate the contents of jsp (select box) when we display validation message.
Since iam directly forwarding to jsp in input attribute there is no way i can prepopulate the select box
since the logic for bringing pre-populate data is in action.

I dont want to use Sessions.
 
anand kumarblr
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please reply to above question?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
input attribute? In Struts 2?

Have you looked at the Prepare interceptor and its cousin Preparable?
 
anand kumarblr
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also tried with preapre and preparable..
Prepare method gets called when input get called.. and it populates my select box... and also displays validation messages.
But the problem is same prepare method gets called When i successfully entered all the fields also which i dont want to do.

Iam really stuck up with this validation From 2 weeks

So now iam trying with MessageStoreInterceptor....
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
prepareXxx, where xxx is a method name is also called--you *could* do that if it meets other requirements... although the additional performance hit caused by a single unnecessary prepare call may not be worth the bother.

Setting the message store interceptor's mode to automatic will handle most use-cases for preserving messages across redirects.

All that said I've never had that many problems with messages etc., but I try to work within the framework's limitations.
 
Srinivasa Kumar Meda
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anand,

Did you get any solution for this?? I am also facing the similar problem.

Mine is In the index.jsp , I need to populate a select box and then fill the data in the form and submit. On submit of it, it will invoke another action at this time if validation defined fails, it cant populate the data for select box along with the error messages.

Could anyone who already got the solution for this, can you please help us???

Thanks,
Srinivas
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic