You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Maxence Dewil <m....@t4hr.com> on 2005/10/19 10:22:56 UTC

Validation of inter-dependent fields

Hello,

 

My application has to validate a form where a date depends on another
date (the first one must be < the next one), but the JSF validation is
component-oriented. How can I handle that in an elegant way?

 

A solution is described here but I don't understand how to achieve it :
http://weblogs.java.net/blog/johnreynolds/archive/2004/07/improve_jsf_by
_1.html (#Validation of Inter-Dependent Fields).

 

Regards,

 

Maxence Dewil


Re: Validation of inter-dependent fields

Posted by Mike Kienenberger <mk...@gmail.com>.
Mathias,

This request has come up on the mailing list quite often.
Any chance of a validateLessThan and validateGreaterThan addition to
tomahawk to complement validateEquals?   Maybe using a Comparable
interface if it's defined?

 -Mike

On 10/19/05, Mathias Brökelmann <mb...@googlemail.com> wrote:
> define a custom validator for the second date field (must be the second).
>
> <h:inputDate id="lowerDate" value="#{yourBackinBean.lowerDate}"/>
> <h:inputDate value="#{yourBackinBean.upperDate}"
> validator="#{yourBackingBean.validateDates}"/>
>
> public class YourBackingBean
> {
>   public void validateDates(FacesContext context, UIComponent
> component, Object value) throws ValidatorException
>   {
>     UIInput lowerComponent = (UIInput)component.findComponent("lowerDate");
>     if(lowerComponent.isValid())
>     {
>       Date lowerDate = lowerComponent.getValue();
>       Date upperDate = (Date)value;
>       // compare the two dates and throw a ValidatorException with
> message if they are not valid
>     }
>   }
> }
>
>
> 2005/10/19, Maxence Dewil <m....@t4hr.com>:
> >
> >
> >
> > Hello,
> >
> >
> >
> > My application has to validate a form where a date depends on another date
> > (the first one must be < the next one), but the JSF validation is
> > component-oriented. How can I handle that in an elegant way?
> >
> >
> >
> > A solution is described here but I don't understand how to achieve it :
> > http://weblogs.java.net/blog/johnreynolds/archive/2004/07/improve_jsf_by_1.html
> > (#Validation of Inter-Dependent Fields).
> >
> >
> >
> > Regards,
> >
> >
> >
> > Maxence Dewil
>
>
> --
> Mathias
>

Re: Validation of inter-dependent fields

Posted by Mathias Brökelmann <mb...@googlemail.com>.
define a custom validator for the second date field (must be the second).

<h:inputDate id="lowerDate" value="#{yourBackinBean.lowerDate}"/>
<h:inputDate value="#{yourBackinBean.upperDate}"
validator="#{yourBackingBean.validateDates}"/>

public class YourBackingBean
{
  public void validateDates(FacesContext context, UIComponent
component, Object value) throws ValidatorException
  {
    UIInput lowerComponent = (UIInput)component.findComponent("lowerDate");
    if(lowerComponent.isValid())
    {
      Date lowerDate = lowerComponent.getValue();
      Date upperDate = (Date)value;
      // compare the two dates and throw a ValidatorException with
message if they are not valid
    }
  }
}


2005/10/19, Maxence Dewil <m....@t4hr.com>:
>
>
>
> Hello,
>
>
>
> My application has to validate a form where a date depends on another date
> (the first one must be < the next one), but the JSF validation is
> component-oriented. How can I handle that in an elegant way?
>
>
>
> A solution is described here but I don't understand how to achieve it :
> http://weblogs.java.net/blog/johnreynolds/archive/2004/07/improve_jsf_by_1.html
> (#Validation of Inter-Dependent Fields).
>
>
>
> Regards,
>
>
>
> Maxence Dewil


--
Mathias