Results 1 to 6 of 6
  1. #1
    ngreddyit is offline Member
    Join Date
    Jan 2012
    Posts
    4
    Rep Power
    0

    Default JSTL - How to Use request scope variable to get value from map

    Hi,
    i am having a map object in JSTL, Map<String,Object> key string is like as follows 'Region_SiteName_Feature_templae'
    in the above SiteName and Feature are request scope variables, how can i use them to retrieve value from map

    <c:set var="mapRegions" value="${rc.regionMap}"/>
    <c:set var="siteName" value="${rc.siteName}"/> ex: siteName=ABCDE
    <c:set var="Feature " value="${rc.Feature }"/> ex: Feature = POY
    i am getting value using the key Region_ABCDE_POY_templae
    ${mapRegions.Region_ABCDE_POY_templae}, but i want to generate the key dynamically using the above two siteName and Feature variables?

    something like this ${mapRegions.Region_${siteName}_${Feature}_templae }

    but this is not working, how can we do this using JSTL.

    Thanks in Advance.

    Gangi.
    Last edited by ngreddyit; 01-23-2012 at 05:38 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: JSTL - How to Use request scope variable to get value from map

    Concatenate your String beforehand into another var?

  3. #3
    ngreddyit is offline Member
    Join Date
    Jan 2012
    Posts
    4
    Rep Power
    0

    Default Re: JSTL - How to Use request scope variable to get value from map

    Thanks,
    i can concatenate the string before hand, but expression inside expression is not accepting, ${ObjectrName.${concatenatedString}.data}

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: JSTL - How to Use request scope variable to get value from map

    Java Code:
    <c:set var="concatenatedString" value="Region_${siteName}_${Feature}_templae"/>
    .. then
    ${mapRegions[${concatenatedString}]}  // I think, I can never remember the syntax exactly.

  5. #5
    ngreddyit is offline Member
    Join Date
    Jan 2012
    Posts
    4
    Rep Power
    0

    Default Re: JSTL - How to Use request scope variable to get value from map

    Above syntax is not correct, i tried this before, but its not working any thoughts?


    Caused by: javax.el.ELException: Error Parsing: ${regionsAsMap[${keyString}
    at org.apache.el.lang.ExpressionBuilder.createNodeInt ernal(ExpressionBuilder.java:125)
    at org.apache.el.lang.ExpressionBuilder.build(Express ionBuilder.java:146)
    at org.apache.el.lang.ExpressionBuilder.createValueEx pression(ExpressionBuilder.java:190)
    at org.apache.el.ExpressionFactoryImpl.createValueExp ression(ExpressionFactoryImpl.java:68)
    at org.apache.jasper.runtime.PageContextImpl.propriet aryEvaluate(PageContextImpl.java:922)
    at org.apache.jsp.jsp.techtarget.v3.pageLayouts.wdefP ageLayout1_jsp._jspService(wdefPageLayout1_jsp.jav a:188)
    at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:374)
    ... 112 more
    Caused by: org.apache.el.parser.ParseException: Encountered "{" at line 1, column 17.
    Was expecting one of:

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: JSTL - How to Use request scope variable to get value from map

    Take the ${} out inside the [].
    I did say I can't guarantee the syntax.

Similar Threads

  1. problem with formbean in request scope
    By rajendra_bayana in forum Struts
    Replies: 0
    Last Post: 12-29-2011, 10:11 AM
  2. Variable Scope
    By Laura Warren in forum New To Java
    Replies: 3
    Last Post: 01-11-2009, 10:16 PM
  3. Request Scope in HttpServlet
    By rkpasunoori in forum Java Servlet
    Replies: 1
    Last Post: 11-13-2008, 05:43 AM
  4. How to use request Scope in Spring
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-31-2008, 10:06 AM
  5. How to use request Scope in Spring
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-28-2007, 12:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •