wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with validation Watch "Problem with validation New topic
Author

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
Sheriff

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"
classname="org.apache.struts.util.StrutsValidator"
method="validateEmail"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.email">
<javascript><![CDATA[
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 ]
 
wood burning stoves
 
subject: Problem with validation 'required' attributes
 
Similar Threads
Struts e-mail validator doesn't handle null?
Email validation does not work
Question about the required validator
Struts 1.2 retaininf form fields in jsp in validation error
struts validator. stoping on first validation error.