From: Chad B. <cwb...@us...> - 2008-04-02 23:14:45
|
User: cwbrandon Date: 08/04/02 16:11:04 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet PageableDataModel.java.vsl Log: find the owner component instead of setting it Revision Changes Path 1.5 +44 -6 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.4 retrieving revision 1.5 diff -u -w -r1.4 -r1.5 --- PageableDataModel.java.vsl 2 Apr 2008 22:37:48 -0000 1.4 +++ PageableDataModel.java.vsl 2 Apr 2008 23:11:04 -0000 1.5 @@ -99,19 +99,57 @@ return pageNumber; } - private javax.faces.component.UIData owner; + /** + * Gets the number of the first record. + * + * @return the first record number. + */ + private int getFirst() + { + final javax.faces.component.UIData owner = this.findOwner(); + return owner != null ? owner.getFirst() : -1; + } /** - * Sets the UIData owner of this pageable data model. + * Finds the component that "owns" this data model. + * + * @return the owne component (i.e. table). */ - public void setOwner(javax.faces.component.UIData owner) + private javax.faces.component.UIData findOwner() { - this.owner = owner; + return (javax.faces.component.UIData)findOwner(javax.faces.context.FacesContext.getCurrentInstance().getViewRoot()); } - private int getFirst() + /** + * Finds the component that "owns" this data model. + * + * @param component the component to start the search with. + * @return the owne component (i.e. table). + */ + private javax.faces.component.UIComponent findOwner(final javax.faces.component.UIComponent component) + { + javax.faces.component.UIComponent owner = null; + if (component instanceof javax.faces.component.UIData) { - return this.owner != null ? this.owner.getFirst() : -1; + final javax.faces.component.UIData uiData = (javax.faces.component.UIData)component; + if (this.equals(uiData.getValue())) + { + owner = component; + } + } + if (owner == null && component != null) + { + for (final java.util.Iterator iterator = component.getFacetsAndChildren(); iterator.hasNext();) + { + final javax.faces.component.UIComponent childComponent = (javax.faces.component.UIComponent)iterator.next(); + owner = this.findOwner(childComponent); + if (owner != null) + { + break; + } + } + } + return owner; } /** |