Reputation: 819
I am passing a Model
and a List<String>
from controller to .html
file using the render
method invocation. The Model
passed contains some values that has to be populated in different components present in the UI and the List<String>
is used for binding with the combo-box.
For binding the List<String>
with combo-box in the .html
using the below code and this is working fine:
#{select 'employee.role', items:userRoles, valueProperty:'userRoles', labelProperty:'userRoles'/}
What I want to achieve:
Suppose the List<String>
contains the roles as Trainer
, Educator
, Trainee
, Staff
and the Model
passed has a role
property with value Staff
. When the page loads, then Staff
should be in selected
state in the combo-box display.
Problem
I am aware of how to iterate through a List
in Play framework template but I am not aware of how to keep a value selected
in the drop-down based on one of the property values present in the Model
Kindly help me on this.
Upvotes: 0
Views: 1901
Reputation: 691913
From the documentation:
This tag can generate options using items attribute.
- items (optional) - list of objects, used to create options
- value (optional) - selected element in items (note that multiple selections are not supported)
- labelProperty (optional) - for each item, attribute used as option’s label
- valueProperty (optional) - for each item, attribute used as option’s value. id is used by default
So, the code should be:
#{select 'employee.role', items: userRoles, value: model.role /}
Upvotes: 2