I came across a requirement where a table having a list of employee entities. The table is not a updatable table. So each row is modified by a form that comes up in a dialog on selecting a row. A new row is created on clicking + icon in the table toolbar. This table has filtering enabled. I have a flag "Show only to be submitted entities". On selecting the checkbox corresponding to that flag, the table should show only the newly added or modified rows.
To achieve this, I followed a simple approach of using filtering. Firstly I maintained a transient attribute in the entity which is a plain string and is updated on every new row creation or modification. I call that attribute a marker and the values are (N) for newly newly added ones and (M) for modified ones. On clicking the "Show only to be submitted entities"checkbox, I am populating a filter criteria saying marker startswith "(". Then queued the queryevent. This table has filtering enabled. So I also ensured that the existing filters are not disturbed. The "showOnlyToSubmitEntities" is boolean flag that preserves the selection of "Show only to be submitted entities" checkbox. If it is selected, the filter criteria is applied with marker added to it. Else it is removed.
Queuing event on selecting checkbox: (getTable() method returns the binding of the RichTable)
FilterableQueryDescriptor queryDescriptor =
(FilterableQueryDescriptor)getTable().getFilterModel();
getTable().queueEvent(new QueryEvent(getTable(), queryDescriptor));
----------------------------------------------------------------------------------------------------------------------
Handling the query event:
FilterableQueryDescriptor fqd =
(FilterableQueryDescriptor)queryEvent.getDescriptor();
Iterator itr = null;
if (showOnlyToSubmitEntities != null && showOnlyToSubmitEntities) {
fqd.getFilterCriteria().put("marker", "(");
} else {
itr = fqd.getFilterCriteria().entrySet().iterator();
while (itr.hasNext()) {
if (((Map.Entry)itr.next()).getKey().equals("legend")) {
itr.remove();
}
}
}
ADFUtil.invokeEL(el, new Class[] { QueryEvent.class },
new Object[] { queryEvent });
To achieve this, I followed a simple approach of using filtering. Firstly I maintained a transient attribute in the entity which is a plain string and is updated on every new row creation or modification. I call that attribute a marker and the values are (N) for newly newly added ones and (M) for modified ones. On clicking the "Show only to be submitted entities"checkbox, I am populating a filter criteria saying marker startswith "(". Then queued the queryevent. This table has filtering enabled. So I also ensured that the existing filters are not disturbed. The "showOnlyToSubmitEntities" is boolean flag that preserves the selection of "Show only to be submitted entities" checkbox. If it is selected, the filter criteria is applied with marker added to it. Else it is removed.
Queuing event on selecting checkbox: (getTable() method returns the binding of the RichTable)
FilterableQueryDescriptor queryDescriptor =
(FilterableQueryDescriptor)getTable().getFilterModel();
getTable().queueEvent(new QueryEvent(getTable(), queryDescriptor));
----------------------------------------------------------------------------------------------------------------------
Handling the query event:
FilterableQueryDescriptor fqd =
(FilterableQueryDescriptor)queryEvent.getDescriptor();
Iterator itr = null;
if (showOnlyToSubmitEntities != null && showOnlyToSubmitEntities) {
fqd.getFilterCriteria().put("marker", "(");
} else {
itr = fqd.getFilterCriteria().entrySet().iterator();
while (itr.hasNext()) {
if (((Map.Entry)itr.next()).getKey().equals("legend")) {
itr.remove();
}
}
}
ADFUtil.invokeEL(el, new Class[] { QueryEvent.class },
new Object[] { queryEvent });