aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
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
Author

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/ListAccountAction.do" METHOD="POST">

<INPUT TYPE="SUBMIT" VALUE="Submit">

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
sanat
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;
document.forms[0].submit();
}

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="/DisplyAccountAction.do"><%=accountName%></html:link>
in struts-config:
<action path="/DisplyAccountAction"
parameter="/jsp/profile/account/accountDetail.jsp"
type="com.uf.management.profile.item.action.DisplayAccountAction"/>

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
Greenhorn

Joined: Sep 26, 2003
Posts: 15
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="html" uri="http://jakarta.apache.org/struts/tags-html" %>

<!-- 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>
 
 
subject: How to handle a action on a link?