webtier@glassfish.java.net

JSF2: Field/form validation

From: <webtier_at_javadesktop.org>
Date: Mon, 27 Sep 2010 02:55:08 PDT

Hello, I want to validate forms with variable properties from a database.
e.g fetching the allowed min. length of a field from the database and validating it with the form field.

<h:inputText value="#{partnerRelasjonModel.selectedEntity.partnerBarn.partnernummer}" alidator="#{partnerRelasjonValidator.partnernummer}" />

public void partnernummer(FacesContext facesContext, UIComponent uiComponent, Object o) throws ValidatorException {
       // db lookup and validation ...
    }

Given that h:inputText's value is a string (i.e. the getter returns a string) this is a working solution.

The problem: my entities does not only contain strings, but also integers - inputText's validator does not seem to work with Integers.

    (value=Integer)
    <h:inputText value="#{partnerRelasjonModel.selectedEntity.garantiperiode}" validator="#{partnerRelasjonValidator.garantiperiode}" />


    public void garantiperiode(FacesContext facesContext, UIComponent uiComponent, Object o) throws ValidatorException {
       // db lookup and validation ...
    }


There are no signs of errors or such; the method "garantiperiode" is not even invoked.
No luck googling for a solution either.

Is there a "best practice"-solution for validating forms, witch supports my requirements?
[Message sent by forum member 'airblade']

http://forums.java.net/jive/thread.jspa?messageID=483751