wood burning stoves 2.0*
The moose likes JSP and the fly likes EL with in scriptlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "EL with in scriptlet" Watch "EL with in scriptlet" New topic
Author

EL with in scriptlet

dahood shaikh
Greenhorn

Joined: Nov 27, 2012
Posts: 7
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

Joined: Aug 30, 2012
Posts: 90
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

Joined: Nov 27, 2012
Posts: 7
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

Joined: Aug 30, 2012
Posts: 90
That means its treating $ as a string.

Try making use of escape sequence for $ like:
String dataBind = "\${pageFlow.groupMap['" + groupId + "']}";
dahood shaikh
Greenhorn

Joined: Nov 27, 2012
Posts: 7
:-( 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

Joined: Aug 30, 2012
Posts: 90
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

Joined: Aug 30, 2012
Posts: 90
Try using:

<netui:content value="<% out.print(dataBind); %>"/>
dahood shaikh
Greenhorn

Joined: Nov 27, 2012
Posts: 7
:-) it shows nothing now !

its displaying empty space on the page.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

You cannot mix the EL with scriptlets. Ditch the obsolete scriptlets.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
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

Joined: Jan 10, 2002
Posts: 61433
    
  67

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


So much better!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL with in scriptlet