• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem in using validator framework with multiple screen jsps

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not too sure if this works with a single jsp page w/ different 'screens'...
[ September 04, 2007: Message edited by: Bhaskar Reddy ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Senthil Kumar
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can someone help me on this
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic