0

There is a problem that is driving me crazy. I am trying to display a value from a composite component. But it never gets printed.

<cc:interface>
    <cc:attribute name="parts" type="java.util.List" required="true""/>
    <cc:attribute name="context" type="String" required="true""/>
</cc:interface>

<!-- IMPLEMENTATION -->
<cc:implementation>
...
            <c:forEach items="#{cc.attrs.parts}" var="part">
...
                    <td>#{part.roles(cc.attrs.context)}</td>
...
            </c:forEach>
...
</cc:implementation>

The method behind #{part.roles(cc.attrs.context)} is never called (no errors, no printing).

If I use #{part.roles("Example")} I obtain:

javax.el.ELException: /resources/utils/parts.xhtml: Method not found: class com.ex.Part.roles(java.lang.String)

Both parts and context have values (I can print them) and calling #{part.roles} prints indeed the HashMap. Am I missing something?

public class Part implements Serializable {

    private HashMap<String, String> roles;
....
    // This can be called OK
    public HashMap<String, String> getRoles() {
        return roles;
    }

    public String getRoles(String id) {
    //Never called
        if ((roles != null) && (id != null)) {
            return roles.get(id);
        }
        return null;
    }
}

EDIT

First error is that the calling part should be:

#{part.getRoles(cc.attrs.context)}

So using #{part.getRoles("Hello")} at least calls the method correctly. But still cc.attrs.context is not rendering properly as an argument (the method is not called), even though it renders well as #{cc.attrs.context}.


EDIT 2

Funnier. This works

<c:set var="ci" value="#{cc.attrs.context}" scope="request"/>
<td>#{part.getRoles(ci)}</td>

I wonder if this is just a bug


EDIT 3

I am using TomEE 1.7.4.

In my pom.xml I have:

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version> <!-- TomEE only supports 6.0 -->
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.faces</artifactId>
        <version>2.2.13</version>
        <scope>runtime</scope>
    </dependency>

I am not sure why the second dependency is necessary (TomEE was supposed to be enough), but without it the program gives me this error:

Could not get component metadata for xxx.xhtml. Did you forget to specify <composite:interface>?
user1156544
  • 1,725
  • 2
  • 25
  • 51

0 Answers0