Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts e-mail validator doesn't handle null?

 
Ryan White
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<field property="email" depends="required , email">
<arg0 key="form.email"/>
</field>

use this in your validation.xml file
 
Ryan White
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic