You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by mi...@apache.org on 2005/07/08 01:00:40 UTC

cvs commit: jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/model/simple SimpleTableStateAdaptor.java SimpleTableState.java SimpleTableSortingState.java SimpleTablePagingState.java

mindbridge    2005/07/07 16:00:40

  Modified:    contrib/src/java/org/apache/tapestry/contrib/table/components
                        TableView.jwc FormTable.jwc TablePages.jwc
                        TableColumns.jwc TableRows.jwc Table.jwc
                        TableFormPages.jwc TableValues.jwc TableView.java
                        TableMessages.java TableStrings.properties
               contrib/src/java/org/apache/tapestry/contrib/table/model/simple
                        SimpleTableState.java SimpleTableSortingState.java
                        SimpleTablePagingState.java
  Added:       contrib/src/java/org/apache/tapestry/contrib/table/model/simple
                        SimpleTableStateAdaptor.java
  Log:
  Allowing the user of Table to choose whether to persist the state in session (as before) or on the client.
  
  Revision  Changes    Path
  1.13      +11 -0     jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableView.jwc
  
  Index: TableView.jwc
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableView.jwc,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TableView.jwc	25 Jun 2005 04:55:23 -0000	1.12
  +++ TableView.jwc	7 Jul 2005 23:00:39 -0000	1.13
  @@ -96,6 +96,15 @@
           </description>
       </parameter>
       
  +    <parameter name="persist" default-value="session" default-binding="literal"> 
  +        <description>
  +            Defines how the table state (paging and sorting) will be persisted
  +            if no tableSessionStoreManager is defined.
  +            The possible values are 'session' (the default), 'client', 'client:page', 
  +            and 'client:app'.
  +        </description>
  +    </parameter>
  +    
       <parameter name="element" default-value="table" default-binding="literal"> 
           <description>
               The tag with which the component will be inserted in the generated content.
  @@ -109,6 +118,8 @@
       </parameter>
       
       <property name="sessionState" persist="session"/>
  +    <property name="clientState" persist="client:page"/>
  +    <property name="clientAppState" persist="client:app"/>
       
       <component id="table" type="Any" inherit-informal-parameters="yes">
           <binding name="element" value="ognl:element"/>
  
  
  
  1.7       +10 -0     jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/FormTable.jwc
  
  Index: FormTable.jwc
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/FormTable.jwc,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FormTable.jwc	25 Jun 2005 04:55:23 -0000	1.6
  +++ FormTable.jwc	7 Jul 2005 23:00:39 -0000	1.7
  @@ -112,6 +112,15 @@
           </description>
       </parameter>
       
  +    <parameter name="persist" default-value="'session'"> 
  +        <description>
  +            Defines how the table state (paging and sorting) will be persisted
  +            if no tableSessionStoreManager is defined.
  +            The possible values are 'session' (the default), 'client', 'client:page', 
  +            and 'client:app'.
  +        </description>
  +    </parameter>
  +    
       <parameter name="columnSettingsContainer"
           type="org.apache.tapestry.IComponent"
           required="no"
  @@ -226,6 +235,7 @@
   		<inherited-binding name="initialSortOrder" parameter-name="initialSortOrder"/>
   		<inherited-binding name="tableSessionStateManager" parameter-name="tableSessionStateManager"/>
   		<inherited-binding name="tableSessionStoreManager" parameter-name="tableSessionStoreManager"/>
  +		<inherited-binding name="persist" parameter-name="persist"/>
   		<inherited-binding name="columnSettingsContainer" parameter-name="columnSettingsContainer"/>
   		<static-binding name="element">div</static-binding>
   	</component>
  
  
  
  1.5       +1 -1      jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TablePages.jwc
  
  Index: TablePages.jwc
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TablePages.jwc,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TablePages.jwc	25 Jun 2005 04:55:23 -0000	1.4
  +++ TablePages.jwc	7 Jul 2005 23:00:39 -0000	1.5
  @@ -47,7 +47,7 @@
   	<component id="condOther" type="Else">
   	</component>
     
  -	<component id="iterPage" type="Foreach">
  +	<component id="iterPage" type="For">
   		<binding name="source" expression="pageList"/>
   		<binding name="value" expression="displayPage"/>
   	</component>
  
  
  
  1.9       +1 -1      jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableColumns.jwc
  
  Index: TableColumns.jwc
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableColumns.jwc,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TableColumns.jwc	23 Jun 2005 14:13:25 -0000	1.8
  +++ TableColumns.jwc	7 Jul 2005 23:00:39 -0000	1.9
  @@ -47,7 +47,7 @@
           <description>The CSS class of the table columns</description>
       </parameter>
       
  -	<component id="iterColumns" type="Foreach">
  +	<component id="iterColumns" type="For">
   		<binding name="source" value="ognl:tableColumnIterator"/>
   		<binding name="value" value="ognl:tableColumn"/>
   	</component>
  
  
  
  1.5       +1 -1      jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableRows.jwc
  
  Index: TableRows.jwc
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableRows.jwc,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TableRows.jwc	9 Jan 2005 19:57:00 -0000	1.4
  +++ TableRows.jwc	7 Jul 2005 23:00:39 -0000	1.5
  @@ -42,7 +42,7 @@
           <description>The tag to use to wrap the rows in, 'tr' by default.</description>
       </parameter>
   
  -	<component id="iterRows" type="Foreach">
  +	<component id="iterRows" type="For">
   		<binding name="source" expression="tableRowsIterator"/>
   		<binding name="value" expression="tableRow"/>
   	</component>
  
  
  
  1.7       +10 -0     jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/Table.jwc
  
  Index: Table.jwc
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/Table.jwc,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Table.jwc	25 Jun 2005 04:55:23 -0000	1.6
  +++ Table.jwc	7 Jul 2005 23:00:39 -0000	1.7
  @@ -112,6 +112,15 @@
           </description>
       </parameter>
       
  +    <parameter name="persist" default-value="'session'"> 
  +        <description>
  +            Defines how the table state (paging and sorting) will be persisted
  +            if no tableSessionStoreManager is defined.
  +            The possible values are 'session' (the default), 'client', 'client:page', 
  +            and 'client:app'.
  +        </description>
  +    </parameter>
  +    
       <parameter name="columnSettingsContainer"
           type="org.apache.tapestry.IComponent"
           required="no"
  @@ -215,6 +224,7 @@
   		<inherited-binding name="initialSortOrder" parameter-name="initialSortOrder"/>
   		<inherited-binding name="tableSessionStateManager" parameter-name="tableSessionStateManager"/>
   		<inherited-binding name="tableSessionStoreManager" parameter-name="tableSessionStoreManager"/>
  +		<inherited-binding name="persist" parameter-name="persist"/>
   		<inherited-binding name="columnSettingsContainer" parameter-name="columnSettingsContainer"/>
   		<static-binding name="element">div</static-binding>
   	</component>
  
  
  
  1.5       +1 -1      jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableFormPages.jwc
  
  Index: TableFormPages.jwc
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableFormPages.jwc,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TableFormPages.jwc	25 Jun 2005 04:55:23 -0000	1.4
  +++ TableFormPages.jwc	7 Jul 2005 23:00:39 -0000	1.5
  @@ -64,7 +64,7 @@
   	<component id="condOther" type="Else">
   	</component>
     
  -	<component id="iterPage" type="Foreach">
  +	<component id="iterPage" type="For">
   		<binding name="source" expression="pageList"/>
   		<binding name="value" expression="displayPage"/>
   	</component>
  
  
  
  1.9       +1 -1      jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableValues.jwc
  
  Index: TableValues.jwc
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableValues.jwc,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TableValues.jwc	23 Jun 2005 14:13:25 -0000	1.8
  +++ TableValues.jwc	7 Jul 2005 23:00:39 -0000	1.9
  @@ -40,7 +40,7 @@
           <description>The CSS class of the table values</description>
       </parameter>
       
  -	<component id="iterColumns" type="Foreach">
  +	<component id="iterColumns" type="For">
   		<binding name="source" value="ognl:tableColumnIterator"/>
   		<binding name="value" value="ognl:tableColumn"/>
   	</component>
  
  
  
  1.11      +26 -3     jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableView.java
  
  Index: TableView.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableView.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TableView.java	25 Jun 2005 04:55:23 -0000	1.10
  +++ TableView.java	7 Jul 2005 23:00:39 -0000	1.11
  @@ -134,11 +134,21 @@
   
       public abstract int getPageSize();
   
  +    public abstract String getPersist();
  +
       // enhanced property methods
       public abstract Serializable getSessionState();
   
       public abstract void setSessionState(Serializable sessionState);
   
  +    public abstract Serializable getClientState();
  +
  +    public abstract void setClientState(Serializable sessionState);
  +
  +    public abstract Serializable getClientAppState();
  +
  +    public abstract void setClientAppState(Serializable sessionState);
  +
       /**
        * The component constructor. Invokes the component member initializations.
        */
  @@ -414,7 +424,13 @@
           ITableSessionStoreManager objManager = getTableSessionStoreManager();
           if (objManager != null)
               return objManager.loadState(getPage().getRequestCycle());
  -        return getSessionState();
  +    	String strPersist = getPersist();
  +    	if (strPersist.equals("client") || strPersist.equals("client:page"))
  +    		return getClientState();
  +    	else if (strPersist.equals("client:app"))
  +    		return getClientAppState();
  +    	else
  +    		return getSessionState();
       }
   
       /**
  @@ -428,8 +444,15 @@
           ITableSessionStoreManager objManager = getTableSessionStoreManager();
           if (objManager != null)
               objManager.saveState(getPage().getRequestCycle(), objState);
  -        else
  -            setSessionState(objState);
  +        else {
  +        	String strPersist = getPersist();
  +        	if (strPersist.equals("client") || strPersist.equals("client:page"))
  +        		setClientState(objState);
  +        	else if (strPersist.equals("client:app"))
  +        		setClientAppState(objState);
  +        	else 
  +        		setSessionState(objState);
  +        }
       }
   
       /**
  
  
  
  1.5       +5 -1      jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableMessages.java
  
  Index: TableMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableMessages.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TableMessages.java	13 May 2005 13:21:06 -0000	1.4
  +++ TableMessages.java	7 Jul 2005 23:00:39 -0000	1.5
  @@ -22,7 +22,7 @@
    * @author Howard M. Lewis Ship
    * @since 4.0
    */
  -class TableMessages
  +public class TableMessages
   {
       protected static MessageFormatter _formatter = new MessageFormatter(TableMessages.class,
               "TableStrings");
  @@ -53,4 +53,8 @@
       {
           return _formatter.format("columns-only-please", component.getExtendedId());
       }
  +    
  +    public static String invalidTableStateFormat(String value) {
  +    	return _formatter.format("invalid-table-state-format", value);
  +    }
   }
  \ No newline at end of file
  
  
  
  1.4       +1 -0      jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableStrings.properties
  
  Index: TableStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/components/TableStrings.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TableStrings.properties	6 Jan 2005 02:17:17 -0000	1.3
  +++ TableStrings.properties	7 Jul 2005 23:00:39 -0000	1.4
  @@ -17,3 +17,4 @@
   not-a-column=The expression '{1}' in the 'columns' parameter of component {0} does not evaluate to an ITableColumn
   invalid-table-source=The source parameter of component {0} is of type {1}, but must be of type Object[], Collection, Iterator, or IBasicTableModel
   invalid-table-columns=The columns parameter of component {0} is of type {1}, but must be of type String, ITableColumnModel, ITableColumn[], List, or Iterator
  +invalid-table-state-format=Invalid format of the table state: {0}
  
  
  
  1.6       +5 -0      jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/model/simple/SimpleTableState.java
  
  Index: SimpleTableState.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/model/simple/SimpleTableState.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SimpleTableState.java	25 Jun 2005 04:57:07 -0000	1.5
  +++ SimpleTableState.java	7 Jul 2005 23:00:40 -0000	1.6
  @@ -44,6 +44,11 @@
   		m_objSortingState = objSortingState;
   	}
   
  +	public SimpleTableState(int nPageSize, int nCurrentPage, String strSortColumn, boolean bSortOrder) {
  +		this(new SimpleTablePagingState(nPageSize, nCurrentPage), 
  +				new SimpleTableSortingState(strSortColumn, bSortOrder));
  +	}
  +	
   	/**
   	 * Returns the pagingState.
   	 * @return ITablePagingState
  
  
  
  1.6       +7 -3      jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/model/simple/SimpleTableSortingState.java
  
  Index: SimpleTableSortingState.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/model/simple/SimpleTableSortingState.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SimpleTableSortingState.java	25 Jun 2005 04:57:07 -0000	1.5
  +++ SimpleTableSortingState.java	7 Jul 2005 23:00:40 -0000	1.6
  @@ -34,11 +34,15 @@
   
   	public SimpleTableSortingState()
   	{
  -		m_strSortColumn = null; // no sorting
  -		m_bSortOrder = ITableSortingState.SORT_ASCENDING;
  -		// irrelevant, but anyway
  +		this(null, ITableSortingState.SORT_ASCENDING); 
   	}
   
  +	public SimpleTableSortingState(String strSortColumn, boolean bSortOrder)
  +	{
  +		m_strSortColumn = strSortColumn; 
  +		m_bSortOrder = bSortOrder;
  +	}
  +	
   	/**
   	 * Returns the SortOrder.
   	 * @return boolean
  
  
  
  1.6       +6 -2      jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/model/simple/SimpleTablePagingState.java
  
  Index: SimpleTablePagingState.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/model/simple/SimpleTablePagingState.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SimpleTablePagingState.java	25 Jun 2005 04:57:07 -0000	1.5
  +++ SimpleTablePagingState.java	7 Jul 2005 23:00:40 -0000	1.6
  @@ -35,10 +35,14 @@
   
       public SimpleTablePagingState()
       {
  -        m_nPageSize = DEFAULT_PAGE_SIZE;
  -        m_nCurrentPage = 0;
  +        this(DEFAULT_PAGE_SIZE, 0);
       }
   
  +    public SimpleTablePagingState(int nPageSize, int nCurrentPage) {
  +        m_nPageSize = nPageSize;
  +        m_nCurrentPage = nCurrentPage;
  +    }
  +    
       /**
        * Returns the pageSize.
        * @return int
  
  
  
  1.1                  jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/table/model/simple/SimpleTableStateAdaptor.java
  
  Index: SimpleTableStateAdaptor.java
  ===================================================================
  /*
   * Created on Jul 6, 2005
   */
  package org.apache.tapestry.contrib.table.model.simple;
  
  
  import java.io.IOException;
  import java.util.StringTokenizer;
  
  import org.apache.tapestry.contrib.table.components.TableMessages;
  import org.apache.tapestry.services.DataSqueezer;
  import org.apache.tapestry.util.io.ISqueezeAdaptor;
  
  public class SimpleTableStateAdaptor implements ISqueezeAdaptor {
  
      private static final String PREFIX = "t";
  	
  	public String squeeze(DataSqueezer squeezer, Object data)
  			throws IOException {
  		SimpleTableState objState = (SimpleTableState) data;
  		
  		StringBuffer buf = new StringBuffer();
  		buf.append(objState.getPagingState().getPageSize());
  		buf.append(":");
  		buf.append(objState.getPagingState().getCurrentPage());
  		buf.append(":");
  		String strSortColumn = objState.getSortingState().getSortColumn();
  		if (strSortColumn == null)
  			strSortColumn = "";
  		buf.append(strSortColumn);
  		buf.append(":");
  		buf.append(objState.getSortingState().getSortOrder() ? 'T' : 'F');
  		
  		return buf.toString();
  	}
  
  	public Object unsqueeze(DataSqueezer squeezer, String string)
  			throws IOException {
  		StringTokenizer strTok = new StringTokenizer(string, ":");
  		if (strTok.countTokens() != 4)
  			throw new IOException(TableMessages.invalidTableStateFormat(string));
  		int nPageSize = Integer.parseInt(strTok.nextToken());
  		int nCurrentPage = Integer.parseInt(strTok.nextToken());
  		String strSortColumn = strTok.nextToken();
  		if (strSortColumn.equals(""))
  			strSortColumn = null;
  		boolean bSortOrder = strTok.nextToken().equals("T");
  		
  		return new SimpleTableState(nPageSize, nCurrentPage, strSortColumn, bSortOrder);
  	}
  
  	public void register(DataSqueezer squeezer) {
  		squeezer.register(PREFIX, SimpleTableState.class, this);
  	}
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org