Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中创建MethodExpression(并在JSF中使用)_Jsf_Richfaces_El_Uiinclude_Methodexpression - Fatal编程技术网

在Java中创建MethodExpression(并在JSF中使用)

在Java中创建MethodExpression(并在JSF中使用),jsf,richfaces,el,uiinclude,methodexpression,Jsf,Richfaces,El,Uiinclude,Methodexpression,几天来,我一直在尝试创建一个带有自动完成功能的“通用”对话框。事实证明,我只是用“错误的方式”创建了MethodExpression。所以我想我应该把这个记录在这里 重申:您希望动态创建MethodExpression,将其存储在属性中,并在JSTL模板或JSF页面中使用它 例如: // Template <c:forEach items="#{property.subItems}" var="subitem"> <ui:include src="editor.xhtml"

几天来,我一直在尝试创建一个带有自动完成功能的“通用”对话框。事实证明,我只是用“错误的方式”创建了MethodExpression。所以我想我应该把这个记录在这里

重申:您希望动态创建MethodExpression,将其存储在属性中,并在JSTL模板或JSF页面中使用它

例如:

// Template
<c:forEach items="#{property.subItems}" var="subitem">
  <ui:include src="editor.xhtml">
    <ui:param name="autocompleteMethod" value="#{subitem.autocompMethod}" />
  </ui:include>
</c:forEach>

// editor.xhtml
// We're using RichFaces (unfortunately), but this is just an example
<rich:autocomplete mode="cachedAjax" minChars="2"
      autocompleteMethod="#{autocompleteMethod}"
/>
//模板
//editor.xhtml
//我们正在使用RichFaces(不幸的是),但这只是一个例子

我在


你怎么认为这是一个复制品?您链接的问题使用OmniFaces和PrimeFaces等特定框架来解决问题。这里的主要内容是如何从代码构造MethodExpression。我可能在RichFaces小部件中使用它,但这只是一个使用示例,可以替换。该解决方案本身是纯JSF,可与所有*Faces框架一起使用。
public static MethodExpression createMethodExpression(String methodExpression, Class<?> expectedReturnType, Class<?>[] expectedParamTypes) {
    FacesContext context = FacesContext.getCurrentInstance();
    return context.getApplication().getExpressionFactory()
            .createMethodExpression(context.getELContext(), methodExpression, expectedReturnType, expectedParamTypes);
}
@SuppressWarnings("rawtypes") // Generics use type erasure
Class<List> retType = List.class;
Class<?>[] paramTypes = {String.class};
MethodExpression autocompleteMethod = createMethodExpression("#{myBean.myAutocomplete}", retType, paramTypes);
// In the questions example, we'd need to set a property here:
this.autocompMethod = autocompleteMethod;
MethodExpression getAutocompMethod() {
    return this.autocompMethod;
}