One of the af:table feature is a filter over its column to filter its data. You can manipulate with this fields with backingbean, this manipulation can be as :
- Execute some code before filtering.
- Execute some code after filtering.
- Add something to the value you enter to filter before filtering.
- Re-execute query.
.
.
.
to do this follow this steps :
1- Bind your table in the backingbean (e.g.in Binding property of table set #{myBackingbean.myTable}).
2- In table QueryListener property set its value to
#{ myBackingbean.onTableQueryExecuted}
3- In your backingbean implement onTableQueryExecuted with:
public void onTableQueryExecuted(QueryEvent queryEvent) {
// If needed, do something before the table's query is processed
invokeMethod("#{bindings.DeptView1Query.processQuery}",QueryEvent.class,queryEvent);
// Where DeptView1Query is a searchRegion name in your binding
// If needed, do something after the table's query is processed
}
public static Object invokeMethod(String expr, Class[] paramTypes,
Object[] params) {
FacesContext fc = FacesContext.getCurrentInstance();
ELContext elc = fc.getELContext();
ExpressionFactory ef = fc.getApplication().getExpressionFactory();
MethodExpression me =
ef.createMethodExpression(elc, expr, Object.class, paramTypes);
return me.invoke(elc, params);
}
public static Object invokeMethod(String expr, Class paramType,
Object param) {
return invokeMethod(expr, new Class[] { paramType },
new Object[] { param });
}
To get the value which you enter to filter the column :
private FilterableQueryDescriptor getTableQueryDescriptor() {
return (FilterableQueryDescriptor)getMyTable().getFilterModel();
}
private Map getTableFilterCriteria() {
return getTableQueryDescriptor().getFilterCriteria();
}
getTableFilterCriteria().clear(); // to clear all filds.
getTableFilterCriteria().put("Dname","%N%");// to set value of the filterable field .
getTableFilterCriteria().remove("Dname"); // to clear the Dname Filterable text only.
getTableFilterCriteria().get("Dname");// to get the value that you enter to filter the table.
To re-execute query:
QueryEvent queryEvent = new QueryEvent(getMyTable(),getTableQueryDescriptor() );
queryEvent.setPhaseId(PhaseId.INVOKE_APPLICATION);
getTable().queueEvent(queryEvent);
Admiring the time and energy you put into your site and detailed information you provide.
ReplyDeleteIt's awesome to come across a blog every once in a while that isn't the same outdated rehashed information.
Fantastic read! I've bookmarked your site and I'm including your
RSS feeds to my Google account. Many thanks!
my website - usb solar charger ()
Very helpful info!,thank you for sharing knowledge :)
ReplyDelete