tags:

views:

191

answers:

1

I'm new to struts2 and confused by the '#','%' and '$' element. There are some usages like:

${user.name}
%{user.name}
<s:radio list="#{key1:value1,key2:value2}" />

Could any give me an explanation and examples?

+3  A: 

To put it simply

If ${user.name} in jsp page, it is an EL expression. If ${user.name} in struts.xml, it is an OGNL expression.

If %{user.name} in jsp page, it is an OGNL expression.

Final, #{key1:value1,key2:value2} is an OGNL expression, it means creates a map that maps the key1 to the value1 and key2 to the value2.

BTW: #{key1:value1,key2:value2} should be wrap in %{}, like %{#{key1:value1,key2:value2}}, however, some attributes in struts2 tags will assume that is OGNL expression, that means without %{} is OK.

Gordian Yuan