Let's create a control that will allow us to use one of the available celebrities and provide a way to display exactly which celebrity was selected. I don't know what it will be used for, but it might certainly become valuable as we continue to develop the Celebrity Collector application. The control can be placed on any page for now, let it be ShowAll
for example, and the end result might look like this:
And here is how this will look in the page template:
<t:form> <t:select t:model="celebrityModel" t:value="selectedCelebrity" t:encoder="celebrityEncoder"/> <input type="submit" value="Submit"/> </t:form> <p>Selected Celebrity: ${selectedCelebrityName}</p>
You can see that the Select
component has three parameters, in this case, celebrityModel, selectedCelebrity
and celebrityEncoder
. Here is how they can be provided by the page class:
public SelectModel getCelebrityModel() { return new CelebritySelectModel(getAllCelebrities()); } public...