• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle a action on a link?

 
michelle Wang
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
sanat
Ranch Hand
Posts: 111
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ 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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic