Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validator, same field, same formbean, diff JSP,diff validations

 
Arthur Ford
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a form bean


I use this ActionForm bean in 2 jsps.

JSP1,JSP2

In JSP1, I need to validate the empNo field to be 'required'.
In JSP2, I need to validate the empNo field to be 'required' and 'integer'.

Ofcourse, all the other 20 properties have their own validations..

Right now, what I am doing is I have given a different name to the actionform bean in struts-config and have repeated the validations in validation.xml.

But what is ugly that just for one field, 20 of them are getting repeated..

Is there any way out??

and then
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what you could do is:
- write one declarative validation which checks required
- write your own 2 lines of business-logic in the appropriate action which valides for integer if necessary

this would allow you to live with just one configuration...

would that help?

jan
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do both the JSP points to the same action? I believe you can get around without coping the whole form twice. In validation.xml file the field element has an attribute "page".

Steps to try:
- Add an int field called page in the form.
- When JSP1 is being rendered render this field as hidden with value 0
- When JSP2 is being rendered render this field as hidden type with value 1
- In the validation.xml file create two field elements for form member that requires different validation on JSP1 and JSP2 with page value as 0 and 1
- For the rest of form members set the page value to 0

Validator doc says

All validation for any field on a page less than or equal to the current page is performed server side. All validation for any field on a page equal to the current page is generated for the client side Javascript. A mutli-part form expects the page attribute to be set.


- Only question I have is will Validator framework evaluate all the dependency if the dependencies are defined in more than one field element for the same element. I guess it's worth trying.

- As long as you don't enable client side validation this should be fine.

I couldn't try myself right now. Let us know if it works.
[ September 26, 2006: Message edited by: Purushothaman Thambu ]
 
Arthur Ford
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnks guys for the reply. I tried the page method. It didnt work. So, I just changed my JSP page, and wrote Javascript for the page. Didnt use the validation framework for this page.

I had a deadline, so coudlnt experiment a lot. Maybe will try later.
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

In a similar example, I am getting

13:01:07,625 ERROR [[action]] Servlet.service() for servlet action threw exception
java.lang.NullPointerException
at strutstutorial.UserRegistrationForm.validate(Unknown Source)

Any clues on where I am going wrong?

Rgds,

Seetesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic