File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Custom Tags( using Jdeveloper ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Custom Tags( using Jdeveloper )" Watch "Custom Tags( using Jdeveloper )" New topic
Author

Custom Tags( using Jdeveloper )

Ranadhir Nag
Ranch Hand

Joined: Mar 09, 2006
Posts: 138
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?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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 ]

[My Blog]
All roads lead to JavaRanch
Ranadhir Nag
Ranch Hand

Joined: Mar 09, 2006
Posts: 138
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

Joined: Nov 24, 2005
Posts: 14687
    
  16


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

Joined: Mar 09, 2006
Posts: 138
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom Tags( using Jdeveloper )