s:select selected option from a list based on a condition

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

s:select selected option from a list based on a condition

heberraja@gmail.com
<s:select name='student'
 list="students" listKey="sid" listValue="name"
 value="defaultStudent.equals('true')"
/>

I have a select tag as above. The Student object has a boolean value defaultStudent with getter isDefaultStudent. How to pre-select the default student based on this boolean value. Value accepts only static value, not condition.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: s:select selected option from a list based on a condition

Yasser Zamani-2


On 11/20/2017 5:00 PM, [hidden email] wrote:
> <s:select name='student'
>   list="students" listKey="sid" listValue="name"
>   value="defaultStudent.equals('true')"
> />
>
> I have a select tag as above. The Student object has a boolean value defaultStudent with getter isDefaultStudent. How to pre-select the default student based on this boolean value. Value accepts only static value, not condition.

I think this approach would work:

IN YOUR ACTION
public Integer getDefaultStudentId() {
foreach(Student s : students) if(s.isDefaultStudent()) return s.getId();
return -1;
}

IN YOUR JSP
<s:select ... value="defaultStudentId" ...

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: s:select selected option from a list based on a condition

Lukasz Lenart
In reply to this post by heberraja@gmail.com
2017-11-20 14:30 GMT+01:00 [hidden email] <[hidden email]>:
> <s:select name='student'
>  list="students" listKey="sid" listValue="name"
>  value="defaultStudent.equals('true')"
> />
>
> I have a select tag as above. The Student object has a boolean value defaultStudent with getter isDefaultStudent. How to pre-select the default student based on this boolean value. Value accepts only static value, not condition.

value="%{#this.defaultStudent ? #this.name : '-1'}"

or

value="%{[0].defaultStudent ? [0].name : '-1'}"


Regards
--
Ɓukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]