How to capture EventDispatchAction in Struts from Hyperlink?
I have a JSP page where there are multiple options for search, i.e. "search by Application id", "search by Applicant name" etc. I have used struts EventDispatchAction to catch the event generated by a particular submit button. This is working fine. Below is the snap of the struts-config file for this:
Now I am facing problem in paginating the search results, because I am not able to generate event when the page numbers are clicked. They are hyperlinks. Below is the code used to generate the page numbers:
<c:forEach items="${pagelist}" var="emp">
<td><a href="#?page=${emp}">${emp}</a></td>
</c:forEach>
I am not sure what to put in place of # to generate event for EventDispatchAction. The ActionClass to capture the submits is given below:
public class SearchApplicationAction extends org.apache.struts.actions.EventDispatchAction {
public ActionForward idSubmit(ActionMapping mappin开发者_开发问答g, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List applist = null;
SearchApplicationForm searchApp = (SearchApplicationForm) form;
String idText = searchApp.getAppId();
int appId = Integer.parseInt(idText);
UserManager manager = new UserManager();
applist = manager.ViewApplicationById(appId);
sess.setAttribute("applicationList", applist);
return mapping.findForward("idSubmit");
}
public ActionForward nameSubmit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List applist = null;
SearchApplicationForm searchApp = (SearchApplicationForm) form;
String name = searchApp.getApplicantName();
UserManager manager = new UserManager();
applist = manager.ViewApplicationByName(name);
sess.setAttribute("applicationList", applist);
return mapping.findForward("nameSubmit");
}
}
Any help in this regard will be very helpful. Thanks
Thanks Miguel. Actually the problem is not in using actions with links but to catch the appropriate event. When a user clicks on any of the search options then the event is handled in SearchApplicationAction. But after paginating the search results, I have to generate those actions whenever someone clicks on the page numbers. If I hardcode the action in hyperlink then it works.
<td><a href="searchApplication.do?nameSubmit&page=${emp}">${emp}</a></td>
You could use the struts taglib: <html:link>
in order to build links related to struts actions. See this: http://struts.apache.org/1.x/struts-taglib/tagreference.html#html:link
精彩评论