Use Struts2's <s:property> tag in <display:table> tags

5k views Asked by At

I am trying to add a list into a table using DisplayTag.

Everything works normally when I add list property to a column in the usual manner:

<display:column property="status" title="Claim Status"/>
<display:column property="authNo" title="Authorization Number" href="authSlipMasterAction">

Now, I want to check when authNo is not blank; if it is blank, then do not provide the link, so how can I use <s:if test=''> and <s:property value=""> in the <display:table> tag ?

I've tried to display the value using <s:property value="authNo"/> but no value is shown (I have to display the value because I want to check the condition)

This is my code

   <display:table uid="myTable" id="display-tag" name="session.claimReportList">
   <display:column title="Authorization No"> 
    <s:property value="#attr.myTable.transNo" />
</display:column>

I have also tried

      <s:property value="#session.myTable.transNo" />
2

There are 2 answers

1
Andrea Ligios On BEST ANSWER

You need to use the #attr. notation in your <s:property /> or <s:if /> when inside a DisplayTag column; you also need to use the uid specified in the <display:table> tag after the #attr. to access your objects.

For example:

<display:table requestURI="actionURL" uid="myTable" />

    <display:column title="authNo">    
        <s:property value="#attr.myTable.authNo" />
    </display:column>

</display:table>

From OGNL Basics - Struts 2 Named Objects:

#attr['foo'] or #attr.foo

Access to PageContext if available, otherwise searches request/session/application respectively

P.S: I'd consider taking a look at some newer grid like jqGrid or DataTables, though.

1
Ranjitsinh On

Please try following code inside display tag.

1.) #attr.objectName: attribute in page, request, session, or application scope (searched in that order)
2.) row is the id you have used for display:table.
3.) authNo: Your custom propery.

<s:if test="%{#attr.row.authNo != null}">
    <display:column title="Status">Your custom message</display:column>
    </s:if>

Hope it may help you..!!