The validator doesnt reject it because 'choice' is a value as well, and thus valid. A validator cannot on it is own determine that 'choice' is an invalid value for a 'gender' field Besides that you also need to set an actual validator on your PropertySelection component, otherwise it will never work.
Writing a custom validator is the best solution I guess,, and it is not that hard: public class SelectValidator implements Validator { public void validate(IFormComponent field, ValidationMessages messages, Object obj) throws ValidatorException { if (((String) obj).startsWith("choice")) { throw new ValidatorException("You must select either man or woman for " + field.getDisplayName() + "."); } } public boolean getAcceptsNull() { return false; } public boolean isRequired() { return false; } public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) { // not impl } } Don;t forget to put it in hivemodule.xml as well: <module id="project" version="1.0.0" package="your.projects.package"> </contribution> <contribution configuration-id="tapestry.form.validator.Validators"> <validator name="mustSelect" configurable="false" class="your.projects.package.validator.SelectValidator"/> </contribution> </module> -----Original Message----- From: news [mailto:[EMAIL PROTECTED] On Behalf Of Carl Pelletier Sent: vrijdag 28 april 2006 16:53 To: tapestry-user@jakarta.apache.org Subject: HOW TO validate the first choice of IPropertySelectionModel Hi everyone. I'm new to Tapestry 4 (never use Tapestry before) and I would like to say that I love it! But now, I'm trying to do a simple thing: I would like to display a combo box on my page with 3 values: "choice", "man", "women" and validate the value selected. The dropdown is required so if the user choose "choice" the validator must reject it. I trying to do it with a StringPropertySelectionModel and would like to avoid of doing a custom validator or a custom been. The default value of the combo box is "choice" so when the user submit the form, the validator must return a error. What I am missing? I search the mailling list and found nothing like this. Sorry If I mist something. sorry for the bad english to. I'm french. Here are the IPropertySelectionModel example: -------------------------- public static final IPropertySelectionModel SEXE_MODEL = new StringPropertySelectionModel( new String[] { "Choisir", "Homme", "Femme" }); ------------------------- Here are the method called on the submit of the form: ------------------------ public String onOK() { ValidationDelegate delegate = this.getDelegate(); if (delegate.getHasErrors()) { return null; } getContactCRUDService().save(getContact(), getInternalId() == null); return "contactList"; } ------------------------ Here are the combo box in the HTML page. ------------------------ <select jwcid="[EMAIL PROTECTED]" model="ognl:@[EMAIL PROTECTED]" value="ognl:Contact.Birth.sexe"> <option value="Choisir" selected="selected">Choisir</option> <option value="">---------------</option> <option value="Homme" >Homme</option> <option value="Femme">Femme</option> </select> ------------------------ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]