I had a similar question a week or so ago. I think you can use requiredIf, but that
is being deprecated in favor of validWhen. I'm using a hidden input to tell which
submit button was pressed and which field to validate. Once validWhen makes it in to
a non-beta release, I'll probably use validator, but for now, I'm just testing the
trackBy property in my ActionForm and doing my own validation there.
<html:form action="/track" >
<html:hidden property="trackBy"/>
<script>
function set(target) {document.forms[0].trackBy.value=target;}
</script>
<table border="0">
<tr>
<td>
<bean:message key="label.proNumber"/>
</td>
<td colspan="3">
<html:text property="proNumber" />
</td>
<td>
<html:submit onclick="set('trackByPro');">
<bean:message key="button.track"/>
</html:submit>
</td>
</tr>
<tr>
<td>
<bean:message key="label.bolNumber"/>
</td>
<td colspan="3">
<html:text property="bolNumber" />
</td>
<td>
<html:submit onclick="set('trackByBol');">
<bean:message key="button.track"/>
</html:submit>
</td>
</tr>
</table>
</html:form>
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (trackBy.equals("trackByPro")) {
validatePro(errors);
} else if (trackBy.equals("trackByBol")) {
validateBol(errors);
} else {
errors.add("unknown query method", new
ActionError("query_method.unknown"));
}
return errors;
-----Original Message-----
From: Brian McSweeney [mailto:[EMAIL PROTECTED]
Sent: Wednesday, October 01, 2003 05:29
To: 'Struts Users Mailing List'
Subject: Using multiple validators on one jsp
Hi all,
Say I have a jsp that takes two input parameters - one is an email and
the other is a credit card.
However I have two submit buttons, so if you enter the email, it runs
Action 1, and if you enter
The credit card it runs Action 2.
I want to use the validator to validate the parameters as being correct
emails and credit cards.
However I'm not sure if this can be done. For example, if I put at the
top of my page
<html:javascript form="form1"/> which might contain the email parameter,
then only the
email will get validated in either case. Alternatively if I put at the
top of my page:
<html:javascript form="form2"/> which might contain the credit card
parameter, then only the
credit card will get validated.
What I want is - if the user enters an email, then the email gets
validated, and if he enters a
credit card, then that gets validated.
Is this possible?
Thanks,
Brian
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]