-
1. Re: validator for two components at once
marx3 Jul 1, 2008 11:31 AM (in response to marx3)
two datesFor example first field 2007-01-01 must be before the second one 2007-10-10
Is it possible to write validator, which gets values from two different components?
-
2. Re: validator for two components at once
mail.micke Jul 1, 2008 12:31 PM (in response to marx3)Tomahawk seems to have a validator that does this, perhaps it can be used or at least used as a reference when implementing your own.
Take a look here SVN validateEqual
-
3. Re: validator for two components at once
tom_goring Jul 1, 2008 12:50 PM (in response to marx3)You could for your entities:
@AssertTrue(message="Message Text") @Transient public boolean isValid() { // .... }
-
4. Re: validator for two components at once
yetidesalpes Jul 2, 2008 10:06 AM (in response to marx3)I did something like that :
@Name("ratePeriodValidator") @org.jboss.seam.annotations.faces.Validator public class RatePeriodValidator implements Serializable, Validator { @In(create = true) RatePeriodHome ratePeriodHome; @In("#{messages['date.to.before.from']}") private String dateToBeforeFrom; public void validate(FacesContext arg0, UIComponent arg1, Object value) throws ValidatorException { if (!((Date) value).after(ratePeriodHome.getInstance().getBegin())) throw new ValidatorException(new FacesMessage(dateToBeforeFrom)); } }
and in the view :
<rich:calendar id="end" validator="ratePeriodValidator" value="#{ratePeriodHome.instance.end}"> <s:validate/> </rich:calendar>
Hope this helps !
-
5. Re: validator for two components at once
stephen Jul 2, 2008 10:26 AM (in response to marx3)Huh? How can that work?
At the time your validator runs, the values have not yet been saved to the entity, so ratePeriodHome.getInstance().getBegin() won't return the current (local
) value to which you need to compare against.
Or maybe I am missing something? -
6. Re: validator for two components at once
marx3 Jul 2, 2008 10:43 AM (in response to marx3)I did it in different way: i've set
label
property in richcalendar component (i don't see it used anywhere) like ">toDate". In validator i read this property. First sign means which date should be bigger. The rest is used to lookup second component from facesContext, then fire converter from this object (converter.getAsObject) to read second value. Now I have two values and I can compare them.It's hack, but works. I've tried with
<f:param ... value="toDate">
inside <f:validator> but I couldn't read it in validator. Maybe there is better way to pass name of second field to validator...?
-
7. Re: validator for two components at once
yetidesalpes Jul 3, 2008 9:53 AM (in response to marx3)Oops, I forgot that , in my case, the getBegin() date is computed and not editable...
Sorry !