2

I´m trying to create a simple composite component with a selectOneMenu... It is really simple:

<cc:implementation>
    <h:panelGrid columns="2">
        <p:outputLabel for="#{cc.attrs.fieldId}" value="#{cc.attrs.fieldLabel}"/>
        <p:selectOneMenu id="#{cc.attrs.fieldId}" required="#{cc.attrs.required}" converter="#{cc.attrs.converter}" value="#{cc.attrs.targetValue}">
                <f:selectItem itemLabel="#{msg['label.selecione.item']}" itemValue="" />
                <f:selectItems value="#{cc.attrs.listValue}"/>
        </p:selectOneMenu>
    </h:panelGrid>          
</cc:implementation>

So, the problem is when I´m trying to pass the converter! That is an ENUM converter (extends EnumConverter with @FacesConverter(value = "tipoCampoConverter") annotation)

The error is: javax.el.ELException: Cannot convert tipoCampoConverter of type class java.lang.String to interface javax.faces.convert.Converter

**EDIT:

Some extra info:

I tried to declare the attribute with and without the 'type':

    <cc:attribute name="converter" required="true" type="javax.faces.convert.Converter"/>

Some more info: INFO: Starting Servlet Engine: Apache Tomcat/7.0.12 INFO: Initializing Mojarra 2.1.10 INFO: Running on PrimeFaces 3.4.2 INFO: Running on PrimeFaces Extensions 0.6.1

:)

1 Answer 1

7

The converter attribute expects by default a Converter instance when the value is a ValueExpression. Something like this <h:inputText converter="#{bean.converter}">. This unintuitive behaviour in composites is unfortunately "by design".

Your best bet is to use <f:converter> instead.

<p:selectOneMenu ...>
    ...
    <f:converter converterId="#{cc.attrs.converter}" />
</p:selectOneMenu>

Unrelated to the concrete problem, you do not need a converter for this particular use case at all. JSF has already a builtin enum converter. You only need this converter if you're binding an UISelectMany component to a List<E> instead of E[].

See also:

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.