views:

549

answers:

1

Hi All,

I have link on click of which i want to get the entire list from database and display using display tag.I don't have any problem in using display tag (displaytag).,But i am not getting how would get the complete list on click of a hyperlink in struts.

As on clicking the link i am moving to a jsp and having a display tag where i have to dispaly the list,But how would i get it?

A: 

With Ajax, it's not possible since displaytag has no support for ajax. Here is a way of doing this (if I understood what you want to do).

The onclick event handler will point to your Struts action. The action will then get all information from database, populate the list, store it in request.setAttribute request and return a forward to a jsp page.

From the JSP page, use displaytag to iterate through the list, and display the value using bean:write tag.


E.g.

This is an example of an anchor tag that uses EL (expression language) pointing to a Struts Action page.

<a href="${pageContext.request.contextPath}/myAction.do?command=DoSomeCommand&userId=<bean:write name="user" property="id" />"><bean:message key="label.my_link" /></a>

The /myAction.do is declared in struts-config.xml file as

<action path="/myAction" type="org.apache.struts.action.MyAction" scope="request"  parameter="command">

</action>

if you want to use the anchor onclick event do something like this:

<a onclick="window.location.href='${pageContext.request.contextPath}/myAction.do?command=DoSomeCommand&userId=<bean:write name="user" property="id" />'" href="#"></a>

where ${pageContext.request.contextPath} means <%= request.getContextPath() %>

alternatively, use the struts <html:link> tag and it'll render an anchor tag for you.

The Elite Gentleman
you are right but how to make the event handler point to the struts action that is what i need<a href="struts action"> ?
sarah
See edited post.
The Elite Gentleman