org.ujorm.wicket.component.tools
Class ChoiceRendererNullable<T extends Enum<T>>

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

public class ChoiceRendererNullable<T extends Enum<T>>
extends Object
implements org.apache.wicket.markup.html.form.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.vaynbergm, pavel.ponec
See Also:
Serialized Form

Field Summary
protected static String UNDEFINED_ITEM_KEY
          Undefined item Key
 
Constructor Summary
ChoiceRendererNullable()
          Constructor that creates the choice renderer that will use global instance of localizer to resolve resource keys.
ChoiceRendererNullable(org.apache.wicket.Component resourceSource)
          Constructor
 
Method Summary
 Object getDisplayValue(T item)
          
 String getIdValue(T item, int index)
          
protected  String getUndefinedKey()
          Localization key for undefined value
protected  CharSequence postprocess(String value)
          Postprocesses the value after it is retrieved from the localizer.
protected  String resourceKey(T item)
          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
 

Field Detail

UNDEFINED_ITEM_KEY

protected static final String UNDEFINED_ITEM_KEY
Undefined item Key

See Also:
Constant Field Values
Constructor Detail

ChoiceRendererNullable

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


ChoiceRendererNullable

public ChoiceRendererNullable(org.apache.wicket.Component resourceSource)
Constructor

Parameters:
resourceSource -
Method Detail

getDisplayValue

public Object getDisplayValue(T item)
                       throws NullPointerException

Specified by:
getDisplayValue in interface org.apache.wicket.markup.html.form.IChoiceRenderer<T extends Enum<T>>
Throws:
NullPointerException

resourceKey

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

Parameters:
item -
Returns:
resource key

postprocess

protected CharSequence postprocess(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 String getIdValue(T item,
                         int index)

Specified by:
getIdValue in interface org.apache.wicket.markup.html.form.IChoiceRenderer<T extends Enum<T>>

getUndefinedKey

protected String getUndefinedKey()
Localization key for undefined value



Copyright © 2015. All Rights Reserved.