wood burning stoves
The moose likes Struts and the fly likes Problem with validation 'required' attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with validation Watch "Problem with validation New topic

Problem with validation 'required' attributes

Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
Suppose this case. I'm using Validator framework. So, I have a form with two e-mail fields and javascript validation on.

In validation.xml file I defined for the first e-mail field depends="required,email", and for the second e-mail field depends="email".
But, the result is the same. Both fields are "required".

What I want in my JSP is validation against second e-mail field only if it was not empty. I don't want javascript message "Invalid e-mail format" on an empty e-mail field.

Is there any way to overcome this problem?
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

Doublecheck in validator-rules.xml that email does not depend on required.
You want it to be depends=""

A good workman is known by his tools.
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
Thanks. I've already figured out that.
I will make a new entry for email validation (e.g. email2, with depends set to "").
Thanks for the answer again!
[ August 20, 2004: Message edited by: Velika Srbija ]
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
Another chained problem.

After entering new validation-rule named 'email2' with 'depends' parameter set to "":

<validator name="email2"
function validateEmail(form) {
... ...
(here is the same code as in the 'email' validation-rule; no changes)
... ...

almost everythhing works OK. Validation works as expected, but there is no JavaScript ALERT message for incorrect input.
I have tried to modify JavaScript code in order to fix this problem, but failed every time.

What is the problem?
Vladan Radovanovic
Ranch Hand

Joined: Mar 20, 2000
Posts: 216
Pomoz Bog brate Srbine. Let's see if I can help here.
Well now that struts part is working, javascript is the only thing that's left to troubleshoot now, right? That should be an easy part. Why don't you look at the resulting page and it's source. Treat it as pure html and just troubleshoot javascript part.
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
Bog ti pomogo sokole. Da mi ti ne rece sta da radim, ja se nikad sam ne bi' setio.

I've already done what you said. No result.
Why don't you try yourself. Only small modifications in any code that uses Validator plug-in are needed in order to test this.
[ August 22, 2004: Message edited by: Velika Srbija ]
I agree. Here's the link: http://aspose.com/file-tools
subject: Problem with validation 'required' attributes
It's not a secret anymore!