File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes How to handle a action on a link? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to handle a action on a link?" Watch "How to handle a action on a link?" New topic

How to handle a action on a link?

michelle Wang
Ranch Hand

Joined: Jan 12, 2004
Posts: 65
I used a form for button action,
<FORM ACTION="../action/" METHOD="POST">


but now I need to click on a text hyper link to another detail page, for example, click on accountName then display all detail info about that account. When click on the accountName, I need pass in the accountID for the next search process also. How to code this part? Any one have sample code?

michelle Wang <br />SCJP 1.4
Ranch Hand

Joined: Dec 08, 2004
Posts: 111

JavaScript can be used for this type of situations. Here is the javascript:

function submitAction(strutsAction) {
document.forms[0].action = strutsAction;

In your JSP you need to write something like this

<a href="javascript:submitAction('theAction')">accountName</a>

Hope this helps.
michelle Wang
Ranch Hand

Joined: Jan 12, 2004
Posts: 65
now I find can use this:
<html:link page="/"><%=accountName%></html:link>
in struts-config:
<action path="/DisplyAccountAction"

But now my pbm is how to pass the accountID to action with the link? bcs in my Action, I need the accountID (which user clicked) to retrieve from DB, then disply detail in the next page(accountDetail.jsp).
[ June 08, 2005: Message edited by: michelle Wang ]
praveen kumar gudapati

Joined: Sep 26, 2003
Posts: 15
<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="html" uri="" %>

<!-- header stuff here -->

<jsp:useBean id="params" class="java.util.HashMap"/>

<c:set target="${params}" property="user" value="${user.username}"/>
<c:set target="${params}" property="product" value="${product.productId}"/>
<html:link action="/BuyProduct" name="params">Buy Product Link</html:link>
Jack Wiesenthaler
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
<html:link> tag has paramId/paramName/paramProperty attributes, use those like this:

<html:link action="DisplayAccountAction" paramId="accountID" paramName="myBean" paramProperty="accountID"><bean:write name="myBean" property="accountName"/></html:link>
I agree. Here's the link:
subject: How to handle a action on a link?
It's not a secret anymore!