Wednesday, January 26, 2011

JSTL duplication

I wanted to be able to traverse a Java HashMap using JSTL but at the same time I didn't want to display duplicate entries.

To do that with JSTL, I stored the list of already displayed records into a HashMap as follows:

                            <%-- Don't show duplicate gene names --%>
                            <%-- Already process Genes --%>
                            <jsp:useBean id="processed" class="java.util.HashMap" />                            <c:forEach items="${facs.genotypeTranslationErrors}" var="genotypeObservation" varStatus="errorCounter">
                                <c:if test="${empty processed[genotypeObservation.improperGeneName]}">
                                    <c:set target="${processed}" property="${genotypeObservation.improperGeneName}" value="${true}" />                            
                                    <p>
                                        Assay:                            
                                        <span class="errorHighlight">
                                            <strong>${genotypeObservation.improperGeneName}</strong>
                                        </span>
                                    </p>
                                </c:if>                                                
                            </c:forEach>

Reference: http://stackoverflow.com/questions/4517928/how-to-group-rows-with-duplicate-column-properties-in-a-jstl-cforeach

No comments:

Post a Comment