【问题标题】:JSF MethodExpression javax.el.PropertyNotFoundExceptionJSF MethodExpression javax.el.PropertyNotFoundException
【发布时间】:2012-10-30 21:02:05
【问题描述】:

我正在尝试开发一个自定义组件,该组件需要从 backingbean 调用一个方法以从 bb 获取一些数据(这将在某个 Ajax 调用后的解码阶段调用),并带有一个参数(它将来 ajax 调用)。

我遇到的问题是我将属性定义为 MethodExpression(在标记库和组件中),我得到了 Ajax 帖子,解码参数,当我尝试从我得到的组件中获取方法绑定时以下错误:

javax.el.PropertyNotFoundException: /easyFaces.xhtml @19,151 dataSource="#{theBean.loadDataFromSource}": 类 'ar.com.easytech.faces.test.homeBean' 没有属性 'loadDataFromBean'。

这是相关代码..(如果这不是正确的方法,请告诉我..)

标签库:

<attribute>
    <display-name>Data Source</display-name>
    <name>dataSource</name>
    <required>true</required>
    <type>javax.el.MethodExpression</type>
    <method-signature>java.util.List theDataSource(java.lang.String)</method-signature>
</attribute>

组件定义:

public class Autocomplete extends HtmlInputText implements ClientBehaviorHolder 
...
    public MethodExpression getDataSource() {
        return (MethodExpression) getStateHelper().eval(PropertyKeys.dataSource);
    }

    public void setDataSource(MethodExpression dataSource) {
        getStateHelper().put(PropertyKeys.dataSource, dataSource);
    }

最后是产生错误的渲染方法:

private List<Object> getData(FacesContext context, Autocomplete autocomplete, String data) {

    Object dataObject = null;
    MethodExpression dataSource = autocomplete.getDataSource();

    if (dataSource != null) {
        try {
            dataObject = dataSource.invoke(context.getELContext(), new Object[] {data});
            return convertToList(dataObject);
        } catch (MethodNotFoundException e) {
            logger.log(Level.INFO,"Method not found: {0}", dataSource.getExpressionString() );

        }
    }
    return null;

}

这是来自BB的方法

public List<String> autcompleteFromSource(String param) {

    List<String> tmpData = new ArrayList<String>();
    tmpData.add("XXA_TABLE_A");
    tmpData.add("XXA_TABLE_B");
    tmpData.add("XXA_TABLE_C");

    return tmpData;
}

以及带有组件的.xhtml

<et:autocomplete id="autoc" minLength="3" delay="500" value="#{easyfacesBean.selectedValue}" dataSource="#{easyfacesBean.autcompleteFromSource}" />

问题是,如果我定义一个方法 getAutocompleteFromSource() 它识别该方法并且错误更改为无法将列表转换为 MethodExpression,因此显然它只是将 autocompleteFromSource 解释为一个简单的属性而不是方法定义,是这甚至是从 BB 调用方法的正确方法? (考虑到这不是实际行动也不是验证)

【问题讨论】:

  • 其实错误是在ar.com.easytech.faces.test.homeBean类中,能不能把里面的函数loadDataFromBean显示出来?
  • 我用 BB 和 .xhtml 的方法编辑了问题

标签: jsf-2 propertynotfoundexception


【解决方案1】:

我找到了解决方案,因为事实证明您还需要定义一个“处理程序”来定义方法签名,所以我创建了处理程序并添加到 taglib 并且一切都开始正常工作..仅供参考..这是处理程序..

问候

public class AutocompleteHandler extends ComponentHandler {

    public AutocompleteHandler(ComponentConfig config) {
        super(config);
    }

    protected MetaRuleset createMetaRuleset(Class type) {
        MetaRuleset metaRuleset = super.createMetaRuleset(type);
        metaRuleset.addRule(new MethodRule("dataSource", List.class, new Class[] { String.class }));
        return metaRuleset;
    }

}

【讨论】:

    猜你喜欢
    • 2012-10-27
    • 2014-06-06
    • 2016-12-06
    • 2012-04-29
    • 2015-02-25
    • 2015-10-01
    • 2016-02-17
    • 2013-08-28
    • 2012-04-12
    相关资源
    最近更新 更多