Reputation: 752
I am new to Struts2. I have to create breadcrumbs in an application so what I want to do is to set a Map with all label/url of all links in breadcrumbs. My problem is that I don't know how to get the URL of an action inside the action class.
eg.
private Map<String, String> breadcrumbs;
public String MyAction() throws Exception {
breadcrumbs.put("List", SomeClass.getUrl("listAction"));
breadcrumbs.put("Project", SomeClass.getUrl("projectAction"));
breadcrumbs.put("Chart", SomeClass.getUrl("chartProjectAction"));
return Action.SUCCESS;
}
So, what should I use instead of that SomeClass to get the Url of an action?
Thanks in advance, Ciprian
Upvotes: 0
Views: 870
Reputation: 752
Eventually, as Aleksandr M suggests, I've send from the Action the action names and compile the URL directly from the .jsp file using s:url tag
<s:iterator value="breadcrumbs" status="st">
<s:if test="#st.last == true">
<li class="active"><s:property value="key" /></li>
</s:if>
<s:else>
<li><a href="<s:url action="%{value}" />"><s:property value="key" /></a></li>
</s:else>
</s:iterator>
Hope this will help someone!
Upvotes: 1