如果显示标签中的条件?

时间:2012-06-21 12:04:42

标签: java-ee struts displaytag

如果行的值等于“GRAND TOTAL”,我想显示链接,否则我在代码片段下面尝试但是收到错误的纯文本

<display:table name="expScoreCardCol" export="true" pagesize="20" sort="list" id="data" requestURI="" class="tablelist">   

     <display:column title="Zone" sortable="true" property="zone"></display:column>              
    <display:column title="Non-HNI Total" sortable="true" property="nonhniTotal"></display:column>   
        <display:column title="Non-HNI Per %" sortable="true" property="nonhniPer"></display:column>   

    <%if(!${data.zone}=="GRAND TOTAL"){ %>       
        <display:column title="Grand Total" sortable="true">   
        <html:link action="/exceptionScoreCardGrandReport.do?zone=${data.zone}"><b>${data.grandTotal}</b></html:link>   
        </display:column>   
        <%} %>   
</display:table>  

错误:

An error occurred at line: 270 in the generated java file
Syntax error, insert "while ( Expression ) ;" to complete DoStatement

An error occurred at line: 282 in the generated java file
Syntax error, insert "while ( Expression ) ;" to complete BlockStatements

An error occurred at line: 288 in the generated java file
Syntax error, insert "else Statement" to complete IfStatement

An error occurred at line: 288 in the generated java file
Syntax error, insert "}" to complete Block

1 个答案:

答案 0 :(得分:4)

不要使用scriptlet。决不。使用JSTL和EL。并且理解EL不能在scriptlet中使用:scriplets包含Java代码,而EL不是Java。

此外,如果特定行不是总计,则代码会添加一列。这不是应该做的。该列应始终存在,但其内容应根据行更改:

<display:table name="expScoreCardCol" export="true" pagesize="20" sort="list" id="data" requestURI="" class="tablelist">
    <display:column title="Zone" sortable="true" property="zone" />
    <display:column title="Non-HNI Total" sortable="true" property="nonhniTotal" />
    <display:column title="Non-HNI Per %" sortable="true" property="nonhniPer" />
    <display:column title="Grand Total" sortable="true">
        <c:if test="${data.zone != 'GRAND TOTAL'}">       
            <html:link action="/exceptionScoreCardGrandReport.do?zone=${data.zone}">
                <b>${data.grandTotal}</b>
            </html:link>
        </c:if>
    </display:column>      
</display:table>