On Wed, 2 Jan 2002, Paul DuBois wrote:
What are the constraints on the type of expressions that may be used
with c:if?
The short answer is 'boolean' or 'Boolean.'
The somewhat longer answer is that for the rtexprvalue library, the only
permissible type is 'boolean'. For the EL library, the value must resolve
to a Boolean as far as the tag handler's concerned; it's up to the
expression language, not the tag handler, to convert boolean (e.g., a
boolean Bean property) to Boolean.
Assume that $x has the value 1: c:set var=x value=1/
This evaluates the body:
c:if test=$x == 1/true/c:if
This does not:
c:if test=1 == $x/true/c:if
So the test must begin with a variable?
Note that '$' does not begin a variable, but identifies an EL expression.
Don't confuse '$' with the Bourne shell (or Perl) variable-reference
operator. The attribute value 1 == $x represents the String literal
1 == $x; $x == 1 represents the EL expression x == 1. Thus,
$1 == x should work just fine.
Note that this syntax is certainly not beyond debate. At a conference
recently, a member of the audience in a presentation I was giving on JSTL
suggested that XSLT's '{}' syntax would be much clearer to adopt than
Unix's '$'. Do you think that if the syntax had been
c:if test={x == 1}
and
c:if test={1 == 1x
that this would have avoided the confusion? I'd personally be very
interested in any feedback you've got.
Also, it looks like you can test only *one* variable value. If I try
to compare two values like this:
c:if test=$var1 == $var2true/c:if
Then I get: ReferenceError: $var2 is not defined.
Same issue here; the 'var2' attribute is referenced as 'var2', not
'$var2'. ($var2 could be the name of an attribute in its own right; the
ReferenceError comes from findAttribute($var2) failing.
Is there a way to compare two variables directly from JSTL, if c:if
cannot? I'm using EA3.
$var1 == var2
$var2 == var1
P.S. Most of the /standard-doc/Conditionals_FunctionalDescription_1_EA1.html
page uses JSTL core tags in the examples with no c: tag prefix (e.g., when
rather than c:when).
Yeah, we have yet to decide how to consistently describe our actions, when
the prefixes are really just suggestions and not mandated in any context.
I'm facing the same problem with my JSTL book. I'm personally leaning
toward always using the suggested prefixes in writing.
Shawn
--
To unsubscribe, e-mail: mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]