Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7870001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:29:10+00:00 2026-06-03T01:29:10+00:00

I am facing some problem in using EL in JSTL and not able to

  • 0

I am facing some problem in using EL in JSTL and not able to access Java Hash Map as I would like. I am aware that in EL the key, if Integer gets accessed as Long. I have following hash map definition that I am trying to access in JSTL –

Map<Long, Object> testMap = new HashMap<Long, Object>();

In JSP page, I need to check if the map contains a specific key or not. I attempt to do that by checking if not empty as following –

<c:if test='${ ! empty testMap[currObj.currVal]}'>

I also access the map’s value for a key somewhere in the code like below –

<c:if test='${ testMapMap[5].data == 'something'}'>

Now the problem –

If i define my map above as <Integer, Object> then the first c:if works but second fails (as the second tries to access it as Long). However, if I define my map above as <Long, Object> the first if check always fails as it always recognizes it as empty but the second if statement where I check for the value works.

Is there any good way to make sure I access HashMap for both the if statements correctly? I will appreciate opinions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:29:12+00:00Added an answer on June 3, 2026 at 1:29 am

    What is currObj? Can you redefine its currVal member as a Long (or long)?


    A numeric literal (matching the IntegerLiteral production in the EL syntax) will be represented as a Long. The expression currObj.currVal evaluates to an Integer. A Long never equals() an Integer, so one expression must result in a different type.

    Essentially, what you need is an explicit type conversion. Nothing like this is built into EL, but you could create a custom EL function to do it for you. This is a static function that you implement in Java, then describe in a TLD. Another answer of mine gives an example of the packaging. Here’s what the function and its usage could look like in your case.

    package com.y.taglib.core;
    
    public final class CoercionUtil {
    
      public static Long toLong(Long n) {
        return n;
      }
    
    }
    

    The TLD would look like this:

    <taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">
      <tlib-version>1.0</tlib-version>
      <short-name>x-c</short-name>
      <uri>http://dev.y.com/taglib/core/1.0</uri>
      <function>
        <description>Coerce to a java.lang.Long.</description>
        <display-name>long</display-name>
        <name>long</name>
        <function-class>com.y.taglib.core.CoercionUtil</function-class>
        <function-signature>java.lang.Long toLong(java.lang.Long)</function-signature>
      </function>
    </taglib>
    

    In your JSP:

    <%@taglib uri="http://dev.y.com/taglib/core/1.0" prefix="my" %>
    ...
    <c:if test='${ ! empty testMap[my:long(currObj.currVal)]}'>
    

    The JSP engine takes care of the necessary type coercion (from the Integer result of currVal to the Long required by the toLong() method. Your method is there simply to indicate the required type; without it, the JSP engine sees the (erased) type of the argument of testMap.get(Object), and doesn’t see the need to perform any coercion since Integer is-an Object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm facing this problem with Java. I want to get some HTML informations from
I am facing some problem while returning data from web services. I am using
Started making a simple GUI using netbeans and now I'm facing some problem. I
I'm facing some problem when I fetch page content of particular Id. I'm using
Hi guys I am using entity framework, I am facing some problem while checking
Im facing some problem with json and objective c. Atm i am using sbJson
I've been using Zend framework some time now, but I'm facing a problem I
I'm using XStream to serialize some objects to XML, and am facing a problem
I am facing some problems for using placement new for contiguous memory.Please guide me,
I am facing some issues while serializing objects (I am using JBoss Drools, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.