T
- The model object typepublic class LambdaChoiceRenderer<T> extends Object implements IChoiceRenderer<T>
Usage:
new DropDownChoice<User>("users", new Model<User>(selectedUser), listOfUsers, new LambdaChoiceRenderer<User>(User::getName))
creates a DropDownChoice of users and the display value will be looked up by function (User::getName) and the id the index of the object in the ListOfUsers
new DropDownChoice<User>("users", new Model<User>(selectedUser), listOfUsers, new LambdaChoiceRenderer<User>(User::getName, User::getId))
creates a DropDownChoice of users and the display value will be looked up by function (User::getName) and the id will be looked up by the function (User::getId)
Constructor and Description |
---|
LambdaChoiceRenderer()
Constructor.
|
LambdaChoiceRenderer(org.danekja.java.util.function.serializable.SerializableFunction<T,?> displayExpression)
Constructor.
|
LambdaChoiceRenderer(org.danekja.java.util.function.serializable.SerializableFunction<T,?> displayExpression,
org.danekja.java.util.function.serializable.SerializableFunction<T,?> idExpression)
Constructor.
|
Modifier and Type | Method and 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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
detach, getObject
public LambdaChoiceRenderer()
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
public LambdaChoiceRenderer(org.danekja.java.util.function.serializable.SerializableFunction<T,?> displayExpression)
When you use this constructor, the display value will be determined by executing the given function on the list object, and the id will be based on the list index. The display value will be calculated by the given function
displayExpression
- A function to get the display valuepublic LambdaChoiceRenderer(org.danekja.java.util.function.serializable.SerializableFunction<T,?> displayExpression, org.danekja.java.util.function.serializable.SerializableFunction<T,?> idExpression)
When you use this constructor, both the id and the display value will be determined by executing the given functions on the list object.
displayExpression
- A function to get the display valueidExpression
- A function to get the id valuepublic Object getDisplayValue(T object)
IChoiceRenderer
getDisplayValue
in interface IChoiceRenderer<T>
object
- the actual objectpublic String getIdValue(T object, int index)
IChoiceRenderer
Note that the given index can be -1
if the object in question is not contained in the
available choices.
getIdValue
in interface IChoiceRenderer<T>
object
- The object for which the id should be generatedindex
- The index of the object in the choices list.Copyright © 2006–2022 Apache Software Foundation. All rights reserved.