jsp - If-else (nested) or when condition in JSTL -
i have program populates table , depending on type of value in each cell, change formatting - percentage, decimal places, grouping etc.
i have table default view , allow user filter results entering document number , table changes add 2 columns - document number , corresponding document name.
so, if number of columns retrieved say, 10, behaviour. if if 12, then, other behaviour.
date | documents bought | documents started | column 4 | column 5 03/24/2013 | 1000.0 | 2,000 | 1,500 | 2,500
is curtailed version of default view.
date | document id| document name | documents bought | documents started | column 4 | column 5 03/24/2013| 55 | waiver | 10 | 20 | 4 | 5
i using same java program call queries, , populate tables. wrote following in jsp.
<c:foreach var="row" items="${docfunnel}"> <tr> <c:foreach var="cell" items="${row}" varstatus="rowidx"> <c:choose> <c:when test="${rowidx.count==17}"> </c:when> <c:when test="${rowidx.index==2}"> <td>${cell}</td> </c:when> <c:when test="${rowidx.index==1}"> <td><fmt:formatnumber type="number" maxfractiondigits="3" groupingused="false" value="${cell}" /></td> </c:when> <c:otherwise> <c:choose> <c:when test="${rowidx.index==0}"> <td>${cell}</td> </c:when> <c:otherwise> <td> <fmt:formatnumber type="number" maxfractiondigits="3" groupingused="true" value="${cell}" /> </td> </c:otherwise> </c:choose> </c:otherwise> </c:choose> </c:foreach> </tr> </c:foreach> i had first designed first case in mind, , used check when got index 0, print cell is, or else, use formatnumber. filtering, , subsequent addition of 2 columns, had rewrite jstl , got second version work perfectly, original 1 not awry, grouping not appearing , ".0" appended number in 3rd column, , grouping not appearing 2nd column. rest of columns fine in both cases. know simple:
if(no. of columns == 12) if(index == 0 || index == 2) no format //print date , name of document if(index == 1) numberformat no grouping used //since indicates document id else if(no. of columns == 10) if(index == 0) no format //print date else numberformat grouping //regardless of number of columns but i'm not getting right in jstl. doing wrong? please let me know , suggest improvements. thank you.
if(no. of columns == 12) if(index == 0 || index == 2) no format //print date , name of document if(index == 1) numberformat no grouping used //since indicates document id else if(no. of columns == 10) if(index == 0) no format //print date else numberformat grouping //regardless of number of columns ========================================================= have write below <c:choose> <c:when test="${rowidx.count==12}"> <c:if test="${rowidx.index==0} || ${rowidx.index==2}"> no format //print date , name of document </c:if> <c:if test="${rowidx.index==1}"> numberformat no grouping used //since indicates document id </c:if> </c:when> <c:when test="${rowidx.count==10}"> <c:if test="${rowidx.index==0}"> no format //print date </c:if> </c:when>`enter code here` <c:otherwise> numberformat grouping //regardless of number of columns </c:otherwise>
Comments
Post a Comment