wicket.markup.html.form
Class ChoiceRenderer

java.lang.Object
  extended by wicket.markup.html.form.ChoiceRenderer
All Implemented Interfaces:
java.io.Serializable, IChoiceRenderer

public class ChoiceRenderer
extends java.lang.Object
implements IChoiceRenderer

Default implementation of IChoiceRenderer. Usage:

 new DropDownChoice("users", new Model(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("users", new Model(selectedUser), listOfUsers, new ChoiceRenderer("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 ListOfUsers

 new DropDownChoice("users", new Model(selectedUser), listOfUsers, new ChoiceRenderer("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
ChoiceRenderer()
          Construct.
ChoiceRenderer(java.lang.String displayExpression)
          Construct.
ChoiceRenderer(java.lang.String displayExpression, java.lang.String idExpression)
          Construct.
 
Method Summary
 java.lang.Object getDisplayValue(java.lang.Object object)
          Get the value for displaying to an end user.
 java.lang.String getIdValue(java.lang.Object 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
 

Constructor Detail

ChoiceRenderer

public ChoiceRenderer()
Construct. 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(java.lang.String displayExpression)
Construct. 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(java.lang.String displayExpression,
                      java.lang.String idExpression)
Construct. 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 value
idExpression - A property expression to get the id value
Method Detail

getDisplayValue

public java.lang.Object getDisplayValue(java.lang.Object object)
Description copied from interface: IChoiceRenderer
Get the value for displaying to an end user.

Specified by:
getDisplayValue in interface IChoiceRenderer
Parameters:
object - the actual object
Returns:
the value meant for displaying to an end user
See Also:
IChoiceRenderer.getDisplayValue(java.lang.Object)

getIdValue

public java.lang.String getIdValue(java.lang.Object 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.

Specified by:
getIdValue in interface IChoiceRenderer
Parameters:
object - The object for which the id should be generated
index - The index of the object in the choices list.
Returns:
String
See Also:
IChoiceRenderer.getIdValue(java.lang.Object, int)


Copyright © 2004-2007 Wicket developers. All Rights Reserved.