com.sun.rave.web.ui.util
Class ConversionUtilities

java.lang.Object
  extended by com.sun.rave.web.ui.util.ConversionUtilities

public class ConversionUtilities
extends java.lang.Object

The ConversionUtilities class provides utility method for converting values to and from Strings. Use this class if your component processes input from the user, or displays a converted value.


Constructor Summary
ConversionUtilities()
           
 
Method Summary
static java.lang.Object convertRenderedValue(javax.faces.context.FacesContext context, java.lang.Object submittedValue, javax.faces.component.UIComponent component)
          Return the converted value of submittedValue.
static java.lang.Object convertValueToArray(javax.faces.component.UIComponent component, java.lang.String[] rawValues, javax.faces.context.FacesContext context)
          Convert a String array of submitted values to the appropriate type of Array for the value Object.
static java.lang.Object convertValueToList(javax.faces.component.UIComponent component, java.lang.String[] rawValues, javax.faces.context.FacesContext context)
          Convert a String array of submitted values to the appropriate type of List for the value Object.
static java.lang.Object convertValueToObject(javax.faces.component.UIComponent component, java.lang.String rawValue, javax.faces.context.FacesContext context)
          Convert the values of a component with a single (non-list, non-array) value.
static java.lang.String convertValueToString(javax.faces.component.UIComponent component, java.lang.Object realValue)
          Converts an Object (which may or may not be the value of the component) to a String using the converter associated with the component.
static javax.faces.convert.Converter getConverterForClass(java.lang.Class converterClass)
          This method retrieves an appropriate converter based on the type of an object.
static void removeRenderedValue(javax.faces.component.UIComponent component)
          Remove the stored rendered value from the specified component.
static void removeSavedRenderedValueState(javax.faces.component.UIComponent component)
          Remove the storage for the "virtual" for the specified component used to save the rendered value for the "virtual" instances of this component when used in a table.
static boolean renderedNull(javax.faces.component.UIComponent component)
          Return true if the stored rendered value on the specified component was null.
static void restoreRenderedValueState(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Used to restore the rendered value when a component is used within a table.
static void saveRenderedValueState(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Used to preserve the rendered value when a component is used within a table.
static void setRenderedValue(javax.faces.component.UIComponent component, java.lang.Object value)
          Record the value being rendered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConversionUtilities

public ConversionUtilities()
Method Detail

convertValueToObject

public static java.lang.Object convertValueToObject(javax.faces.component.UIComponent component,
                                                    java.lang.String rawValue,
                                                    javax.faces.context.FacesContext context)
                                             throws javax.faces.convert.ConverterException

Convert the values of a component with a single (non-list, non-array) value. Use this method if

Parameters:
component - The component whose value is getting converted
rawValue - The submitted value of the component
context - The FacesContext of the request
Returns:
An Object representing the converted value. If rawValue == null return null.
Throws:
javax.faces.convert.ConverterException - if the conversion fails
See Also:
ValueTypeEvaluator

convertValueToArray

public static java.lang.Object convertValueToArray(javax.faces.component.UIComponent component,
                                                   java.lang.String[] rawValues,
                                                   javax.faces.context.FacesContext context)
                                            throws javax.faces.convert.ConverterException

Convert a String array of submitted values to the appropriate type of Array for the value Object. This method assumes that the value binding for the value of the component has been determined to be an array (and as a consequence that the component implements ValueHolder).

To evaluate the valueBinding, use the ValueTypeEvaluator class.

Parameters:
component - The component whose submitted values are to be converted
rawValues - The submitted value of the component
context - The FacesContext of the request
Returns:
An array of converted values
Throws:
javax.faces.convert.ConverterException - if the conversion fails
See Also:
ValueTypeEvaluator

convertValueToList

public static java.lang.Object convertValueToList(javax.faces.component.UIComponent component,
                                                  java.lang.String[] rawValues,
                                                  javax.faces.context.FacesContext context)
                                           throws javax.faces.convert.ConverterException

Convert a String array of submitted values to the appropriate type of List for the value Object. This method assumes that the value binding for the value of the component has been determined to be a subclass of java.util.List, and as a consequence, that the component implements ValueHolder.

To evaluate the valueBinding, use the ValueTypeEvaluator class.

Parameters:
component - The component whose submitted values are to be converted
rawValues - The submitted value of the component
context - The FacesContext of the request
Returns:
A List of converted values
Throws:
javax.faces.convert.ConverterException - if the conversion fails
See Also:
ValueTypeEvaluator

convertValueToString

public static java.lang.String convertValueToString(javax.faces.component.UIComponent component,
                                                    java.lang.Object realValue)
                                             throws javax.faces.convert.ConverterException
Converts an Object (which may or may not be the value of the component) to a String using the converter associated with the component. This method can be used to convert the value of the component, or the value of an Object associated with the component, such as the objects representing the options for a listbox or a checkboxgroup.

Parameters:
component - The component that needs to display the value as a String
realValue - The object that the component is to display
Returns:
If converting the Object to a String fails
Throws:
javax.faces.convert.ConverterException - if the conversion fails

getConverterForClass

public static javax.faces.convert.Converter getConverterForClass(java.lang.Class converterClass)
This method retrieves an appropriate converter based on the type of an object.

Parameters:
converterClass - The name of the converter class
Returns:
An instance of the appropriate converter type

convertRenderedValue

public static java.lang.Object convertRenderedValue(javax.faces.context.FacesContext context,
                                                    java.lang.Object submittedValue,
                                                    javax.faces.component.UIComponent component)
                                             throws javax.faces.convert.ConverterException
Return the converted value of submittedValue. If submittedValue is null, return null. If submittedValue is "", check the rendered value. If the the value that was rendered was null, return null else continue to convert.

Throws:
javax.faces.convert.ConverterException

setRenderedValue

public static void setRenderedValue(javax.faces.component.UIComponent component,
                                    java.lang.Object value)
Record the value being rendered.

Parameters:
component - The component being rendered.
value - The value being rendered.

renderedNull

public static boolean renderedNull(javax.faces.component.UIComponent component)
Return true if the stored rendered value on the specified component was null.


removeRenderedValue

public static void removeRenderedValue(javax.faces.component.UIComponent component)
Remove the stored rendered value from the specified component.


saveRenderedValueState

public static void saveRenderedValueState(javax.faces.context.FacesContext context,
                                          javax.faces.component.UIComponent component)
Used to preserve the rendered value when a component is used within a table. Since there is only one component instance when used in a table column the rendered value must be maintained for each "virtual" component instance for the rows in the column.

Parameters:
context - The current FacesContext for this request.
component - The component that is appearing in the table.

restoreRenderedValueState

public static void restoreRenderedValueState(javax.faces.context.FacesContext context,
                                             javax.faces.component.UIComponent component)
Used to restore the rendered value when a component is used within a table. Since there is only one component instance when used in a table column the rendered value must be maintained and restored for each "virtual" component instance for the rows in the column.

Parameters:
context - The current FacesContext for this request.
component - The component that is appearing in the table.

removeSavedRenderedValueState

public static void removeSavedRenderedValueState(javax.faces.component.UIComponent component)
Remove the storage for the "virtual" for the specified component used to save the rendered value for the "virtual" instances of this component when used in a table.