wood burning stoves 2.0*
The moose likes Struts and the fly likes problem in using validator framework with multiple screen jsps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problem in using validator framework with multiple screen jsps" Watch "problem in using validator framework with multiple screen jsps" New topic
Author

problem in using validator framework with multiple screen jsps

Senthil Kumar
Ranch Hand

Joined: Mar 13, 2006
Posts: 264
We have jsp files with mutiple screens and each having user inputs. we tried to use the validator framework to do the server side and client side validation.

The problem we are facing is server side validatin is triggered even before we input the data, since request goes to the Action class before jsp.

i want to know,
is there a machanism to specify when the validation should happen.

And i want to validate only the fields in screen1 for the first request.And the fields in 2nd screen when the 2 request is submitted.(note that all the screens are written in single jsp). can this be done in struts.

we are using struts 1.1


when you really want something, all the universe always conspires in your favour.<br /> <br />SCJP1.5-77%<br />SCWCD-89%
Bhaskar Reddy
Ranch Hand

Joined: Dec 17, 2002
Posts: 52
Did you try having a hidden field (say screenName) that says which 'screen' the user is in and based on this value, do your validations...?

If you are using validation.xml, you may try using validwhen check...
Bhaskar Reddy
Ranch Hand

Joined: Dec 17, 2002
Posts: 52
Not too sure if this works with a single jsp page w/ different 'screens'...
[ September 04, 2007: Message edited by: Bhaskar Reddy ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Senthil Kumar SS:
The problem we are facing is server side validatin is triggered even before we input the data, since request goes to the Action class before jsp.

Make sure you have a separate preparatory Action mapping that does this. Then simply sepecify validate="false" for this Action mapping in the struts-config.xml file.
Originally posted by Senthil Kumar SS:
And i want to validate only the fields in screen1 for the first request.And the fields in 2nd screen when the 2 request is submitted.(note that all the screens are written in single jsp). can this be done in struts.

we are using struts 1.1

Try looking in the documentation for the page attribute of the field element in the validation.xml file. You may be able to use this to validate differently for each page. See the heading Multi Page Formsin this link.


Merrill
Consultant, Sima Solutions
Senthil Kumar
Ranch Hand

Joined: Mar 13, 2006
Posts: 264
Here is our validation.xml file

<form name="logonForm" >
<field
property="username"
depends="required" page="1">
<arg key="logonForm.username"/>
</field>
<field
property="password"
depends="required,mask" page="1">
<arg key="logonForm.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
</field>
</form>


And the jsp file

<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>

<h1>welcome page </h1>
<html:form action="/logon" >
<html:submit property="dosubmit" value="Clcik here" />
<html:hidden property="page" value="5"/>
</html:form>
</body>

</html:html>


second jsp


<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>

<h1>JSP Page</h1>
<html:form action="/logon" onsubmit="return validateLogonForm(this);" >
UserName <html:text property="username" size="16" maxlength="16" style="width:138px; height:19" />
Password <html assword property="password" />
<html:submit property="submit" value="Go" />
<html:hidden property="page" value="1"/>
</html:form>
</body>


<html:errors/>
</html:html>

Despite of passing the page value as "5" , validation gets executed for the second jsp(both jsp's are using the same form).And we get the validation messages in the second jsp.

Our doubt is, will the value passed through page hidden element visible in validation.xml.Because the log in my form bean is not getting printed.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
It looks like you have not understood how the page attribute works. Here is a quote from the documentation:
All validation for any field on a page less than or equal to the current page is performed server side

That means that if you define page=1 for a field in your validation.xml, and the current page is five, the field will be validated, since 5 is greater than 1.

The assumption is that the ActionForm is in session scope, and that you're keeping the values entered from previous pages. If you do this, fields defined for page 1 will pass validation, since you still have the value the user entered in page 1.
Senthil Kumar
Ranch Hand

Joined: Mar 13, 2006
Posts: 264

All validation for any field on a page less than or equal to the current page is performed server side.


I have tried the other way as well.

<form name="logonForm" >
<field
property="username"
depends="required" page="10">
<arg key="logonForm.username"/>
</field>
<field
property="password"
depends="required,mask" page="10">
<arg key="logonForm.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
</field>
</form>


And passed page value as 5. But still validations gets executed. please suggest me a solution
[ September 06, 2007: Message edited by: Senthil Kumar SS ]
Senthil Kumar
Ranch Hand

Joined: Mar 13, 2006
Posts: 264
can someone help me on this
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I thought that Merrill has already done a good job of helping you. What are your specific questions? Do you understand that if the page value is 5 then validation will be executed for pages 1, 2, 3, 4 and 5? Are you keeping your form in session scope? If not then the built in "page" support of the validator framework might not work for you.

When I have implemented Validation in wizard pages I implemented it myself in the validate method of the form. If you were using Struts 1.2+ then you could probably do this with the validwhen rule. I have wondered how much work it would be to change the validation so that the page validation was only executed for the current page. I am not sure if there are extension points or if you would have to change Struts code and recompile.

- Brent
 
 
subject: problem in using validator framework with multiple screen jsps
 
Similar Threads
Help regarding struts validator framework (version 1.2.7)
Struts parent & popup window with validator framework
Struts 1.2 - Client and Server-side validations
Bypass client-side struts validation
struts validator. stoping on first validation error.