From: Chad B. <cwb...@us...> - 2008-03-27 20:33:07
|
User: cwbrandon Date: 08/03/27 13:33:11 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet PageableDataModel.java.vsl Log: add isEmpty method Revision Changes Path 1.2 +10 -0 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.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- PageableDataModel.java.vsl 27 Mar 2008 18:34:52 -0000 1.1 +++ PageableDataModel.java.vsl 27 Mar 2008 20:33:11 -0000 1.2 @@ -249,4 +249,14 @@ } this.sortAscending = sortAscending; } + + /** + * Provides ability to check whether or not the + * data is empty in JSTL (this this class wraps a collection + * when the collection is pageable). + */ + public boolean isEmpty() + { + return this.getRowCount() == 0; + } } \ No newline at end of file |
From: Chad B. <cwb...@us...> - 2008-03-31 22:48:58
|
User: cwbrandon Date: 08/03/31 15:48:58 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet PageableDataModel.java.vsl Log: fix setter name Revision Changes Path 1.3 +1 -1 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.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- PageableDataModel.java.vsl 27 Mar 2008 20:33:11 -0000 1.2 +++ PageableDataModel.java.vsl 31 Mar 2008 22:48:57 -0000 1.3 @@ -225,7 +225,7 @@ return this.sortProperty; } - public void setSortColumn(String sortProperty) + public void setSortProperty(String sortProperty) { if (sortProperty != null && !sortProperty.equals(this.sortProperty)) { |
From: Chad B. <cwb...@us...> - 2008-04-02 22:37:42
|
User: cwbrandon Date: 08/04/02 15:37:48 Modified: andromda-jsf2/src/main/resources/templates/jsf2/views/portlet view-table.xhtml.vsl andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet PageableDataModel.java.vsl Log: improvements to portlet table and pageable data model Revision Changes Path 1.7 +1 -1 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/views/portlet/view-table.xhtml.vsl Index: view-table.xhtml.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/views/portlet/view-table.xhtml.vsl,v retrieving revision 1.6 retrieving revision 1.7 diff -u -w -r1.6 -r1.7 --- view-table.xhtml.vsl 27 Mar 2008 23:39:18 -0000 1.6 +++ view-table.xhtml.vsl 2 Apr 2008 22:37:47 -0000 1.7 @@ -71,7 +71,7 @@ #end <h:column> <f:facet name="header"> - <t:commandSortHeader columnName="$columnName" arrow="true"> + <t:commandSortHeader columnName="$columnName" arrow="true" propertyName="$columnName"> <h:outputText value="#{messages['$table.getTableColumnMessageKey($columnName)']}"/> </t:commandSortHeader> </f:facet> 1.4 +25 -38 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.3 retrieving revision 1.4 diff -u -w -r1.3 -r1.4 --- PageableDataModel.java.vsl 31 Mar 2008 22:48:57 -0000 1.3 +++ PageableDataModel.java.vsl 2 Apr 2008 22:37:48 -0000 1.4 @@ -71,7 +71,7 @@ */ public $paginationResultClassName getPage() { - if (this.page == null) + if (this.page == null || this.forcePageRefresh) { this.page = this.getPage( @@ -79,6 +79,7 @@ this.pageSize, this.sortProperty, this.sortAscending); + this.forcePageRefresh = false; } return this.page; } @@ -98,6 +99,21 @@ return pageNumber; } + private javax.faces.component.UIData owner; + + /** + * Sets the UIData owner of this pageable data model. + */ + public void setOwner(javax.faces.component.UIData owner) + { + this.owner = owner; + } + + private int getFirst() + { + return this.owner != null ? this.owner.getFirst() : -1; + } + /** * Keeps track of the previous row index (so that we don't search more than we need) */ @@ -120,15 +136,14 @@ 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 && + (first == -1 || (this.rowIndex >= first && this.rowIndex <= (first + this.pageSize))); + } + page = this.getPage(); this.previousRowIndex = this.rowIndex; - // - only search if the listIndex is 0 (that is its a multiple of the page size) - page = - this.getPage( - this.getPageNumber(), - pageSize, - this.sortProperty, - this.sortAscending); - this.forcePageRefresh = false; } Object rowData = null; if (page.getData() != null) @@ -188,34 +203,6 @@ String sortProperty, boolean sortAscending); - /* Used by ADF - public Object getRowKey() - { - return isRowAvailable() ? String.valueOf(getRowIndex()) : null; - } - - public void setRowKey(Object key) - { - setRowIndex(this.toRowIndex((String)key)); - } - - /** - * Creates a row index for the given row key - * - private int toRowIndex(String rowKey) - { - int rowIndex = -1; - try - { - rowIndex = Integer.parseInt(rowKey); - } - catch (NumberFormatException exception) - { - // - ignore - } - return rowIndex; - }*/ - private boolean forcePageRefresh; private String sortProperty; @@ -243,7 +230,7 @@ public void setSortAscending(boolean sortAscending) { - if (sortAscending != sortAscending) + if (this.sortAscending != sortAscending) { this.forcePageRefresh = true; } |
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; } /** |
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 && |
From: Chad B. <cwb...@us...> - 2008-04-03 19:56:38
|
User: cwbrandon Date: 08/04/03 12:56:42 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet PageableDataModel.java.vsl Log: Reset the owner component's first value when the data model is created Revision Changes Path 1.7 +27 -8 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.6 retrieving revision 1.7 diff -u -w -r1.6 -r1.7 --- PageableDataModel.java.vsl 3 Apr 2008 16:23:47 -0000 1.6 +++ PageableDataModel.java.vsl 3 Apr 2008 19:56:41 -0000 1.7 @@ -71,6 +71,7 @@ */ public $paginationResultClassName getPage() { + this.initialize(); if (this.page == null || this.forcePageRefresh) { this.page = @@ -84,7 +85,7 @@ return this.page; } - private int getPageNumber() + protected int getPageNumber() { int pageNumber = 1; int rowIndex = this.rowIndex + 1; @@ -104,7 +105,7 @@ * * @return the first record number. */ - private int getFirst() + protected int getFirst() { final javax.faces.component.UIData owner = this.findOwner(); return owner != null ? owner.getFirst() : -1; @@ -120,14 +121,27 @@ private static final String SORT_ASCENDING = "sortAscending"; /** + * When this pageable data model is created a reset is required (i.e. + * setting first to 0 on the owner and resetting the rowIndex to 0 + */ + private boolean resetRequired = true; + + /** * Finds the component that "owns" this data model. * * @return the owne component (i.e. table). */ - private javax.faces.component.UIData findOwner() + protected javax.faces.component.UIData findOwner() + { + return (javax.faces.component.UIData)findOwner(javax.faces.context.FacesContext.getCurrentInstance().getViewRoot()); + } + + /** + * Performs any required initialization. + */ + protected void initialize() { - final javax.faces.component.UIData owner = - (javax.faces.component.UIData)findOwner(javax.faces.context.FacesContext.getCurrentInstance().getViewRoot()); + final javax.faces.component.UIData owner = this.findOwner(); if (owner != null) { final Object sortProperty = this.getProperty(owner, SORT_PROPERTY); @@ -140,11 +154,16 @@ { this.setSortAscending((Boolean)sortAscending); } + if (this.resetRequired) + { + owner.setFirst(0); + this.setRowIndex(0); + this.resetRequired = false; + } } - return owner; } - private Object getProperty(final javax.faces.component.UIData owner, String name) + protected Object getProperty(final javax.faces.component.UIData owner, String name) { Object property = null; if (owner != null) @@ -170,7 +189,7 @@ * @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) + protected javax.faces.component.UIComponent findOwner(final javax.faces.component.UIComponent component) { javax.faces.component.UIComponent owner = null; if (component instanceof javax.faces.component.UIData) |
From: Chad B. <cwb...@us...> - 2008-04-08 01:22:14
|
User: cwbrandon Date: 08/04/07 18:20:28 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils PageableDataModel.java.vsl JsfUtils.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/flow ViewPopulator.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet PageableDataModel.java.vsl Log: enable form serialization for portlets Revision Changes Path 1.2 +1 -0 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/PageableDataModel.java.vsl Index: PageableDataModel.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/PageableDataModel.java.vsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- PageableDataModel.java.vsl 27 Mar 2008 18:34:47 -0000 1.1 +++ PageableDataModel.java.vsl 8 Apr 2008 01:20:28 -0000 1.2 @@ -16,6 +16,7 @@ */ public abstract class $className extends org.apache.myfaces.trinidad.model.CollectionModel + implements java.io.Serializable { private int pageSize; private int rowIndex; 1.3 +23 -19 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/JsfUtils.java.vsl Index: JsfUtils.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/JsfUtils.java.vsl,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- JsfUtils.java.vsl 25 Feb 2008 14:28:51 -0000 1.2 +++ JsfUtils.java.vsl 8 Apr 2008 01:20:28 -0000 1.3 @@ -4,6 +4,8 @@ #end import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * Utilities used within the JSF Cartridge @@ -12,6 +14,8 @@ */ public class $className { + private static Log logger = LogFactory.getLog(JsfUtils.class); + /** * The location of the temporary directoy used the JSF cartridge. */ @@ -44,7 +48,7 @@ * @param session the session from which to create the serialization path. * @param form the form to serialize. */ - public static void serializeForm(final javax.servlet.http.HttpSession session, final Object form) + public static void serializeForm(final $jsfUtils.sessionClassName session, final Object form) { java.io.ObjectOutputStream objectStream = null; try @@ -61,7 +65,7 @@ } catch (final Exception exception) { - // - ignore if we couldn't serialize the form. + logger.warn(exception); } finally { @@ -85,7 +89,7 @@ * @return the serialized form. * @throws Exception */ - public static Object getSerializedForm(final javax.servlet.http.HttpSession session) + public static Object getSerializedForm(final $jsfUtils.sessionClassName session) { Object form = null; java.io.ObjectInputStream objectStream = null; @@ -121,7 +125,7 @@ * * @param session the session for which to remove the serialized form. */ - public static void deleteSerializedForm(final javax.servlet.http.HttpSession session) + public static void deleteSerializedForm(final $jsfUtils.sessionClassName session) { final java.io.File serializationFile = new java.io.File(getFormSerializationPath(session)); @@ -143,7 +147,7 @@ * @param session the session containing the unique id in which to create the path. * @return the path to which serialization occurs. */ - private static String getFormSerializationPath(final javax.servlet.http.HttpSession session) + private static String getFormSerializationPath(final $jsfUtils.sessionClassName session) { return TEMPORARY_DIRECTORY + session.getId() + SERIALIZED_FORM_FILE_NAME; } 1.5 +8 -1 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/ViewPopulator.java.vsl Index: ViewPopulator.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/ViewPopulator.java.vsl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -w -r1.4 -r1.5 --- ViewPopulator.java.vsl 21 Mar 2008 16:07:12 -0000 1.4 +++ ViewPopulator.java.vsl 8 Apr 2008 01:20:28 -0000 1.5 @@ -139,6 +139,13 @@ { form = session.getAttribute("$view.formKey"); } +#if ($formSerialization) + // - if the form is still null, see if we can get it from a serialized state + if (form == null) + { + form = ${managedBeansPackage}.JsfUtils.getSerializedForm(session); + } +#end } else { @@ -164,7 +171,7 @@ #end } #end -#if ($standalone && $formSerialization) +#if ($formSerialization) // - serialize the form if (form != null) { 1.8 +1 -0 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.7 retrieving revision 1.8 diff -u -w -r1.7 -r1.8 --- PageableDataModel.java.vsl 3 Apr 2008 19:56:41 -0000 1.7 +++ PageableDataModel.java.vsl 8 Apr 2008 01:20:28 -0000 1.8 @@ -10,6 +10,7 @@ */ public abstract class $className extends javax.faces.model.DataModel + implements java.io.Serializable { private int pageSize; private int rowIndex; |