my dog learned polymorphism*
The moose likes JSP and the fly likes equivalent EL instead of scriplet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "equivalent EL instead of scriplet" Watch "equivalent EL instead of scriplet" New topic

equivalent EL instead of scriplet

Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
how can I replace the following scriplet with the help of c:if and EL

<% if(searchResults.size() == 0 && request.getAttribute ("firstLoad") == null ) { %> code

<% } else { %> code
<% } %>

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60782

Give it a shot and see how close you can get.

Some notes:

  • searchResult will need to be a scoped variable rather than a scripting variable
  • the JSTL 1.1 fn:length() EL function can be used to obtain the size of a collection
  • the empty operator will check for null or empty
  • in order to implement an "else" condition, you'll need to use <c:choose> rather than <c:if>
  • it is assumed that you are using JSTL 1.1 and JSP 2.0

  • [ October 03, 2006: Message edited by: Bear Bibeault ]

    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Muhammad Imad Qureshi
    Ranch Hand

    Joined: Sep 13, 2005
    Posts: 238
    hey bear thanks a lot. i was just too much in a rush. i did it. thanks
    this is what i did. I thought i cannot use && and compare null in EL but it turns out i can

    <c:when test="${empty searchResults && firstLoad == null }">
    Addresses Not Found ! </span></p>
    ....html to generate and display table
    wood burning stoves
    subject: equivalent EL instead of scriplet
    Similar Threads
    EL and expression
    Content of JSTL test attributes
    access to local variable via EL
    question in tagdependent body-content
    how to iterate and get values in a dropdown from a list variable