带显示标签的开关盒

kit*_*kid 8 jsp displaytag

我想根据从Session获得的内容在Display Tag列中显示各种数据.

如何将开关盒与显示标签集成 <display:column> 如果我从会话中获得的单位价值是1等,我想显示AAA

这就是我想要做的.

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

谢谢你.

JB *_*zet 21

你完全按照没有它的方式使用displaytag.只需在servlet/action调度到JSP中计算所需的单元,并将该单元存储在请求中的某个bean中.然后在JSP中访问这个bean:

<display:column>${theBeanStoredInTheRequest.unit}</display:column>
Run Code Online (Sandbox Code Playgroud)

或者使用JSTL在JSP本身中计算它,但它更详细:

<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>
Run Code Online (Sandbox Code Playgroud)