Reputation: 4672
I have the following code in my JSP
function doContractAction(actionUrl) {
var strActionUrl = actionUrl;
if(strActionUrl !=null) {
document.forms[0].action = actionUrl;
document.forms[0].submit();
}
return false;
}
<div id="content">
<div id="report">
<s:form name="openControl" id="myActionForm" theme="simple" action="ShowAlertReports" method="post">
<div id="accordion">
<s:iterator id="alertCat" value="alerts" status="status" >
<h2 style="font-size:1.1em; padding-top:0px;padding-left:1px;padding-bottom:-5px; font-weight:bold;">
<p align="left"><s:property value="%{key}"/></p>
</h2>
<br>
<div>
<table id="${status.index}" class="grid one-em-below constant-left-width" cellspacing="0" d="ad-hoc-reports">
<thead class="nosort">
<tr>
<th scope="col" class="sortAsc" onclick="applySort(this);"><a style="cursor:pointer; color: #0066FF; font-weight:bold;">Alert Name </a></th>
<th scope="col" onclick="applySort(this);"><a style="cursor:pointer; color: #0066FF; font-weight:bold;">Customer Name</a></th>
<th scope="col" onclick="applySort(this);"><a style="cursor:pointer; color: #0066FF; font-weight:bold;">Date Opened</a></th>
<th scope="col">Action</th>
</tr>
</thead >
<tbody style="font-size:12px;">
<s:iterator id="alertsubcat" value="%{value}">
<tr>
<td>
<s:property value="name"/>
</td>
<td>
<s:property value="customerName"/>
</td>
<td style="font-size:11px;">
<s:if test="%{display=='OK'}">
<input type="button" value='<s:property value="%{display}" />'
onclick='return closeInfoAlert("<s:property value="%{alertsNotificationId}" />");' />
</s:if>
<s:else>
<input type="button" value='<s:property value="%{display}" />'
onclick='return doContractAction("<s:property value="%{url}" />");' />
</s:else>
</td>
</tr>
</s:iterator>
</tbody>
</table>
<br>
</div>
</s:iterator>
</div>
<s:hidden name="description" id="description" value=""/>
</s:form>
<br>
</div>
</div>
Now <p align="left"><s:property value="%{key}"/></p>
can have values
My requirement is from code
<s:else>
<input type="button" value='<s:property value="%{display}" />'
onclick='return doContractAction("<s:property value="%{url}" />");' />
</s:else>
I need to pass the value="%{key} which will be checked in the function doContractAction and I can check the value in key and if it equals Alert1 or Alert 2 . I open a pop-up window
How do I achieve this ?
Upvotes: 0
Views: 1281
Reputation: 1331
You can use a struts2 counter to give unique id's to each element in loop,I have given a link to refer counter in struts2 here
Now give unique id's to Button
and to <p>
, Now you will have elements given as below
<p id="p-0" align="left"> <input id="input-0" type="button">
<p id="p-1" align="left"> <input id="input-1" type="button">
...
<p id="p-n" align="left"> <input id="input-n" type="button">
Now you can pass id of the button using this.id
you can refer
here
Now you can split input-id
and counstruct p-id
. Once you get p-id
. Now you can get value of the p
by using
getElementById()
Upvotes: 1