• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL with in scriptlet

 
dahood shaikh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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>
 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Try using:

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

its displaying empty space on the page.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot mix the EL with scriptlets. Ditch the obsolete scriptlets.
 
Stefan Evans
Bartender
Posts: 1691
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:And all of that scriptlet code could be replaced with just:


So much better!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic