几天来,我一直试图获得一个具有自动完成功能的“通用”对话框。结果,我只是以“错误的方式”创建了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}"
/>发布于 2016-08-01 16:11:50
我在20.html找到了解决方案
public static MethodExpression createMethodExpression(String methodExpression, Class<?> expectedReturnType, Class<?>[] expectedParamTypes) {
FacesContext context = FacesContext.getCurrentInstance();
return context.getApplication().getExpressionFactory()
.createMethodExpression(context.getELContext(), methodExpression, expectedReturnType, expectedParamTypes);
}然后,您可以创建一个MethodExpression并将其存储在一个属性中。对于RichFaces自动完成,签名是:List<String> autocomplete(String prefix)
@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;
}https://stackoverflow.com/questions/38703477
复制相似问题