http://struts.apache.org/2.1.2/docs/using-field-validators.html
<s:form ...> ........ <s:textfield label="Required Validator Field" name="requiredValidatorField" /> <s:textfield label="Field Expression Validator Field" name="fieldExpressionValidatorField" /> ..... </s:form> package org.apache.struts2.showcase.validation; public class FieldValidatorsExampleAction extends AbstractValidationActionSupport { private String requiredValidatorField = null; public String getRequiredValidatorField() { return requiredValidatorField; } public void setRequiredValidatorField(String requiredValidatorField) { this.requiredValidatorField = requiredValidatorField; } private String fieldExpressionValidatorField = null; public String getFieldExpressionValidatorField() { return fieldExpressionValidatorField; } public void setFieldExpressionValidatorField(String fieldExpressionValidatorField) { this.fieldExpressionValidatorField = fieldExpressionValidatorField; } } } WEB-INF/classes/validator.xml <validators> ........ <field name="requiredValidatorField"> <field-validator type="required"> <message><![CDATA[ required ]]></message> </field-validator> </field> <field name="fieldExpressionValidatorField"> <field-validator type="fieldexpression"> <param name="expression">(fieldExpressionValidatorField == requiredValidatorField)</param> <message><![CDATA[ must be the same as the Required Validator Field if specified ]]></message> </field-validator> </field> .......... </validators>Martin Gainty ______________________________________________ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. > To: user@struts.apache.org > Subject: Re: Validating that two fields match? > Date: Thu, 13 Aug 2009 10:06:38 -0400 > From: musom...@aol.com > > > try the pattern > > <field name="model.pointOfContact.emailAddress"> > etc > > > > > > > > -----Original Message----- > From: James Carr <james.r.c...@gmail.com> > To: Struts Users Mailing List <user@struts.apache.org> > Sent: Thu, Aug 13, 2009 9:53 am > Subject: Re: Validating that two fields match? > > > > > > > > > > > I have tried this and it doesn't seem to work at all. I am using > ModelDriven and the model object has a PointOfContact object with an > emailAddress and confirmingEmail attributes. > > <field name="pointOfContact.emailAddress"> > <field-validator type="requiredstring"> > <param name="trim">true</param> > <message>Email Address is required.</message> > </field-validator> > <field-validator type="email"> > <message>Please enter a valid email</message> > </field-validator> > <field-validator type="expression"> > <param > name="expression">(pointOfContact.emailAddress.equals(pointOfContact.confirmingEmail))</param> > <message>Verify that you have entered the same email > address in both fields</message> > </field-validator> > </field> > > The other two validators above it work. > > Thanks, > James > > On Wed, Aug 12, 2009 at 5:59 PM, <musom...@aol.com> wrote: > > > > Check out > > http://struts.apache.org/2.x/docs/expression-validator.html > > > > If you are using annotations check out > > > > http://struts.apache.org/2.x/docs/expressionvalidator-annotation.html > > > > Your expression will be something like > > @ExpressionValidator(expression="email.equals(confirmEmail)",? message="The > email fields do not match") > > > > > > > > Chris > > > > > > > > > > -----Original Message----- > > From: James Carr <james.r.c...@gmail.com> > > To: Struts Users Mailing List <user@struts.apache.org> > > Sent: Wed, Aug 12, 2009 5:30 pm > > Subject: Validating that two fields match? > > > > > > > > > > > > > > > > > > > > > > Hello, > > > > Is there something out of the box that will let me validate if two > > fields match in struts2? An example would be a form with email and > > confirmingEmail fields. > > > > Thanks, > > James > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > > For additional commands, e-mail: user-h...@struts.apache.org > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > > > > > _________________________________________________________________ Get your vacation photos on your phone! http://windowsliveformobile.com/en-us/photos/default.aspx?&OCID=0809TL-HM