File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Validation Problem in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation Problem in struts2" Watch "Validation Problem in struts2" New topic
Author

Validation Problem in struts2

anand kumarblr
Greenhorn

Joined: Oct 27, 2006
Posts: 27
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 27, 2006
Posts: 27
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

Joined: Oct 27, 2006
Posts: 27
Can anyone please reply to above question?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

input attribute? In Struts 2?

Have you looked at the Prepare interceptor and its cousin Preparable?
anand kumarblr
Greenhorn

Joined: Oct 27, 2006
Posts: 27
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Dec 10, 2010
Posts: 6
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validation Problem in struts2
 
Similar Threads
Automatic validation is not working with dispatch action
Struts2 Validations problem
Struts2 Validation..Need Help
Struts 2 Validation
Struts 2 forms with different actions