File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts+Multipage Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts+Multipage Validation" Watch "Struts+Multipage Validation" New topic

Struts+Multipage Validation

Sai P Kumar

Joined: Jan 22, 2004
Posts: 11
I have a single ActionFormbean (in request scope) and now there are multiple pages using the same ActionForm Bean. i need to validate all this pages. and all the feilds on all the pages are a SUB SET of Action Form Bean (IN REQUEST SCOPE).
I need some help regarding the way to proceed.
Thank you.
Regards Sai.
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
With your request, or possibly in your form, include a field that has a value which is unique to each page. Then, when processing a page request, you know from which page the request is originating and can validate only the fields that appear on that page. Given that you know which page the request came from, you can also return the user back to that page if a validation error occurs.
I use the validate method within the form, I'm not sure how using the Validator class would affect this approach.
Srikanth Shenoy
Ranch Hand

Joined: Jan 24, 2004
Posts: 184
If you use ValidatorForm from org.apache.struts.validator package, the page variable is in-built. The validate method is also implemented and it invokes the commons validator by passing the page number.
You have to just populate the right page value during form submission.
Write your validations in the xml as follows by including the page number:
<form name="CustomerForm">
<field property="firstName" page=�2� depends="required">
<arg0 key="customerform.firstname"/>
Author: Struts Survival Guide - Basics to Best Practices

Srikanth Shenoy
Author of Struts Survival Guide : Basics to Best Practices
Andras Kerekes

Joined: Oct 19, 2004
Posts: 1

I tried the suggested solution and I used the page attribute of DynaValidatorForm. But I have a problem. Struts does not recognize that I set the page attribute.

I have a multipage registration form and I build my pages with Tiles.
I get the page's value with jsp:useBean and jsp:getProperty. When I set page with jsp:setProperty I get the proper value, but the Struts works with the initialized value, 0. When I try to set page's value in WizardAction (when next or previous event is happened) I get 0 and Struts works also with 0. The scope is session everywhere. I don't understand it. Could anybody helps me?

Kind regards,
I agree. Here's the link:
subject: Struts+Multipage Validation
It's not a secret anymore!