File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with validation 'required' attributes

 
Velika Srbija
Ranch Hand
Posts: 172
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doublecheck in validator-rules.xml that email does not depend on required.
You want it to be depends=""
 
Velika Srbija
Ranch Hand
Posts: 172
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 172
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 216
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 172
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic