Jsf 2 JSF MethodExpression javax.el.PropertyNotFoundException
我正在尝试开发一个自定义组件,它需要从backingbean调用一个方法,以从bb获取一些数据。在某个Ajax调用之后,将在解码阶段使用Ajax调用中的一个参数调用它 我遇到的问题是,我将属性定义为taglibrary和组件中的MethodExpression,我获取Ajax post,解码参数,当我尝试从组件获取方法绑定时,我得到以下错误: javax.el.PropertyNotFoundException:/easyFaces.xhtml@19151 dataSource={theBean.loadDataFromSource}:类 “ar.com.easytech.faces.test.homeBean”没有该属性 “loadDataFromBean” 这是相关代码。。如果这不是正确的方法,请告诉我 标记库:Jsf 2 JSF MethodExpression javax.el.PropertyNotFoundException,jsf-2,propertynotfoundexception,Jsf 2,Propertynotfoundexception,我正在尝试开发一个自定义组件,它需要从backingbean调用一个方法,以从bb获取一些数据。在某个Ajax调用之后,将在解码阶段使用Ajax调用中的一个参数调用它 我遇到的问题是,我将属性定义为taglibrary和组件中的MethodExpression,我获取Ajax post,解码参数,当我尝试从组件获取方法绑定时,我得到以下错误: javax.el.PropertyNotFoundException:/easyFaces.xhtml@19151 dataSource={theBean
<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>
最后是生成错误的渲染方法:
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方法,它会识别该方法,并且错误更改为无法将list转换为MethodExpression,因此很明显,它只是将autocompleteFromSource解释为一个简单的属性,而不是方法定义,这是从BB调用方法的正确方法吗?假设这不是实际操作或验证,我找到了解决方案,因为事实证明,您还需要定义handler来定义方法签名,所以我创建了handler并将其添加到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;
}
}
实际上错误在类ar.com.easytech.faces.test.homeBean中,您能在其中显示函数loadDataFromBean吗?我用BB和.xhtml中的方法编辑了这个问题
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;
}
}