Simply..I need to know whether these list attributes are doing same job or not.
<s:select name="city" label="City" list="cities" listKey="id" listValue="name" />
and
<s:select name="city" label="City" list="%{getCities()}" listKey="id" listValue="name" />
can we invoke action methods like above,If 'yes' what is the correct way to do that?
thanks,
list="cities"
and list="%{getCities()}"
both are exactly same. Both calls getter of List<City> cities
in action class to read value from valuestack
.
Both will throw an error if getter would be removed.
1. <s:select name="city" label="City" list="cities[0]" listKey="id" listValue="name" />
is evaluated to
a. <s:select name="city" label="City" list="%{cities[0]}" listKey="id" listValue="name" />
b. <s:select name="city" label="City" list="%{getCities().get(0)}" listKey="id" listValue="name" />
1, a & b are same because % forces OGNL
evaluation. that will query stack for particular property.
OGNL supports collections, that's why we can use this three.
We call actions when we use particular need.
For Example
<s:url id="databaseList" action="fetch-citynames" />
<sd:autocompleter key="search"
href="%{databaseList}" name="searchText" />
Here fetch-citynames
return json
list.
Also see this link
Actually I read from here
The principal reason is because %{}
syntax is used to force OGNL evaluation where Struts would otherwise be treating the value as a String literal.
For example,
<s:property value="name" />
will look for a name property in the value stack ie is a value retrieved by calling getName().
If you wanted to force it to use literal value "name", you will need to use the %{}
syntax -
<s:property value="%{'name'}" />
But in the case of <s:select list="" />
it uses OGNL Collection Construction
Here is how OGNL
call methods.. See here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.