JSF MethodExpression javax.el.PropertyNotFoundException [英] JSF MethodExpression javax.el.PropertyNotFoundException

查看:140
本文介绍了JSF MethodExpression javax.el.PropertyNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个自定义组件,该组件需要使用一个参数(它将参加ajax调用).

I'm trying to develop a custom component that will need to call a method from the backingbean to get some data from the bb (this will be called in the decode phase after a certain Ajax call) with one parameter (it will come in the ajax call).

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

The problem I'm having is that I define the attribute as a MethodExpression (in the taglibrary and the component), I get the Ajax post, decode the parameter and when I try to get the Method binding from the component I get the following error:

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

javax.el.PropertyNotFoundException: /easyFaces.xhtml @19,151 dataSource="#{theBean.loadDataFromSource}": The class 'ar.com.easytech.faces.test.homeBean' does not have the property 'loadDataFromBean'.

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

Here is the relevant code.. (and please let me know if this is not the correct way to do this..)

taglib:

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

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

and finally the rendered method that generates the error:

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及其组件

And the .xhtml with the component

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

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

The thing is if I define a method getAutocompleteFromSource() it recognised the method and the error changes to can't convert list to MethodExpression, so evidently it is simply interpreting the autocompleteFromSource as a simple property and not a method definition, is this even the correct way to call method from BB? (giving that it's not an actual action nor validation )

推荐答案

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

I found the solution for this, as it turns out you also need to define a "Handler"to define the Method Signature, so I created the handler and added to the taglib and everything started to work fine..just for reference.. here is the handler..

致谢

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

}

这篇关于JSF MethodExpression javax.el.PropertyNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆