struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "CRANFORD, CHRIS" <Chris.Cranf...@setechusa.com>
Subject RE: JSTL c:if question
Date Tue, 01 Mar 2005 12:18:06 GMT
David,

In order to specify the scope, you preceed your variable with the scope
type.  Therefore for a request-scope variable, the variable would be :
"requestScope.variable".  There are several scope types:

  pageScope
  requestScope
  sessionScope
  applicationScope

Additionally, when you have multiple c:if tags that test different
conditions of the same variable, I would suggest rewriting the block as
follows:

<c:choose>
  <c:when test="${requestScope.mode=='a'}">
    first thing
  </c:when>
  <c:when test="${requestScope.mode=='b'}">
    second thing
  </c:when>
  <c:otherwise>
    a catch all section
  </c:otherwise>
</c:choose>

Consider the above more like a switch or if/elseif combo rather than
multiple if statements.

Hope this helps.
Chris

-----Original Message-----
From: David Johnson [mailto:chachany@gmail.com] 
Sent: Monday, February 28, 2005 6:24 PM
To: Struts Users Mailing List
Subject: JSTL c:if question


a little off topic but..

I have a variable (a string named "mode") in request scope and I want to
display something conditionally in the JSP. Right now, I have the
following, which doesnt work. The error is

2: Illegal scope attribute without var in "c:if" tag.

What am I doing wrong?

<c:if test="${mode}=='a'" scope="request">
   first thing
</c:if>
<c:if test="${mode}=='b'" scope="request">
   second thing
</c:if>
-- 
-Dave
ChaChaNY@Gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message