way of validation handling

Hi all,

i have a form with different fields and would like to check whether the fields have correct values (e.g. comparison of some fields, checks of date-patterns, checks of negative/positve values, checks of correct type: int, string, etc.)

as i unterstood there are a lot of possibilites to make a validation handling.

What is the best one?

my idea was following:

create own bean (ValidationBean) where i check my values:

void validateA(){...}

void validateB(){...}

in jsf i put after each inputText-Tag a validator attribut:

<h:inputText id="a" value="#{myBean.a}" validator ="#{validationBean.validateA}">

<h:inputText id="b" value="#{myBean.b}" validator ="#{validationBean.validateB}">

if i get an error of one of validation methods i set in my ValidationBean error and give it out later in my jsf :

<h:outputText value=#{msg.errorValueA} rendered="#{validationBean.aError}/>

<h:outputText value=#{msg.errorValueB} rendered="#{validationBean.bError}/>

so it runs, but if i give a string in an integer field my action (validateA or validateB) is never called.Why?

Is there any simple way for validation handling?

[1716 byte] By [naekoa] at [2007-11-27 5:14:20]
# 1

> but if i give a string in an integer field my action (validateA or validateB) is

> never called.Why?

If you have added <h:messages /> to the form, then you'll notice that there is a conversion exception occurred. This will occur before validation. Also see http://balusc.xs4all.nl/srv/dev-jep-djl.html Workaround is to create a custom converter or to use a String field instead. Or to use componentbinding instead of valuebinding and use UIComponent#getValue().

BalusCa at 2007-7-12 10:36:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

yes....i expanded my code:

<h:inputText id="a" value="#{myBean.a}" validator = "#{validationBean.validateA}">

<f:converter converterId="javax.faces.Integer"/>

</h:inputText>

and get now the conversion exception as you said.

But i need internationalize my error messages and here i just get the default exception from JSF. Is there any way to overwrite this error message with my own?

naekoa at 2007-7-12 10:36:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...