9

I want to display various data in Display Tag column according to what I get from Session.

How can I integrate switch case with display tag <display:column>? I want to display AAA if the unit value I get from session is 1 etc.

Here is what I want to do.

switch(List.unit){
                       case 1:
                            unit = "AAA";
                            break;
                        case 2:
                            unit = "BBB";
                            break;
                        case 3:
                            unit = "CCC";
                            break;
                        default:
                            unit = "undefined";
                            break;
                    }

Thanks ahead.

kitokid
  • 3,009
  • 17
  • 65
  • 101

1 Answers1

24

You do it with displaytag exactly as you would do it without it. Just compute the desired unit in the servlet/action dispatching to your JSP and store this unit in some bean in the request. Then access this bean in the JSP :

<display:column>${theBeanStoredInTheRequest.unit}</display:column>

Or compute it in the JSP itself, using the JSTL, but it's more verbose:

<display:column>
    <c:choose>
        <c:when test="${sessionScope.unit == 1}">AAA</c:when>
        <c:when test="${sessionScope.unit == 2}">BBB</c:when>
        <c:when test="${sessionScope.unit == 3}">CCC</c:when>
        <c:otherwise>undefined</c:otherwise>
    </c:choose>
</display:column>
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • hi, it is displaying all the value in the display column like this [AAA BBB CCC ]. any ideas? the value from the session scope is correctly received. Thanks. – kitokid Sep 30 '11 at 06:37
  • when I try to print out unit value itself `${List.unit}`, the value is correct. 1,2,3 etc. my display table is like this ``. I get the value of List from Session.Thanks. – kitokid Sep 30 '11 at 06:54
  • Have you added the taglib directive for the core JSTL taglib at the beginning of your JSP? What's the generated HTML (view source) – JB Nizet Sep 30 '11 at 07:00
  • Thanks it works. first I use `<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>` and it gave me jasper exception. So when I use,`<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>`, it works well. Thanks for both suggestion. I prefer to use your first suggestion, just pass the computed value and Dispatch to JSP. but both works well. Thanks again :) – kitokid Sep 30 '11 at 07:18