-
1. Re: implementing ModifiableDatamodel
nbelaevski Jul 16, 2009 5:32 AM (in response to baz)Hi,
You have to define property name by which to filter/sort at column level. Take a look at livedemo page source. -
2. Re: implementing ModifiableDatamodel
baz Jul 16, 2009 6:24 AM (in response to baz)Hello,
thanks for the quick answer.You have to define property name by which to filter/sort at column level
I suggest that the sortBy attribute should be used for that.
Our datatable sorts correct when it is backed by a normal list. And sorting is also available for the name columnsortBy="#{personTO.person.firstname} #{personTO.person.lastname}"
What exactly has to change in the datatable definition that the sort capability is available when our table is backed with a "Datamodel"?
In the reference doku and the example i can not find any attribute for propertyname:-(
Ciao, -
3. Re: implementing ModifiableDatamodel
baz Jul 20, 2009 10:27 AM (in response to baz)Hello,
this is what i have found out:
the sortBy Attribute of a rich:column serves two purposes.
1. If the datatable is backed by a normal list, the el-expression is used to access the object of the current row. With this information the table is sorted in memorysortBy="#{personTO.person.firstname}"
2. If a datamodel is supplied the sortBy attribute must be used to specify database colums for orderBy clause.sortBy="#{'person.firstname'}"
so, two new problems aroses:
1. How can i use the same facelet(snippet) which is used from pages where the table is backed by a datamodel and from other pages where the table is backed by a a list.
2. How can i order (in the db) with multiple columns (This is functioning when sorting in memory:sortBy="#{personTO.person.firstname} #{personTO.person.lastname}"
Ciao, -
4. Re: implementing ModifiableDatamodel
kukeltje Jul 20, 2009 10:44 AM (in response to baz)2: By implementing that in your model e.g. with the hibernate queryapi.
I think you can even achieve what you mention by 1 as well -
5. Re: implementing ModifiableDatamodel
baz Jul 20, 2009 10:50 AM (in response to baz)Thanks for your answer
2: By implementing that in your model e.g. with the hibernate queryapi.
It is possible also with JPA. You have to denote the columns separated by colums and parse this string in your code. In this way you are able to generate the correct orderBy ClauseI think you can even achieve what you mention by 1 as well
No. :-(
Because from the el (for inmemory sorting and filtering) i can not deduce the correct column names
I would suggest two propertys. One for inmemory sorting and the other for db backed ordering -
6. Re: implementing ModifiableDatamodel
kukeltje Jul 20, 2009 10:55 AM (in response to baz)1: Yes you can with something like:
public void modify(List filterFields, List<SortField2> sortFields) {
this.filterFields = new ArrayList();
for (int i = 0; i < filterFields.size(); i++) {
Expression expression = filterFields.get(i).getExpression();
String expressionStr = expression.getExpressionString();
if (!expression.isLiteralText()) {
expressionStr = expressionStr.replaceAll("[#|$]{1}\\{.*?\\.", "").replaceAll("\\}", "");
}
this.filterFields.add(expressionStr);
}
if (sortFields != null && !sortFields.isEmpty()) {
SortField2 sortField2 = sortFields.get(0);
log.debug("sortField expression: #0, order #1", sortField2.getExpression(), sortField2.getOrdering());
Expression expression = sortField2.getExpression();
String expressionStr = expression.getExpressionString();
if (!expression.isLiteralText()) {
expressionStr = expressionStr.replaceAll("[#|$]{1}\\{.*?\\.", "").replaceAll("\\}", "");
}
this.sortField = expressionStr;
Ordering ordering = sortField2.getOrdering();
if (ordering == Ordering.DESCENDING) {
this.descending = true;
}
else {
this.descending = false;
}
}
}
in your model -
7. Re: implementing ModifiableDatamodel
kukeltje Jul 20, 2009 10:55 AM (in response to baz)sorry, should have put [ c o d e ] tags around that
-
8. Re: implementing ModifiableDatamodel
baz Jul 20, 2009 11:10 AM (in response to baz)Thanks for the code. But this does not help.
How would you do this:
When sorting in memory you have to denote this: #{personTO.contractNumber}
But when ordering in db you have to write this: #{bpca.person.contractNumber}
Ciao, -
9. Re: implementing ModifiableDatamodel
kukeltje Jul 20, 2009 11:18 AM (in response to baz)Write the modify method in such a way that it knows how to expand 'personTo' to 'bpca.person' be creative... worked for me perfectly.
-
10. Re: implementing ModifiableDatamodel
kukeltje Jul 20, 2009 11:19 AM (in response to baz)keep in mind that within the modify method, the EL is not realy used as an el, but just as a string.