Class ChoiceRenderer<T>
- java.lang.Object
-
- org.apache.wicket.markup.html.form.ChoiceRenderer<T>
-
- Type Parameters:
T
- The model object type
- All Implemented Interfaces:
Serializable
,IChoiceRenderer<T>
,IDetachable
,org.apache.wicket.util.io.IClusterable
- Direct Known Subclasses:
EnumChoiceRenderer
public class ChoiceRenderer<T> extends Object implements IChoiceRenderer<T>, org.apache.wicket.util.io.IClusterable
Renders one choice. Separates the 'id' values used for internal representation from 'display values' which are the values shown to the user of components that use this renderer. Usage:new DropDownChoice<User>("users", new Model<User>(selectedUser), listOfUsers)
creates a DropDownChoice of users and the display value will be toString() and the id the index of the object in the ListOfUsers.new DropDownChoice<User>("users", new Model<User>(selectedUser), listOfUsers, new ChoiceRenderer<User>("name"))
creates a DropDownChoice of users and the display value will be looked up by property expression ("name") and the id the index of the object in the ListOfUsersnew DropDownChoice<User>("users", new Model<User>(selectedUser), listOfUsers, new ChoiceRenderer<User>("name", "id"))
creates a DropDownChoice of users and the display value will be looked up by property expression ("name") and the id will be looked up by the property expression "id"- Author:
- jcompagner
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ChoiceRenderer()
Constructor.ChoiceRenderer(String displayExpression)
Constructor.ChoiceRenderer(String displayExpression, String idExpression)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
getDisplayValue(T object)
Get the value for displaying to an end user.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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.wicket.markup.html.form.IChoiceRenderer
detach, getObject
-
-
-
-
Constructor Detail
-
ChoiceRenderer
public ChoiceRenderer()
Constructor. When you use this constructor, the display value will be determined by calling toString() on the list object, and the id will be based on the list index. the id value will be the index
-
ChoiceRenderer
public ChoiceRenderer(String displayExpression)
Constructor. When you use this constructor, the display value will be determined by executing the given property expression on the list object, and the id will be based on the list index. The display value will be calculated by the given property expression- Parameters:
displayExpression
- A property expression to get the display value
-
ChoiceRenderer
public ChoiceRenderer(String displayExpression, String idExpression)
Constructor. When you use this constructor, both the id and the display value will be determined by executing the given property expressions on the list object.- Parameters:
displayExpression
- A property expression to get the display valueidExpression
- A property expression to get the id value
-
-
Method Detail
-
getDisplayValue
public Object getDisplayValue(T object)
Description copied from interface:IChoiceRenderer
Get the value for displaying to an end user.- Specified by:
getDisplayValue
in interfaceIChoiceRenderer<T>
- Parameters:
object
- the actual object- Returns:
- the value meant for displaying to an end user
-
getIdValue
public String getIdValue(T object, int index)
Description copied from interface:IChoiceRenderer
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.Note that the given index can be
-1
if the object in question is not contained in the available choices.- Specified by:
getIdValue
in interfaceIChoiceRenderer<T>
- Parameters:
object
- The object for which the id should be generatedindex
- The index of the object in the choices list.- Returns:
- String
-
-