如何在Struts中的Display标记中的JavaScript函数中传递值

时间:2014-07-02 12:03:02

标签: jsp struts2 displaytag

<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>

仅提取第一个值,并为多个行提取相同的值。我想传递不同的价值观。

function viewTicketDetail(id)
{
 // 
}

请帮助......

以下是更改后的代码。但我仍然得到所有行的相同值:(

<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}');">

1 个答案:

答案 0 :(得分:0)

您应该在表格中添加uid属性。

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

然后使用OGNL

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

或使用EL

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

使用列

<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>