Is there any difference between converter="entityConverter" and converter="#{entityConverter}" ?
Initially, my application works as a charm with such code:
<p:selectOneMenu id="civilityId"
value="#{customerController.selected.civilityId}"
converter="civilityConverter"> ...
but when I change converter="civilityConverter" to converter="#{civilityConverter}",
I get this error :
Grave: Error Rendering View[/customer/index.xhtml]
javax.el.PropertyNotFoundException: /customer/Edit.xhtml @30,186
value="#{customerController.selected.civilityId}":
Target Unreachable, 'null' returned null
Thanks for any help.
Although this is not specific to the <p:selectOneMenu>, it would be worthwhile to just check its tag documentation if it gives any hints. It says the following:
Name:
converterType:
javax.el.ValueExpression(must evaluate tojava.faces.convert.Converter)Description: An el expression or a literal text that defines a converter for the component. When it's an EL expression, it's resolved to a converter instance. In case it's a static text, it must refer to a converter id.
So, in case of
converter="entityConverter"
it will be resolved as a converter ID which is declared via either the @FacesConverter annotation on the converter class
@FacesConverter("entityConverter")
public class EntityConverter implements Converter {}
or the <converter-id> entry of <converter> registration in faces-config.xml:
<converter>
<converter-id>entityConverter</converter-id>
<converter-class>com.example.EntityConverter</converter-class>
</converter>
And, in case of
converter="#{entityConverter}"
it will be resolved as a concrete Converter instance in the EL context. The normal way to put such an instance in the EL context is to declare it as a managed bean. E.g. via JSF
@ManagedBean
@RequestScoped
public class EntityConverter implements Converter {}
or via CDI
@Named
@RequestScoped
public class EntityConverter implements Converter {}
This is often done so in order to be able to inject an @EJB into it, so that any necessary business/DB logic could be performed. Until the upcoming JSF 2.3, the @FacesConverter (and @FacesValidator) namely doesn't support dependency injection (which you could however work around by using JSF utility library OmniFaces).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With