You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Martin Koci <ma...@aura.cz> on 2010/02/10 15:50:10 UTC

[core] converterId/validatorId and binding

Hi,


there is probably a unclarity regarding cooperation of
converterId/validatorId and binding attributes from f:converter and
f:validator facelets tags.
https://javaserverfaces.dev.java.net/nonav/docs/2.0/pdldocs/facelets/f/converter.html says that converterId is not required, same for validatorId. 

I didn't find what should happen if user does not specify converterId
and binding leads to null object. Simple test page

<h:inputText value="#{testBean.value}" >
 <f:converter binding="#{aNonExistentBean}" /> 
</h:inputText>

confirms that this is mystery for mojarra developers too - it throws
javax.faces.view.facelets.TagException: /test.xhtml @10,54 <f:converter>
Default behavior invoked of requiring a converter-id passed in the
constructor, must override ConvertHandler(ConverterConfig)


Specification does not speak about facelets tag directly but 9.4.5
<f:converter> (for JSP) contains this text:

"The createConverter() method must:

If binding is non-null, call binding.getValue() to obtain a reference to
the Converter instance. If there is no exception thrown, and
binding.getValue() returned a non-null object that implements
javax.faces.convert.Converter, register it by calling setConverter(). If
there was an exception thrown, rethrow the exception as a JspException.
Use the converterId attribute if the converter instance could not be
created from the binding attribute. If the converterId attribute is set,
call the createConverter() method of the Application instance for this
application, passing converter id specified by their converterId
attribute. If the binding attribute was also set, store the converter
instance by calling binding.setValue(). Register the converter instance
by calling setConverter(). If there was an exception thrown, rethrow the
exception as a JspException."

Please notice the sentence "If the converterId attribute is set". I
suggest to follow this behavior in ConvertDelegateHandler and log a
warning or add a FacesMessage in develelopment mode if user uses
f:converter tag without converterId and with null binding (same for
f:validator).

Regards,

Martin Kočí

Related issue: https://issues.apache.org/jira/browse/MYFACES-2536