Reputation: 139
I have a struts 2 project where there are 3 actions that carry out different data reporting functions. I am in the process of creating a Home Page action, to display snippets of the data from the other 3 actions on the home page.
At the moment I have Home.action importing the other 3 actions and then using the other action objects to acquire the data. This doesn't feel 'correct', so I am wondering what the best way to do this is in Struts? Preferably without editing the original 3 actions too much.
Upvotes: 1
Views: 255
Reputation: 285
I've had similar dilemmas and I resolved them by defining a different action in struts.xml
that returns only the action's results (without the surrounding tiles
etc.).
I then used jQuery
to fetch the different actions using Ajax
and that had the additional bonus of actually letting the server calculate the different actions in different requests and therefore my users could see some of the the results before others, thats good if your actions take over 3 seconds to calculate the results.
Please note, that the use of Tiles here is completely irrelevant actually. You can get the same effect by just using different JSP's(that's assuming you want a little bit customized look).
My loadBrokerReport action shows the broker report inside a larger surrounding tile(layout), but loadBrokerReportAjax executes the same method, from the same Action class, but renders the results via ajaxReport.jsp file(That has less clutter, more suitable to be shown next to other things).
<!-- This is the normal action the users select from menu -->
<action name="loadBrokerReport" method="loadBrokerReport" class="ee.reinmets.intra.action.BrokerReportsAction">
<result type="tiles">brokerReport</result>
</action>
<!-- This is the action called via ajax -->
<action name="loadBrokerReportAjax" method="loadBrokerReport" class="ee.reinmets.intra.action.BrokerReportsAction">
<result>/WEB-INF/pages/brokerReports/ajaxReport.jsp</result>
</action>
<!-- This is the tile i'm referencing above, in tiles.xml -->
<definition name="brokerReport" extends="default">
<put-attribute name="body" value="/WEB-INF/pages/brokerReports/normalReport.jsp" />
</definition>
Upvotes: 1