|
From: Chad B. <cwb...@us...> - 2008-04-03 16:23:47
|
User: cwbrandon
Date: 08/04/03 09:23:47
Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet
PageableDataModel.java.vsl
Log:
pull the sort properties from the owner component
Revision Changes Path
1.6 +47 -2 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet/PageableDataModel.java.vsl
Index: PageableDataModel.java.vsl
===================================================================
RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet/PageableDataModel.java.vsl,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -r1.5 -r1.6
--- PageableDataModel.java.vsl 2 Apr 2008 23:11:04 -0000 1.5
+++ PageableDataModel.java.vsl 3 Apr 2008 16:23:47 -0000 1.6
@@ -115,9 +115,53 @@
*
* @return the owne component (i.e. table).
*/
+ private static final String SORT_PROPERTY = "sortProperty";
+
+ private static final String SORT_ASCENDING = "sortAscending";
+
+ /**
+ * Finds the component that "owns" this data model.
+ *
+ * @return the owne component (i.e. table).
+ */
private javax.faces.component.UIData findOwner()
{
- return (javax.faces.component.UIData)findOwner(javax.faces.context.FacesContext.getCurrentInstance().getViewRoot());
+ final javax.faces.component.UIData owner =
+ (javax.faces.component.UIData)findOwner(javax.faces.context.FacesContext.getCurrentInstance().getViewRoot());
+ if (owner != null)
+ {
+ final Object sortProperty = this.getProperty(owner, SORT_PROPERTY);
+ if (sortProperty instanceof String)
+ {
+ this.setSortProperty((String)sortProperty);
+ }
+ final Object sortAscending = this.getProperty(owner, SORT_ASCENDING);
+ if (sortAscending instanceof Boolean)
+ {
+ this.setSortAscending((Boolean)sortAscending);
+ }
+ }
+ return owner;
+ }
+
+ private Object getProperty(final javax.faces.component.UIData owner, String name)
+ {
+ Object property = null;
+ if (owner != null)
+ {
+ try
+ {
+ if (org.apache.commons.beanutils.PropertyUtils.isReadable(owner, name))
+ {
+ property = org.apache.commons.beanutils.PropertyUtils.getProperty(owner, name);
+ }
+ }
+ catch (Exception ex)
+ {
+ // - ignore if not available
+ }
+ }
+ return property;
}
/**
@@ -170,11 +214,12 @@
throw new IllegalArgumentException("Invalid rowIndex: " + rowIndex + "; not within page");
}
+ // - we call getFirst() here to populate any 'owner' properties before the forcePageRefresh check is made
+ final int first = this.getFirst();
// don't perform any new operations if the same index is used over again
final int listIndex = this.rowIndex % this.pageSize;
if (this.forcePageRefresh || listIndex == 0 && this.previousRowIndex != this.rowIndex)
{
- final int first = this.getFirst();
if (!this.forcePageRefresh)
{
this.forcePageRefresh = this.previousRowIndex != this.rowIndex &&
|