commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Waldhoff, Rodney" <rwald...@us.britannica.com>
Subject [Jelly][PATCH] switch/case/default tags
Date Tue, 22 Oct 2002 00:09:24 GMT

I frequently find myself writing Jelly scripts like:

<j:choose>
  <j:when test="${some.complicated.expression().equals('foo')}">
    <!-- do something -->
  </j:when>
  <j:when test="${some.complicated.expression().equals('bar')}">
    <!-- do something else -->
  </j:when>
  <!-- ... -->
  <j:otherwise>
    <!-- do something else -->
  </j:otherwise>
</j:choose>

The redudancy of some.complicated.expression() is required, since choose/when/otherwise is
implementing an if/else if/else expression.  What I really want is a switch/case expression,
e.g.,:

<j:switch on="${some.complicated.expression()}">
  <j:case value="foo">
    <!-- do something -->
  </j:case>
  <j:case value="bar">
    <!-- do something else -->
  </j:case>
  <!-- ... -->
  <j:default>
    <!-- do something else -->
  </j:default>
</j:switch>

(I am aware that I could set/unset a variable to factor out "some.complicated.expression()",
but that doesn't solve the problem very elegantly, IMO. Also true switch/case/default support
lets you do more interesting things than if/else--like doubling up cases by "falling thru".)

The attached patch adds support for these tags, as well as a few simple unit tests for them.

PS: I already have karma to commons and commons-sandbox and hence can commit this directly
if you want to avoid dealing with the patch itself.  I just wanted to run this by everyone
first.

- R.

Mime
View raw message