You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "heberraja@gmail.com" <he...@gmail.com> on 2017/11/20 13:30:28 UTC

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

<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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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

Posted by Lukasz Lenart <lu...@apache.org>.
2017-11-20 14:30 GMT+01:00 heberraja@gmail.com <he...@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.

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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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

Posted by Yasser Zamani <ya...@apache.org>.

On 11/20/2017 5:00 PM, heberraja@gmail.com 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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org