在复合组件中不调用方法

时间:2016-04-13 09:17:30

标签: jsf el composite-component methodnotfound

有一个问题让我发疯。我试图从复合组件中显示一个值。但它永远不会被打印出来。

<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>

#{part.roles(cc.attrs.context)}背后的方法永远不会被调用(没有错误,没有打印)。

如果我使用#{part.roles("Example")},我会获得:

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

partscontext都有值(我可以打印它们),调用#{part.roles}确实打印了HashMap。我错过了什么吗?

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;
    }
}

修改

第一个错误是调用部分应该是:

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

所以使用#{part.getRoles("Hello")}至少可以正确调用方法。 但是cc.attrs.context仍未正确呈现为参数(该方法未被调用),即使它呈现为#{cc.attrs.context}

编辑2

有趣。这工作

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

我想知道这只是一个错误

编辑3

我正在使用TomEE 1.7.4。

pom.xml我有:

    <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>

我不确定为什么第二个依赖是必要的(TomEE应该足够了),但没有它,程序会给我这个错误:

Could not get component metadata for xxx.xhtml. Did you forget to specify <composite:interface>?

0 个答案:

没有答案
相关问题