Search code examples
jspstruts2displaytag

How to pass values in JavaScript Function in Display tag in Struts


<display:table export="false"  id="data" 
                name="helpdeskTickets"  
                requestURI="/dofetchassignedtickets.action" pagesize="5" >
                <div id="tabheadM" class="tableHeader"></div>

        <display:column property="id" title="Ticket ID" sortable="true"   />           
        <display:column property="subject" title="Subject" sortable="true"   />
        <display:column property="module.name" title="Module" sortable="true"  />
        <display:column property="subModule.name" title="SubModule" sortable="true"   />
        <display:column property="createDate" title="Created At" sortable="true"  />
        <display:column property="priority" title="Priority" sortable="true"   />
        <display:column property="ticketstatus" title="Status" sortable="true"  />
        <display:column title="Action" href="javascript:viewTicketDetail('${data.id}');">
        <img  src="<%=request.getContextPath()%>/images/ViewDetails.png" />
        </display:column>

Only the first value is being fetched and same value is being fetched for multiple rows. I would like to pass on different values.

function viewTicketDetail(id)
{
 // 
}

Kindly help..

Below is the code after the changes. But still I am getting the same value for all rows :(

<display:table export="false" id="data" uid="row" name="helpdeskTickets"
 requestURI="/dofetchassignedtickets.action" pagesize="5" > 
  <display:column property="ticketstatus" title="Status" sortable="true" />
  <display:column property="id" title="Action" href="javascript:viewTicketDetail('${row.id}');">

Solution

  • You should add uid attribute to the table.

    <display:table export="false"  id="data" uid="row"
                name="helpdeskTickets"  
                requestURI="/dofetchassignedtickets.action" pagesize="5" >
    

    Then use OGNL

    viewTicketDetail('<s:property value="%{#attr.row.yourAttribute}"/>');
    

    or using EL

    viewTicketDetail('${row.yourAttribute}');
    

    using column

    <display:column title="Action">
        <a href="javascript:viewTicketDetail('<s:property value="%{#attr.row.id}"/>');"><img src="<s:url value='/images/ViewDetails.png'/>" /></a>
    </display:column>