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 2003/09/06 16:06:51 UTC

cvs commit: jakarta-tapestry/examples/Workbench/src/org/apache/tapestry/workbench/table LocaleList.java

mindbridge    2003/09/06 07:06:51

  Modified:    examples/Workbench/context/WEB-INF LocaleList.jwc
                        LocaleList.html
               examples/Workbench/src/org/apache/tapestry/workbench/table
                        LocaleList.java
  Log:
  Modifying the Table example in the workbench to take advantage 
  of the form-specific Table components.
  
  Revision  Changes    Path
  1.4       +11 -5     jakarta-tapestry/examples/Workbench/context/WEB-INF/LocaleList.jwc
  
  Index: LocaleList.jwc
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/examples/Workbench/context/WEB-INF/LocaleList.jwc,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocaleList.jwc	1 Jun 2003 05:05:03 -0000	1.3
  +++ LocaleList.jwc	6 Sep 2003 14:06:51 -0000	1.4
  @@ -14,16 +14,22 @@
   
       <bean name="rowClass" class="org.apache.tapestry.bean.EvenOdd"/>
   
  +	<property-specification name="currentLocale" type="java.util.Locale"/>
  +	
  +	<property-specification name="selectedLocales" type="java.util.Set" 
  +		persistent="yes" initial-value="new java.util.HashSet()"/>
  +
   	<component id="form" type="Form">
  -		<binding name="listener" expression="listeners.formSubmit"/>
  +		<!--binding name="listener" expression="listeners.formSubmit"/-->
   	</component>
   
   	<component id="checkbox" type="Checkbox">
   		<binding name="selected" expression="checkboxSelected"/>
   	</component>
   
  -	<component id="submit" type="Submit">
  +	<component id="submitButton" type="Submit">
   		<static-binding name="label" value="Select locales"/>
  +		<binding name="listener" expression="listeners.selectLocales"/>
   	</component>
   
   	<component id="tableView" type="contrib:TableView">
  @@ -33,8 +39,8 @@
   
   	<component id="tableColumns" type="contrib:TableColumns"/>
   
  -	<component id="tableRows" type="contrib:TableRows">
  -		<binding name="value" expression="currentLocale"/>
  +	<component id="tableRows" type="contrib:TableFormRows">
  +		<binding name="row" expression="currentLocale"/>
   		<binding name="class" expression="beans.rowClass.next"/>
   	</component>
   
  
  
  
  1.2       +3 -3      jakarta-tapestry/examples/Workbench/context/WEB-INF/LocaleList.html
  
  Index: LocaleList.html
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/examples/Workbench/context/WEB-INF/LocaleList.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocaleList.html	5 Mar 2003 23:08:20 -0000	1.1
  +++ LocaleList.html	6 Sep 2003 14:06:51 -0000	1.2
  @@ -10,7 +10,7 @@
   	     and lay them out in our own way. -->
   
   	<table jwcid="tableView" width="100%">
  -		<span jwcid="tablePages@contrib:TablePages"/>
  +		<span jwcid="tablePages@contrib:TableFormPages"/>
   		
   		<tr>
   			<td></td>
  @@ -23,7 +23,7 @@
   		</tr>
   	</table>
   
  -	<span jwcid="submit"/>
  +	<span jwcid="submitButton"/>
   
   </form>
   
  
  
  
  1.2       +47 -72    jakarta-tapestry/examples/Workbench/src/org/apache/tapestry/workbench/table/LocaleList.java
  
  Index: LocaleList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/examples/Workbench/src/org/apache/tapestry/workbench/table/LocaleList.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocaleList.java	5 Mar 2003 23:08:26 -0000	1.1
  +++ LocaleList.java	6 Sep 2003 14:06:51 -0000	1.2
  @@ -56,6 +56,7 @@
   package org.apache.tapestry.workbench.table;
   
   import java.util.HashSet;
  +import java.util.Iterator;
   import java.util.Locale;
   import java.util.Set;
   
  @@ -65,51 +66,33 @@
   import org.apache.tapestry.contrib.table.model.ITableColumnModel;
   import org.apache.tapestry.contrib.table.model.ITableDataModel;
   import org.apache.tapestry.contrib.table.model.ITableModel;
  +import org.apache.tapestry.contrib.table.model.ITableRendererSource;
   import org.apache.tapestry.contrib.table.model.ITableSessionStateManager;
  +import org.apache.tapestry.contrib.table.model.ognl.ExpressionTableColumn;
   import org.apache.tapestry.contrib.table.model.ognl.ExpressionTableColumnModel;
   import org.apache.tapestry.contrib.table.model.simple.SimpleListTableDataModel;
  +import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumnFormRendererSource;
   import org.apache.tapestry.contrib.table.model.simple.SimpleTableSessionStateManager;
   import org.apache.tapestry.contrib.table.model.simple.SimpleTableState;
  -import org.apache.tapestry.event.PageDetachListener;
  -import org.apache.tapestry.event.PageEvent;
   
   /**
    * @author mindbridge
    *
    */
  -public class LocaleList extends BaseComponent implements PageDetachListener
  +public abstract class LocaleList extends BaseComponent
   {
       // immutable values
   	private ITableSessionStateManager m_objTableSessionStateManager;
  -    
  -    // bindings
  -    private IBinding m_objLocaleSelectionListenerBinding;
  -
  -    // temporary    
  -    private Locale m_objCurrentLocale;
  -    
  -    // transient
  -    private Set m_setSelectedLocales;
  -
  -	public LocaleList()
  -	{
  -		// an initialization done only once for each pooled page instance
  -		initTableSessionStateManager();
  -        m_setSelectedLocales = new HashSet();
  -	}
   
       /**
  -     * @see org.apache.tapestry.event.PageDetachListener#pageDetached(PageEvent)
  +     * @see org.apache.tapestry.AbstractComponent#finishLoad()
        */
  -    public void pageDetached(PageEvent event)
  +    protected void finishLoad()
       {
  -        init();
  -    }
  -
  -    private void init() {
  -        m_setSelectedLocales.clear();
  +        super.finishLoad();
  +        initTableSessionStateManager();
       }
  -
  +    
   	/**
   	 * Method initTableSessionStateManager.
   	 * Creates the Table Session State Manager, and thus determines what part
  @@ -138,6 +121,21 @@
                       },
   				true);
   
  +
  +        // Modify the columns to render headers designed for use in a form. 
  +        // These headers ensure that the form is submitted when clicking on them
  +        // and sorting by the column so that current form selections are preserved.
  +        // Skip this if the table is not used in a form or you do not need 
  +        // that behaviour.  
  +        // This is usually used in conjunction with the TableFormPages and
  +        // the TableFormRows components.
  +        ITableRendererSource objRendererSource = new SimpleTableColumnFormRendererSource();
  +        for (Iterator it = objColumnModel.getColumns(); it.hasNext(); ) {
  +            ExpressionTableColumn objColumn = (ExpressionTableColumn) it.next();
  +            objColumn.setColumnRendererSource(objRendererSource);
  +        }
  +
  +
   		// Here we make a choice as to how the table would operate: 
   		//
   		// We select a session state manager that stores only the table state 
  @@ -175,67 +173,44 @@
   		return m_objTableSessionStateManager;
   	}
   
  -	/**
  -	 * Returns the localeSelectionListenerBinding.
  -	 * @return IBinding
  -	 */
  -	public IBinding getLocaleSelectionListenerBinding()
  -	{
  -		return m_objLocaleSelectionListenerBinding;
  -	}
  -
  -	/**
  -	 * Sets the localeSelectionListenerBinding.
  -	 * @param localeSelectionListenerBinding The localeSelectionListenerBinding to set
  -	 */
  -	public void setLocaleSelectionListenerBinding(IBinding localeSelectionListenerBinding)
  -	{
  -		m_objLocaleSelectionListenerBinding = localeSelectionListenerBinding;
  -	}
  -
  -	/**
  -	 * Returns the currentLocale.
  -	 * @return Locale
  -	 */
  -	public Locale getCurrentLocale()
  -	{
  -		return m_objCurrentLocale;
  -	}
  -
  -	/**
  -	 * Sets the currentLocale.
  -	 * @param currentLocale The currentLocale to set
  -	 */
  -	public void setCurrentLocale(Locale currentLocale)
  -	{
  -		m_objCurrentLocale = currentLocale;
  -	}
  -
  -
       public boolean getCheckboxSelected() 
       {
  -        return m_setSelectedLocales.contains(getCurrentLocale());
  +        return getSelectedLocales().contains(getCurrentLocale());
       }
       
       public void setCheckboxSelected(boolean bSelected) 
       {
  +        Locale objLocale = getCurrentLocale();
  +        Set setSelectedLocales = getSelectedLocales();
  +        
           if (bSelected)
  -            m_setSelectedLocales.add(getCurrentLocale());
  +            setSelectedLocales.add(objLocale);
           else
  -            m_setSelectedLocales.remove(getCurrentLocale());
  +            setSelectedLocales.remove(objLocale);
  +        
  +        // persist value
  +        setSelectedLocales(setSelectedLocales);
       }
   
  -    public void formSubmit(IRequestCycle objCycle)
  +    public void selectLocales(IRequestCycle objCycle)
       {
  -        Locale[] arrLocales = new Locale[m_setSelectedLocales.size()];
  -        m_setSelectedLocales.toArray(arrLocales);
  +        Set setSelectedLocales = getSelectedLocales();
  +        Locale[] arrLocales = new Locale[setSelectedLocales.size()];
  +        setSelectedLocales.toArray(arrLocales);
   
           ILocaleSelectionListener objListener = 
               (ILocaleSelectionListener) getLocaleSelectionListenerBinding().getObject();
           objListener.localesSelected(arrLocales);
  -        
  -        m_setSelectedLocales.clear();
  +
  +        // clear selection
  +        setSelectedLocales(new HashSet());
       }
   
  +    public abstract IBinding getLocaleSelectionListenerBinding();
  +    
  +    public abstract Locale getCurrentLocale();
  +
  +    public abstract Set getSelectedLocales();
   
  +    public abstract void setSelectedLocales(Set set);
   }
  
  
  

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