com.sun.webui.jsf.event
Class TableSelectPhaseListener

java.lang.Object
  extended by com.sun.webui.jsf.event.TableSelectPhaseListener
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.faces.event.PhaseListener

public class TableSelectPhaseListener
extends java.lang.Object
implements javax.faces.event.PhaseListener

A utility class for radiobutton and checkbox components used to select rows of a table.

Note: UI guidelines recomend that rows should be unselected when no longer in view. For example, when a user selects rows of the table and navigates to another page. Or, when a user applies a filter or sort that may hide previously selected rows from view. If a user invokes an action to delete the currently selected rows, they may inadvertently remove rows not displayed on the current page. Using TableSelectPhaseListener ensures that invalid row selections are not rendered by clearing selected state after the render response phase. That said, there are cases when maintaining state across table pages is necessary. In this scenario, use the keepSelected method to prevent state from being cleared by this instance.

Note: To see the messages logged by this class, set the following global defaults in your JDK's "jre/lib/logging.properties" file.

 java.util.logging.ConsoleHandler.level = FINE
 com.sun.webui.jsf.event.TableSelectPhaseListener.level = FINE
 

See Also:
Serialized Form

Constructor Summary
TableSelectPhaseListener()
          Default constructor
TableSelectPhaseListener(boolean keepSelected)
          Construct an instance with the given flag indicating that selected objects should not be cleared after the render response phase.
TableSelectPhaseListener(java.lang.Object unselected)
          Construct an instance with an unselected parameter.
 
Method Summary
 void afterPhase(javax.faces.event.PhaseEvent event)
          Called during the JSF Lifecycle after the RENDER_RESPONSE phase.
 void beforePhase(javax.faces.event.PhaseEvent event)
          Called during the JSF Lifecycle before the RENDER_RESPONSE phase.
 void clear()
          Clear all selected objects.
 javax.faces.event.PhaseId getPhaseId()
          Get the phase id.
 java.lang.Object getSelected(com.sun.data.provider.RowKey rowKey)
          Get the selected object from this instance.
 boolean isKeepSelected()
          Test if the flag indicating that selected objects should be cleared after the render response phase.
 boolean isSelected(com.sun.data.provider.RowKey rowKey)
          Test if the object associated with the given RowKey is selected.
 void keepSelected(boolean keepSelected)
          Set the flag indicating that selected objects should be cleared after the render response phase.
 void setSelected(com.sun.data.provider.RowKey rowKey, java.lang.Object object)
          Set the selected object for this instance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableSelectPhaseListener

public TableSelectPhaseListener()
Default constructor


TableSelectPhaseListener

public TableSelectPhaseListener(boolean keepSelected)
Construct an instance with the given flag indicating that selected objects should not be cleared after the render response phase.

Parameters:
keepSelected - If true, ojects are not cleared.

TableSelectPhaseListener

public TableSelectPhaseListener(java.lang.Object unselected)
Construct an instance with an unselected parameter.

The unselected parameter is only required if a primitve value is being used for the selecteValue attribute of the checkbox or radiobutton. If the selectedValue property is an Object value then unselected can be null. If however it is a primitive type then it should be the MIN_VALUE constant instance of the wrapper Object type. For example if the application is assigning int values to selectedValue then unselected should be new Integer(Integer.MIN_VALUE).

Parameters:
unselected - the object to return for an unselected checkbox.
Method Detail

afterPhase

public void afterPhase(javax.faces.event.PhaseEvent event)
Called during the JSF Lifecycle after the RENDER_RESPONSE phase.

Specified by:
afterPhase in interface javax.faces.event.PhaseListener
Parameters:
event - The PhaseEvent object.

beforePhase

public void beforePhase(javax.faces.event.PhaseEvent event)
Called during the JSF Lifecycle before the RENDER_RESPONSE phase.

Specified by:
beforePhase in interface javax.faces.event.PhaseListener
Parameters:
event - The PhaseEvent object.

getPhaseId

public javax.faces.event.PhaseId getPhaseId()
Get the phase id.

Specified by:
getPhaseId in interface javax.faces.event.PhaseListener

clear

public void clear()
Clear all selected objects.


getSelected

public java.lang.Object getSelected(com.sun.data.provider.RowKey rowKey)
Get the selected object from this instance.

Note: Call this method from the get method that that is bound to the selected attribute.

Parameters:
rowKey - The current RowKey.
Returns:
The selected object.

isKeepSelected

public boolean isKeepSelected()
Test if the flag indicating that selected objects should be cleared after the render response phase.

Returns:
true if ojects are not to be cleared.

isSelected

public boolean isSelected(com.sun.data.provider.RowKey rowKey)
Test if the object associated with the given RowKey is selected.

Parameters:
rowKey - The current RowKey.
Returns:
A true or false value.

keepSelected

public void keepSelected(boolean keepSelected)
Set the flag indicating that selected objects should be cleared after the render response phase.

Parameters:
keepSelected - Selected objects are kept true, cleared if false.

setSelected

public void setSelected(com.sun.data.provider.RowKey rowKey,
                        java.lang.Object object)
Set the selected object for this instance.

Note: Call this method from the set method that that is bound to the selected attribute.

Parameters:
rowKey - The current RowKey.
object - The selected object.


Copyright © 2008 Sun Microsystems, Inc. All Rights Reserved.