You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by bj...@accenture.com on 2007/01/31 14:09:04 UTC

Validate multiple fields and show multiple messages

Rather annoying problem, but I really don't know how to fix it.

I have a form, with 3 fields on it.  A field for UserName, one for E-mailaddress and a checkbox.  The username can't be equal to a given value (let's say "testing") and if you check the checkbox, the e-mailaddress is required.  

If both checks fail, I want to display 2 error messages, one for the username and one for the e-mailaddress. 

When the username is equal to the given value, I add this: actionMessages.add(field.getKey(), Resources.getActionMessage(req, validatorAction, field));

When the checkbox is checked, and the e-mailaddress is empty: 
actionMessages.add(field.getKey(), Resources.getActionMessage(req, validatorAction, field));
actionMessages.add(EMAIL, Resources.getActionMessage(req, validatorAction, field));
where EMAIL is the key for the e-mailaddress field.

When a field fails the checksum, I put the text on the labels in red, like this: 
<span <logic:messagesPresent property="txtEmail">class="errorMsg"</logic:messagesPresent>>
    <fmt:message key="createuser.email" bundle="${adminLabels}" />
</span>

The problem is, the error for the e-mailaddress is shown twice.  Is there a way to show the error once, but to put the labels both in red?  

Tia

Björn De Bakker



This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information.  If you have received it in error, please notify the sender immediately and delete the original.  Any other use of the email by you is prohibited.