commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Waldhoff, Rodney" <>
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:when test="${some.complicated.expression().equals('foo')}">
    <!-- do something -->
  <j:when test="${some.complicated.expression().equals('bar')}">
    <!-- do something else -->
  <!-- ... -->
    <!-- do something else -->

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,

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

(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

- R.

View raw message