Hi,

After reading about how to make taglibs, I can't fathom how I can make what I 
want to do even afer consulting some tutorials.

I have a logic:iterate on a Map. let say that the object name obj is taken out 
of the Map. I use obj inside the logic:iterate to get the key and value of each 
obj without a problem.

Now, what I need to do is to use the obj's key on another Map in the form 
object which would be easy if I had control over the session and request object 
and was using normal jsp programming but I have no idea how to do so with 
struts using taglibs.

I had the idea of doing it by creating my own taglib but I didn't manage to do 
it even after consulting some tutorials.

I started with this tag configuration in mind:
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/fetch.tld" prefix="fetch" %>

<logic:iterate id="obj" name="PandoraForm" property="treeMap">
<fetch:item name="PandoraForm" property="hashMap">
<bean:write name="obj" property="key"/>
</fetch:item>
</logic:iterate>

PandoraForm is the form object.
hashMap is a property of type HashMap in PandoraForm.

The tag is supposed to print out the String value for obj's key in hashMap, obj 
come from treeMap.

I made this tld:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd";>
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>fetch</short-name>
<tag>
<name>valeur</name>
<tag-class>FetchValueIntoMap</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>name</name>
<required>true</required>
</attribute>
<attribute>
<name>property</name>
<required>true</required>
</attribute>
</tag>
</taglib>

now, assuming that it's good until now, I have trouble making my class, What I 
have now is this:

import javax.servlet.jsp.tagext.*;
import java.util.*;

public class FetchValueIntoMap extends BodyTagSupport{
private ??? property;
private ??? name;

private static final long serialVersionUID = 1L;

public int doAfterBody(){
System.out.println(property);
System.out.println(name);

String label = "";
BodyContent body = getBodyContent();
String key = body.getString();
System.out.println(key);
//will loop over the Map if I can get it
try{
body.getEnclosingWriter().println(label);
}
catch(Exception ex){
ex.printStackTrace();
}
return EVAL_PAGE;
}

public ??? getName(){
return name;
}
public void setName(??? name){
this.name = name;
}
public ??? getProperty(){
return property;
}
public void setProperty(??? property){
this.property = property;
}
}

Any idea how I can make this freak tag to work?
Thanks

Reply via email to