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: converter
Type: javax.el.ValueExpression
(must evaluate to java.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).
See also: