[prev in list] [next in list] [prev in thread] [next in thread] 

List:       taglibs-user
Subject:    Re: using scripting variable in JSTL standard 1.0 EL
From:       Felipe Leme <jakartalists1 () felipeal ! net>
Date:       2003-12-15 19:30:51
[Download RAW message or body]

Martin,

The problem, I think, is that he wants to do some calculation with the 
request value.

Antony,

If the calculation is simple, you can access the request parameters as 
Martin mentioned, do the calculation using EL, assign it to another 
variable and then use that variable with c:out. Something like this:

// on top of the page
<c:set var="myCalculation" value="${2*param.foo + 3*param.bar}"/>

// then in the middle of the page

<c:out value="${myCalculation}"/>

If the calculation is complex, it would be better to encapsulate it in a 
custom tag (or in a bean). Something like this:

<myTaglib:myCalculation var="myCalculation" param1="${param.foo}" 
param2="${param.bar}"/>

Notice that in this case your custom tag should "know" how to evaluate 
the EL (unless you are using a JSP 2.0). An easier (to implement) 
solution would be:

<myTaglib:myCalculation var="myCalculation" requestParam1="foo" 
requestParam2="bar"/>

But in this case your tag is tied to the request.


Regarding the efficiency, your old solution was slightly more efficient. 
On the other hand, using JSTL and custom tags makes the JSP code much 
cleaner and easier to maintain. It's always a trade-off between 
performance x maintenance: unless the performance is really, really an 
issue, you should opt for the maintenance.

Felipe



Martin Cooper wrote:

>You can access request parameters directly with the EL. For example, if
>you have a request parameter named "foo", you can do this:
>
><c:out value="${param.foo}"/>
>
>The 'param' part is an implicit object that lets you access the request
>parameters.
>
>--
>Martin Cooper
>
>
>
>On Mon, 15 Dec 2003, Antony Paul wrote:
>
>  
>
>>Hi,
>>    I have a page where a value is calculated at top of the page based on a
>>request parameter. It is an integer. Using normal JSP I could get this
>>varaible at another part in page. But if using JSTL do I have to set the
>>value first in pageContext then get the value using EL. Is this an
>>inefficent method ?. I am working on JSTL standard 1.0 Tomcat 4.27.  I have
>>only 2 weeks knowledge in JSTL and EL.
>>    
>>



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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic