I don't know what this <c: tag is for but I'd rather make it work with bean, html, logic and this custom tag of mine. It's not just a matter of making it work, it's also a matter of learning how to make a taglib and also because the whole page is made of those taglibs.

I simplified it to keep the bare minimum for what I really need now.

fetch.tld is

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_1.dtd";>
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>fetch</shortname>
<tag>
<name>valeur</name>
<tagclass>FetchValue</tagclass>
<bodycontent>JSP</bodycontent>
</tag>
</taglib>

I took the info from the bean tld so it should be correct

the class FetchValue is:
import javax.servlet.jsp.tagext.*;

public class FetchValue extends BodyTagSupport{
private static final long serialVersionUID = 1L;

public int doAfterBody(){
 BodyContent body = getBodyContent();
 String label = body.getString();
 System.out.println(label);
 try{
  body.getEnclosingWriter().println(label);
 }
 catch(Exception ex){
  ex.printStackTrace();
 }
 return EVAL_PAGE;
}
}

the jsp page for what I need is:
<%@ 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="mot" name="PandoraForm" property="motTreeMap">
  <fetch:valeur>
     <bean:write name="mot" property="value"/>
  </fetch:valeur>
</logic:iterate>
...

I get this error:
org.apache.jasper.JasperException: Unable to compile class for JSP

Thanks
From: "Eric Plante" <[EMAIL PROTECTED]>

> 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
>
> The tag is supposed to print out the String value for obj's key in
> hashMap, obj come from treeMap.

So your form has two Maps that are keyed alike?  I don't think you need a
custom tag (or Struts tags) at all. This iterates over a treeMap and uses
the key of each 'obj' as the key into a hashMap:

<c:forEach items="${treeMap}" var="obj" >
  ${hashMap[obj.key]}
</c:forEach>

That's with the Maps in request scope... if they're coming from the form
bean, it would be items="${formBeanName.treeMap}" (assuming there is a
getTreeMap method on your form bean.)

The above also assumes JSTL 1.1.  If you're using JSTL 1.0 you'd need a
<c:out value="..." /> in the
middle rather than just the expression.

Here's the JSP I was using to play with this:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>

<%
  java.util.TreeMap treeMap = new java.util.TreeMap();
  treeMap.put( "key1", "value1" );
  treeMap.put( "key2", "value2" );
  request.setAttribute( "treeMap", treeMap );

  java.util.HashMap hashMap = new java.util.HashMap();
  hashMap.put( "value1", "description1" );
  hashMap.put( "value2", "description2" );
  hashMap.put( "key1",   "descByKey1" );
  hashMap.put( "key2",   "descByKey2" );
  request.setAttribute( "hashMap", hashMap );
%>


<c:forEach items="${treeMap}" var="obj" >
  ${hashMap[obj.value]}
</c:forEach>

<hr/>

<c:forEach items="${treeMap}" var="obj" >
  ${hashMap[obj.key]}
</c:forEach>

If you need help adding JSTL to your webapp, just ask.  (We need to know
what version of the Servlet specification you're working with-- Servlet
2.4
(Tomcat 5.x) or something else?)

HTH,
--
Wendy Smoak






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
----- Original Message ----- From: "Wendy Smoak" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Sunday, October 23, 2005 12:05 PM
Subject: Re: Problems with custom taglibs


From: "Eric Plante" <[EMAIL PROTECTED]>

> 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
>
> The tag is supposed to print out the String value for obj's key in
> hashMap, obj come from treeMap.

So your form has two Maps that are keyed alike?  I don't think you need a
custom tag (or Struts tags) at all. This iterates over a treeMap and uses
the key of each 'obj' as the key into a hashMap:

<c:forEach items="${treeMap}" var="obj" >
  ${hashMap[obj.key]}
</c:forEach>

That's with the Maps in request scope... if they're coming from the form
bean, it would be items="${formBeanName.treeMap}" (assuming there is a
getTreeMap method on your form bean.)

The above also assumes JSTL 1.1.  If you're using JSTL 1.0 you'd need a
<c:out value="..." /> in the
middle rather than just the expression.

Here's the JSP I was using to play with this:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>

<%
  java.util.TreeMap treeMap = new java.util.TreeMap();
  treeMap.put( "key1", "value1" );
  treeMap.put( "key2", "value2" );
  request.setAttribute( "treeMap", treeMap );

  java.util.HashMap hashMap = new java.util.HashMap();
  hashMap.put( "value1", "description1" );
  hashMap.put( "value2", "description2" );
  hashMap.put( "key1",   "descByKey1" );
  hashMap.put( "key2",   "descByKey2" );
  request.setAttribute( "hashMap", hashMap );
%>


<c:forEach items="${treeMap}" var="obj" >
  ${hashMap[obj.value]}
</c:forEach>

<hr/>

<c:forEach items="${treeMap}" var="obj" >
  ${hashMap[obj.key]}
</c:forEach>

If you need help adding JSTL to your webapp, just ask.  (We need to know
what version of the Servlet specification you're working with-- Servlet
2.4
(Tomcat 5.x) or something else?)

HTH,
--
Wendy Smoak






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to