wood burning stoves*
The moose likes Struts and the fly likes Struts e-mail validator doesn't handle null? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts e-mail validator doesn Watch "Struts e-mail validator doesn New topic
Author

Struts e-mail validator doesn't handle null?

Ryan White
Greenhorn

Joined: Feb 20, 2008
Posts: 7
I have a form that has 2 e-mail fields. One is the entry field with an "add-email" button next to it that, when clicked, adds the e-mail to a CSV list in the other (locked) e-mail field. this is part of an overall form. Apparently, the built in Struts e-mail validator doesn't handle a null condition because it is allowing me to submit a null with the add-email button. I can't set it as required or the main form won't let me submit without an e-mail in that field which should be empty upon final form submission. The user should have clicked add-email to populate whats in the e-mail field to the CSV list of e-mails.

What can I do here? the Struts e-mail validator works in ensuring the correct format (xxx@xxx.xxx) but somehow it interprets nothing as being a correct e-mail too...

Thanks
~Ryan
shahidrasul shahid
Ranch Hand

Joined: Jan 28, 2008
Posts: 62
<field property="email" depends="required , email">
<arg0 key="form.email"/>
</field>

use this in your validation.xml file
Ryan White
Greenhorn

Joined: Feb 20, 2008
Posts: 7
I can't do that because then it is required for the main form on the page. This is another form within the main form. The e-mail field has an add-email button that adds whatever is in that field to a text box with a list of multiple e-mail addresses. So when the user goes to submit the main form, they should have added the email in the email field to the multi e-mail text box therefore making the email field blank upon final submission.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
What version of Struts are you using? Maybe you could use the validwhen rule? Or when the user pressed the Add button, you could populate a hidden field and perform validation against that field.

- Brent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts e-mail validator doesn't handle null?