Reputation: 558
I'm developing a Struts 2 application. In order to remove duplicated code, I want to have access to an Action
(let's call it A
) in 2 different JSP pages (let's say page_1.jsp
and page_2.jsp
). So far, so good. The problem is that in each of these 2 JSP pages, I also need to have simultaneous access to an additional action: B
and C
, respectively.
To summarize: page_1.jsp
needs access to Actions A
and B
, while page_2.jsp
needs access to Actions A
and C
. How would I get that? As far as I know, using type = "redirectAction"
in struts.xml
won't work, because it only redirects to the action, so the JSP page will only have access to the last action called.
Example:
<action name="A" class="package.action.A" method="execute">
<result name="success" type="redirectAction">B</result>
</action>
<action name="B" class="package.action.B" method="execute">
<result name="success">page_1.jsp</result>
</action>
As far as I know, in the example above page_1.jsp
will only have access to action B
, right?
EDIT:
In fact, class A
is named CreateArchitecturesAction
- I need to access it on actions B
and C
, in order to populate a similar <s:radio>
tag on both. The code is as simple as this:
public class CreateArchitecturesAction extends ActionSupport
{
private List<String> architectures;
private static final String intel32 = "Intel 32 Bit", intel64 = "Intel 64 Bit";
public String execute()
{
architectures = new ArrayList<String>();
architectures.add(intel32);
architectures.add(intel64);
return SUCCESS;
}
public List<String> getArchitectures()
{
return architectures;
}
public String getDefaultArchitectureValue()
{
return intel32;
}
}
Upvotes: 0
Views: 1217
Reputation: 1
Only one action you have access from JSP, however you can have access to any scope available in JSP after the page is dispatched. So this flow
<action name="A" class="package.action.A" method="execute">
<result name="success" type="dispatcher">B</result>
</action>
<action name="B" class="package.action.B" method="execute">
<result name="success">page_1.jsp</result>
</action>
You can have access to action B
if you change the scope of the action to request scoped.
Upvotes: 1