this question has answer here:
i've been trying "generic" dialog, autocomplete functionality, work few days now. turns out, creating methodexpression "wrong way". thought i'd document here.
to reiterate: want dynamically create methodexpression, store in property , use in jstl template or jsf page.
for example:
// 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), example <rich:autocomplete mode="cachedajax" minchars="2" autocompletemethod="#{autocompletemethod}" />
i've found solution @ http://javaevangelist.blogspot.co.at/2012/10/jsf-2x-tip-of-day-programmatically_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); }
you can create methodexpression , store in property. richfaces autocomplete, signature is: 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 questions example, we'd need set property here: this.autocompmethod = autocompletemethod;
then have apropriate getter:
methodexpression getautocompmethod() { return this.autocompmethod; }
Comments
Post a Comment