Bug 54314

Summary: Code generation of TagPlugins: When and Otherwise error when they are used without <c:choose> outside
Product: Tomcat 7 Reporter: Sheldon Shao <xshao>
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED INVALID    
Severity: normal    
Priority: P2    
Version: trunk   
Target Milestone: ---   
Hardware: PC   
OS: All   
Bug Depends on: 54242    
Bug Blocks:    
Attachments: Patchs for Choose When & Otherwise
Test case for Choose.java, When.java & Otherwise.java

Description Sheldon Shao 2012-12-17 07:05:13 UTC
Created attachment 29773 [details]
Patchs for Choose When & Otherwise

There is no "}" when "<c:when> or <c:otherwise>" are used without <c:choose> outside. 
For example,

<c:choose>
  <c:when test="${true}">
    When 1
    <c:when test="${abc}"> When 2 </c:when>
    <c:otherwise>
       Otherwise
    </c:otherwise> <!-- These two tags will generate code like this "if ($abc}) {} else {",  no "}" at the end" -->
  </c:when>
</c:choose>
Comment 1 Sheldon Shao 2012-12-17 07:06:22 UTC
Created attachment 29774 [details]
Test case for Choose.java, When.java & Otherwise.java
Comment 2 Sheldon Shao 2012-12-17 07:12:49 UTC
The test case depends the helper class provided in Bug 54242.
Comment 3 Konstantin Kolinko 2012-12-17 09:39:39 UTC
Your JSP is incorrect. You are not allowed to nest those tags that way.

Did you expect that to be allowed, or you do not like how this error is handled?
Comment 4 Sheldon Shao 2012-12-17 15:51:05 UTC
The JSP works very well on Jasper when without tagPlugins.
However JSP can't be compiled when with those jstl TagPlugins.

Here is the original tags,

                      <c:choose>
                         <c:when test="${iqModel.lotSize gt 0}">
                            <c:when test="${iqModel.remainQty eq 1}">${res:content2(res.content.global.ViewItemWeb.ItemQuantity.LmtlotAvailable, quantityContentContract)}</c:when>
                             <c:otherwise>${res:content2(res.content.global.ViewItemWeb.ItemQuantity.LmtlotsAvailable, quantityContentContract)}</c:otherwise>
                         </c:when>
                         <c:otherwise>${res:content2(res.content.global.ViewItemWeb.ItemQuantity.LmtQtyTxt, quantityContentContract)}</c:otherwise>
                     </c:choose>


(In reply to comment #3)
> Your JSP is incorrect. You are not allowed to nest those tags that way.
> 
> Did you expect that to be allowed, or you do not like how this error is
> handled?
Comment 5 Christopher Schultz 2012-12-20 20:10:16 UTC
Sheldon, what /should/ the result be when you improperly-nest these tags?
Comment 6 Sheldon Shao 2012-12-21 07:51:13 UTC
No tagPlugins the JSP works very well. 
With tagPlugins setup should not give compilation error even at some corner case.

(In reply to comment #5)
> Sheldon, what /should/ the result be when you improperly-nest these tags?
Comment 7 Mark Thomas 2013-01-03 21:17:33 UTC
The page is invalid. When and Otherwise are required to have Choose as an immediate parent. If the JSTL implementation doesn't enforce that then that isn't Tomcat's problem.