• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Custom Tags( using Jdeveloper )  RSS feed

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a custom tag with body ,which populates a map.
The doAfterbody juast parses the body and populates the map

.....
......
BodyContent bodyContent = getBodyContent();
String bodyString = bodyContent.getString();
bodyContent.clearBody();

int start=bodyString.indexOf("{");
int end=bodyString.indexOf("}");

String mapContent = bodyString.substring(start+1,end);
/* Parse the entries in the map */
StringTokenizer token = new StringTokenizer(mapContent,"=;, \t\r\n");
while(token.hasMoreTokens()){
......
map.put(key,value);
}
this.pageContext.setAttribute(id,map);
.....
......

The tag definition in the TLD is

<tag>
<name>MapParseTag</name>
<tag-class>mypackage4.MapParseTag</tag-class>
<tei-class>mypackage4.MapParseTagTEI</tei-class>
<body-content>JSP</body-content>
<display-name>MapParseTag</display-name>
<description>A short description...</description>
<attribute>
<name>id</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<example>Brief snippet showing how to use this tag.</example>
</tag>

I cant compile the client JSP with the following code

</head>
<body>
<taglibPrefix1:MapParseTag id="employee1">
{
firstName=Jennifer,
lastName=Wirth,
age=33
}
</taglibPrefix1:MapParseTag>
<br>
the employee is <%=employee1%>
</br>
</body>
</html>

It says variable employee1 not recognized.What should i do?
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the employee is ${employee1}

(which will call Map.ToString so that's probably not what you want to do)
[ March 09, 2006: Message edited by: Satou kurinosuke ]
 
Ranadhir Nag
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i make that change ,I get the html output as

the employee is ${employee1}

rather than the content of the map ; What I want is the dump of the contents of the map.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If i make that change ,I get the html output as
the employee is ${employee1}


EL is not enabled. You're probably using version 2.3 of web.xml.
There are a few ways to enable EL, one of them is to set web.xml version to 2.4 :

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app 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-app_2_4.xsd"
version="2.4">

</web-app>


If you don't want to do this, I think that you can get the map by doing
<% java.util.Map mymap = (java.util.Map)pageContext.getAttribute("employee1"); %>
<%= mymap %>
[ March 09, 2006: Message edited by: Satou kurinosuke ]
 
Ranadhir Nag
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the scriptlet option - and it worked perfectly.
But when i use a tag without body support in my JSP as follows :

<taglibPrefix1:MapDefineTag id="employee" type="hash" scope="page">
<%
employee.put("firstName", "Kiley");
employee.put("lastName", "Hightower");
employee.put("age", new Integer(33));
employee.put("salary", new Float(22.22));
%>
<br>
The employee is <%=employee%>
</br>
</taglibPrefix1:MapDefineTag>

it works perfectly.Why do i then need to do an explicit getAttribute in this case?

Thanks a lot for the advice in any case.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!