org.apache.wicket.markup.html.form
Class EnumChoiceRenderer<T extends java.lang.Enum<T>>

java.lang.Object
  extended by org.apache.wicket.markup.html.form.EnumChoiceRenderer<T>
Type Parameters:
T -
All Implemented Interfaces:
java.io.Serializable, IClusterable, IChoiceRenderer<T>

public class EnumChoiceRenderer<T extends java.lang.Enum<T>>
extends java.lang.Object
implements IChoiceRenderer<T>

IChoiceRenderer implementation that makes it easy to work with java 5 enums. This renderer will attempt to lookup strings used for the display value using a localizer of a given component. If the component is not specified, the global instance of localizer will be used for lookups.

display value resource key format: <enum.getSimpleClassName()>.<enum.name()>

id value format: <enum.name()>

Author:
igor.vaynberg
See Also:
Serialized Form

Constructor Summary
EnumChoiceRenderer()
          Constructor that creates the choice renderer that will use global instance of localizer to resolve resource keys.
EnumChoiceRenderer(Component resourceSource)
          Constructor
 
Method Summary
 java.lang.Object getDisplayValue(T object)
          Get the value for displaying to an end user.
 java.lang.String getIdValue(T object, int index)
          This method is called to get the id value of an object (used as the value attribute of a choice element) The id can be extracted from the object like a primary key, or if the list is stable you could just return a toString of the index.
protected  java.lang.CharSequence postprocess(java.lang.String value)
          Postprocesses the value after it is retrieved from the localizer.
protected  java.lang.String resourceKey(T object)
          Translates the object into resource key that will be used to lookup the value shown to the user
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumChoiceRenderer

public EnumChoiceRenderer()
Constructor that creates the choice renderer that will use global instance of localizer to resolve resource keys.


EnumChoiceRenderer

public EnumChoiceRenderer(Component resourceSource)
Constructor

Parameters:
resourceSource -
Method Detail

getDisplayValue

public final java.lang.Object getDisplayValue(T object)
Get the value for displaying to an end user.

Specified by:
getDisplayValue in interface IChoiceRenderer<T extends java.lang.Enum<T>>
Parameters:
object - the actual object
Returns:
the value meant for displaying to an end user

resourceKey

protected java.lang.String resourceKey(T object)
Translates the object into resource key that will be used to lookup the value shown to the user

Parameters:
object -
Returns:
resource key

postprocess

protected java.lang.CharSequence postprocess(java.lang.String value)
Postprocesses the value after it is retrieved from the localizer. Default implementation escapes any markup found in the value.

Parameters:
value -
Returns:
postprocessed value

getIdValue

public java.lang.String getIdValue(T object,
                                   int index)
This method is called to get the id value of an object (used as the value attribute of a choice element) The id can be extracted from the object like a primary key, or if the list is stable you could just return a toString of the index.

Specified by:
getIdValue in interface IChoiceRenderer<T extends java.lang.Enum<T>>
Parameters:
object - The object for which the id should be generated
index - The index of the object in the choices list.
Returns:
String


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.