Sorry, maybe I'm not expressing my question accurately.
I understand this is NOT the right approach for implementing this
specific case, but I'm using it as an example to ask for that OGNL
expression.
Finally, I believe I have found it (it works for me):
<s:iterator value="persons">
<td><s:property value="countryId"/></td>
<td><s:property value="%{getCountryName(countryId)}"/></td>
Given PersonAction: public String getCountryName(String countryId).
And:
<td><s:property value="countryId"/></td>
<td><s:property value="countryMap[countryId].countryName"/></td>
Given PersonAction: public Map<String, Country> getCountryMap();
I apologize for the confusion, I'm just starting with Struts.
Thank you.
El 01/05/14 21:05, Dave Newton escribió:
It's not the syntax that's an issue, it's how you're implementing your data
transfer.
There's no "syntax" for retrieving a persisted object by ID beyond what
OGNL's expression language (EL) provides. You can call arbitrary methods.
The problem with doing that on the view layer on a row basis is that you
end up putting a lot of data retrieval logic into your template, where (a)
it doesn't belong, and (b) it's on a row-by-row basis which will kill any
hopes of reasonable performance at scale.
You should be loading your data on the Java side. If you're talking about
on-demand, Ajax-y data loading then it's done via a standard Ajax call and
you can pass IDs or whatever else you want to the server side.
Dave
On Thu, May 1, 2014 at 2:59 PM, Antonio Sánchez<ads...@gmail.com> wrote:
Yes, that the obvious way. Thank you.
But guess there is some situation where the view needs asking to the
controller for some data passing some parameter. Although the example is
not the best one, suppose PersonAction has Map<String, String> get
Countries(), which is called in prepare(). Is there any syntax for
retrieving the country name corresponding to the country id in each
iteration?
El jue 01 may 2014 17:35:52 CEST, Dave Newton escribió:
If you only have an ID then you need to join the Country model; this seems
obvious.
You should do all that on the Java side to avoid the N+1 issue.
Dave
On Thu, May 1, 2014 at 10:58 AM, Antonio Sánchez<ads...@gmail.com>
wrote:
Hello.
Person CRUD.
Person bean has name, age... and "countryId". Country bean has countryId
and countryName.
In persons.jsp all persons are listed, displaying rows for each person,
and columns for name, age... but countryName must be displayed instead of
countryId:
<s:iterator value="persons">
I can display countryId:
<td><s:property value="countryId"/></td>
But, how can I display countryName?
Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail:user-unsubscr...@struts.apache.org
For additional commands, e-mail:user-h...@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail:user-unsubscr...@struts.apache.org
For additional commands, e-mail:user-h...@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org