• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EL with in scriptlet

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
when i try running the below code i get the ouptut as {pageFlow.groupMap['groupId']}

but i need the actual value of the ${pageFlow.groupMap['groupId']} and the gruopId comes as 400,444,etc and when i hardcode the same
and put it in the<netui:content value="${pageFlow.groupMap['444']}"/> i get the correct value for it.

Can any one please help me out in solving this.

Below is the code that i am using

<%
// display a 'header' row for groups
String groupId = (String) pageContext.getAttribute("groupId");

if( groupId == null ) groupId = "";
if( !lastGroupId.equals( groupId ) ) {
String dataBind = "{pageFlow.groupMap['" + groupId + "']}";

%>
<tr >
<td>
<div align="center" class="title_main1">
<netui:content value="<%=dataBind %>"/>
</div>
</td>

</tr>
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This is because you are missing $ in the statement below:

String dataBind = "{pageFlow.groupMap['" + groupId + "']}";



Modify it to: "${pageFlow.groupMap['" + groupId + "']}" and after that it wont treat it as a string and you will get the desired output (using EL).

Regards,
Ashwini Kashyap

 
dahood shaikh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Kashyap,

I even tried that but its not taking that too and displaying as ${pageFlow.groupMap['groupId']}
 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That means its treating $ as a string.

Try making use of escape sequence for $ like:
String dataBind = "\${pageFlow.groupMap['" + groupId + "']}";
 
dahood shaikh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
:-( I GET BELOW ERROR NOW
An error has occurred:


org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 164 in the jsp file: /portlets/commonLabor/pageFlows/floodStoreProfile/floodStoreProfile.jsp
Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
161:
162: if( groupId == null ) groupId = "";
163: if( !lastGroupId.equals( groupId ) ) {
164: String dataBind = "\${pageFlow.groupMap['" + groupId + "']}";
165:
166:
167: %>
 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok then dont make use of that \$ since Exception says its invalid escape sequence.

Try to directly use that expression instead of collecting it in a string if possible.
 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using:

<netui:content value="<% out.print(dataBind); %>"/>
 
dahood shaikh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
:-) it shows nothing now !

its displaying empty space on the page.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a classic example of why scriptlets are discouraged these days.

It's far easier to debug the code when it's in a Java class object instead of a scriptlet.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot mix the EL with scriptlets. Ditch the obsolete scriptlets.
 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the EL Expression could just be: ${pageFlow.groupMap[groupId]} ??

And all of that scriptlet code could be replaced with just:


 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stefan Evans wrote:And all of that scriptlet code could be replaced with just:



So much better!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic