如何将MethodExpression与自定义JSF组件的参数一起使用?

时间:2015-01-07 21:35:24

标签: jsf el custom-component

我正在尝试编写一个自定义JSF树组件,它支持将侦听器添加为属性:

<foo:tree value="#{barController.treeNodes}"
                  type="sidenav"
                  onNodeSelect="#{barController.onTreeClick}">
</foo:tree>

侦听器会接受一个事件参数,如下所示:

public void onTreeClick(TreeSelectEvent event) {}

组件类具有Method表达式的getter / setter,如下所示:

/**
 * @return the onNodeSelect
 */
public MethodExpression getOnNodeSelect() {
    return (MethodExpression ) getStateHelper().eval(PropertyKeys.onNodeSelect);
}

/**
 * @param onNodeSelect the onNodeSelect to set
 */
public void setOnNodeSelect(MethodExpression onNodeSelect) {
    getStateHelper().put(PropertyKeys.onNodeSelect, onNodeSelect);
}

但是,当我调用component.getOnNodeSelect()时,我收到以下错误:

Caused by: javax.el.PropertyNotFoundException: /sandbox.xhtml @22,73 onNodeSelect="#   {barController.onTreeClick}": The class 'com.bar.barController$Proxy$_$$_WeldClientProxy' does not have   the property 'onTreeClick'.
 at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111)
 at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
 at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)

似乎JSF将我的MethodExpression视为ValueExpression,并试图调用一些getter来查找属性。有什么办法可以强迫它使用MethodExpression吗?

我甚至尝试更新tag-lib以添加方法签名:

<attribute>
        <name>onNodeSelect</name>
        <description>The listener to be called when a node has been   selected</description>
        <method-signature>void  process(com.bar.tag.foundation.TreeSelectEvent)</method-signature>
        <type>javax.el.MethodExpression</type>
</attribute>

任何帮助将不胜感激!

0 个答案:

没有答案