views:

223

answers:

2

Hello All,

I recently started using the DisplayTag library and I've run into a problem.

I'm trying to create a column that will allow the user to link to another page if that other page will actually have something to display. I have it setup so that there's always a hyperlink there but I'm having trouble with the conditional. I have a variable setup that will either be empty or something else (usually success). This is what I have tried so far...

<display:table uid="log" pagesize="20" defaultsort="2" name="logs" class="displayTag" sort="list" requestURI="savedReports.action" >  
       <display:column property="reportName" titleKey="label.report" <%if(!((ReportLog)pageContext.getAttribute("log")).getStatus().equals("empty")){ %>href="pdfReportViewer.action" paramId="reportLogId" paramProperty="id" <%} %> sortable="true" headerClass="sortable"></display:column>

This method tries to use jsp in the middle of the display:column tag, and I end up getting an unterminated display:column tag error.

Next I tried this...

<display:table uid="log" pagesize="20" defaultsort="2" name="logs" class="displayTag" sort="list" requestURI="savedReports.action" >  
       <%if(((ReportLog)pageContext.getAttribute("log")).getStatus().equals("empty")){ %>         
        <display:column property="reportName" titleKey="label.report" sortable="true" headerClass="sortable"/>   
       <%}else{ %>
        <display:column property="reportName" titleKey="label.report" href="pdfReportViewer.action" paramId="reportLogId" paramProperty="id" sortable="true" headerClass="sortable"/>
       <%}%>

This didn't throw any errors, but every line defaulted to the hyperlink column. I tested to see if this was an error in my conditional, but alas it was not, creating a dummy column and displaying the result of the conditional, and I get a lovely assortment of trues and falses.

I'm at a loss as to why the second method doesn't work so I'm hoping someone here has some better experience with displaytags!

Thanks!

+1  A: 

A bit ugly, from the top of my head:

<display:column property="reportName" titleKey="label.report" 
    href="${log.status != 'empty' ? pdfReportViewer.action : null}"
    paramId="${log.status != 'empty' ? reportLogId : null}"
    paramProperty="${log.status != 'empty' ? 'id' : null}"
    sortable="true" headerClass="sortable"></display:column>
Bozho
hmmm seems sound... I'll try it out when I get a chance, thanks!
Shaded
This doesn't work because the log object is updated only if it is within the display:column tag, as in the answer self-accepted.
simon
+1  A: 

Thanks for the answer Bozho, but I ended up doing it with a little jsp... code below...

<display:column titleKey="label.view" sortable="false" headerClass="sortable">
    <%if(!((ReportLog)pageContext.getAttribute("log")).getStatus().equals("empty")){ %>
    <a href="pdfReportViewer.action?reportLogId<%=((ReportLog)pageContext.getAttribute("log")).getId()%>">View</a>
    <%} %>
</display:column>

Thanks again for the help!

Shaded
this is very ugly, but if it works for you..
Bozho