File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion 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: 63870

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] [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
    I agree. Here's the link:
    subject: equivalent EL instead of scriplet
    jQuery in Action, 3rd edition