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

problem reg Validator

Raminder Singh
Ranch Hand

Joined: Mar 01, 2002
Posts: 72
I have 2 radio buttons. R1 and R2.
If R1 is clicked, we have to validate FOUR fields. F1,F2,F3,F4.
But in case of R2, only THREE F1,F2,F3.

We include/invoke javascript with <html:javascript formName="11">.
and this formName is as per refreance in validation.xml
<form name="11">
<field> tag for all 4
what will be approach to validate 3 tags? I have made <form name="22">
and write <field> tag for 3 fields.
but when i place <html:javascript> in jsp....only 2nd <html:javascript> tag is used.
so how to solve this??
Also plz help me in validating Two date fields( d1 and d2) thr validator.
Conditions: d1 & d2 >= current date
d1 & d2 <=100
d2 can't less than d1.

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This may seem like a strange reply to your request, but whenever I find myself working really hard to get around the restrictions of a framework, I have to ask myself "Is it really worth it?". I find that when dealing with complex cases where I have to bend over backwards to get the framework to do something for me, it's sometimes easier just to abandon the framework and write the code myself. Just my 2 cents, but in this situation, I think I'd just write the javaScript to do what was needed and work outside the validation framework. If I were concerned about uniformity of error messages, it wouldn't be hard to make the message look like the other messages the validator generates.

Consultant, Sima Solutions
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
i agree with merrill that there are certainly limitations to the validation framework and from time to time you'll have to ask yourself whether or not it's worth it.

in your case, since you are using javascript for validation, why not just skip the validation framework all together? i never understood why people use the validation framework for javascript validation at all. it's cumbersome and adds lots of redundant js into your codes. this is not to mention the cross-browser compatibility, especially when you start adding your own validation. struts 1.2.x improved this quite a bit (i believe), but i still firmly believe i can write simple (shared) js validation more efficiently.

with that said, the validation framework is an extremely powerful tool and wonderfully designed for expandability for server-side validations. there IS a learning curve, but once you get over the hump, the world is in your hand. i think i've encountered many, many types of strange validations and have been able to tackle them all using the framework declaratively. there are a couple of cases i could think of that i had to pull the validations INSIDE the action classes and use struts message handling instead. still, messaging, if set up correctly, interact well with validation error display to create a seemless 'validation'.

-/a<br />certified slacker...yes, my last name is 'do' - <a href="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: problem reg Validator
jQuery in Action, 3rd edition