Yes. There are 3 -4 other JSP's which are combined in home page. In one of the JSP's I have this table. I am also confused on this- How can a javascript retrieve an ID associated with table row (don't know how to select a row either). We are plannig to store row ID in the DB.
Thanks,
This is how it goes:
Your JSP
<nested:form action="yourAction.do">
.... .... .... .... .... .... .... .... ....
.... .... .... .... .... .... .... .... ....
<table>
//Form bean should have a collection variable "rows", with getters and setters
<nested:present property="rows">
<nested:iterate property="rows">
//uniqueId and longName are variables of your collection attribute objects
<nested:hidden property="uniqueId"/>
<tr>
<TD class="formData" onclick="javascript:selectRow('yourAction.do?uid=<nested:write property="uniqueId"/>')">
<nested:hidden property="longName"/>
<nested:write property="longName"/>
</TD>
</tr>
</nested:iterate>
</nested:present>
</table>
.... .... .... .... .... .... .... .... ....
.... .... .... .... .... .... .... .... ....
Your javascript function in jsp
<script type="text/javascript">
function selectRow(URL) {
document.getElementsByTagName('BODY')[0].style.cursor = 'wait';
document.rowForm.action = URL;
document.rowForm.submit();
}
</script>
Your action class
.... .... .... .... .... .... .... .... ....
.... .... .... .... .... .... .... .... ....
String rowUniqueId = request.getParamater("uid");
//Thus you know which row has been selected
//Store your row id in DB
.... .... .... .... .... .... .... .... ....
.... .... .... .... .... .... .... .... ....
Hope that makes things clear. Use nested form, it makes easier to manage multiple forms in your jsp. For reference on struts tags you can refer to:
http://struts.apache.org/1.x/struts-taglib/tlddoc/index.html
SirG
> how can I write on click event for each <tr> then?
Just write it :) Make use of the 'this' property.
HTML<form name="formname">
<input type="hidden" name="selectedRowId" />
<table>
<tr id="someAutogeneratedId" onclick="selectRow(this);">
...
The "someAutogeneratedId" should be an unique identifier.
JS<script>
function selectRow(tr) {
document.formname.selectedRowId = tr.id;
document.formname.submit();
}
</script>
Servlet:String selectedRowId = request.getParameter("selectedRowId");
Edit hm, I have to write faster, I guess :o)
SirGeneral: the "javascript:" declaration is not needed as the onclick actually always expects JavaScript.
Message was edited by:
BalusC
The above code takes to particular link just by clicking on the row itself. I need to have 3-4 options associated with click event.
Also, all these options and the row must be populated in GUI - for example in this post if some one clicks on reply and enters text, the text is displayed in a row with default values like reply- edit and send it as an e-mail.