You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Clay Graham <cy...@best.com> on 2001/09/07 21:14:06 UTC

Nesting Tags (Again)

John,

So I tried your cool eval approach but the JSP page seems to no be able to 
find the string once I have placed it in the page context using the eval 
tag.

Here's my implementation of the eval tag...

public class EvalBody extends BodyTagSupport {
    private String id;

      /* 1) At the end of the tag this function gets called. */
    public int doEndTag() throws JspTagException
    {
    try
    {   /* 2) Get the text within the tag. */
        BodyContent l_tagbody = getBodyContent();
        String ls_output = "";

        /* 3) If text was in the tag body then process it. */
        if(l_tagbody != null)
        {
            String ls_html_text = l_tagbody.getString();
            pageContext.setAttribute(id, ls_html_text);

	//this is to verify that I am setting the property...
            ls_output="body text:"+ls_html_text+" id:"+id;
        }
        /* 4) Write the result back to output stream */
        pageContext.getOut().write(ls_output.trim());
    }
    catch (IOException e)
    {
        throw new JspTagException("Tag Error:" + e.toString());
    }

/* Have the JSP Container continue the JSP page as normal. */
    return EVAL_PAGE;
    }

    public void setId(String as_id)
    {
       id=as_id;
    }

}


here's my JSP page code...

       <!-- you need to handel the null case-->
        <logic:iterate id="contextBean" name="ContextMgr" 
property="contexts">
          <tr>
            <td><strong><bean:write name="contextBean" 
property="name"/></strong></td>
            <td><strong><bean:write name="contextBean" 
property="description"/></strong></td>
            <td>
                <utility:EvalBody id='contextName'><bean:write 
name="contextBean" property="name"/></utility:EvalBody>
                <%String fullUrl="viewcontext.do?name="+contextName;%>
                <strong><html:link href="<%=fullUrl%>">goto 
context</html:link></strong>
            </td>
          </tr>
        </logic:iterate>

and it fails to find the attribute on the page, here's the error...

org.apache.jasper.JasperException: Unable to compile class for 
JSPC:\tc3.2.3\work\localhost_8080%2Fcontextuon\_0002fcontextmgr_0002ejsp  
contextmgr_jsp_58.java:525: Undefined variable: contextName String 
fullUrl="viewcontext.do?name="+contextName;

ok so it can't find the attribute even though I put it in the 
pageContext...

wassup?

Clay



-----Original Message-----
From:	John Raley [SMTP:johnr@moonlight.com]
Sent:	Wednesday, September 05, 2001 2:11 PM
To:	struts-user@jakarta.apache.org
Subject:	Re: Quick question (nesting tags)

Check out
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg14326.html

Clay Graham wrote:

>can you give a more verbose example of how you would do this?
>
>I would like to do this too.
>
>the exact syntax is important, I cant seem to make it work.
>
>-----Original Message-----
>From:	John Raley [SMTP:johnr@moonlight.com]
>Sent:	Wednesday, September 05, 2001 12:08 PM
>To:	struts-user@jakarta.apache.org
>Subject:	Re: Quick question (nesting tags)
>
>Everyone wants to do this.  Unfortunately JSP syntax doesn't allow it.
> The best you can do in a tag attribute is a scriptlet (<%= ... %>).
>
>Greg Lehane wrote:
>
>>Hello all,
>>
>>
>> In my JSP I'm iterating through a vector I've stored in my ActionForm
>>bean, I write out information from the vector to the JSP and the end
>>result is a populated table on the JSP. What I would like to do is add a
>>form to each row on the table (as I iterate through), however, I need to
>>grab info from the form in order to populate the action= part of the
>><html:form ...> tag.
>>
>> So, I attempt to write something like this for each iteration:
>>
>>   <html:form action="/browseRec?action=open&recset=<bean:write
>>name="resultSetVO" property="title" filter="true"/>"> <html:submit
>>property="submit" value="open"/>
>>
>> However, compilation throws up a "Non matching extension tags error"
>>on the JSP. Presumably because have the nested <bean:write ...> tag.
>>
>> I know that this nesting works using regular HTML, but I would rather
>>use the custom tags. Hopefully this simply involves adding commas or
>>something!
>>
>> Thanks,
>>
>>- Greg
>>
>>----------------------------------------------
>>Greg Lehane
>>Software Developer
>>H5 Technologies Inc.
>>520 3rd St. No 17
>>San Francisco, CA 94107
>>415.625.6701 ext. 610 (direct)
>>415.625.6799 (fax)
>>glehane@h5technologies.com
>>
>>
>
>
>
>




Re: Nesting Tags (Again)

Posted by John Raley <jo...@moonlight.com>.
You're almost there.  The content is in your page context;  the problem 
is your tag doesn't declare a scripting variable. You have three choices:
1) Write a TagExtraInfo class for your eval tag that declares the 
variable.  Don't forget the <teiclass> element in your .tld!
2) Use the struts bean:define tag to declare the variable.
3)  Change your code to:

<%String fullUrl="viewcontext.do?name="+pageContext.getAttribute("contextName");%>

I'd go with 2.

Clay Graham wrote:

>John,
>
>So I tried your cool eval approach but the JSP page seems to no be able to 
>find the string once I have placed it in the page context using the eval 
>tag.
>
>Here's my implementation of the eval tag...
>
>public class EvalBody extends BodyTagSupport {
>    private String id;
>
>      /* 1) At the end of the tag this function gets called. */
>    public int doEndTag() throws JspTagException
>    {
>    try
>    {   /* 2) Get the text within the tag. */
>        BodyContent l_tagbody = getBodyContent();
>        String ls_output = "";
>
>        /* 3) If text was in the tag body then process it. */
>        if(l_tagbody != null)
>        {
>            String ls_html_text = l_tagbody.getString();
>            pageContext.setAttribute(id, ls_html_text);
>
>	//this is to verify that I am setting the property...
>            ls_output="body text:"+ls_html_text+" id:"+id;
>        }
>        /* 4) Write the result back to output stream */
>        pageContext.getOut().write(ls_output.trim());
>    }
>    catch (IOException e)
>    {
>        throw new JspTagException("Tag Error:" + e.toString());
>    }
>
>/* Have the JSP Container continue the JSP page as normal. */
>    return EVAL_PAGE;
>    }
>
>    public void setId(String as_id)
>    {
>       id=as_id;
>    }
>
>}
>
>
>here's my JSP page code...
>
>       <!-- you need to handel the null case-->
>        <logic:iterate id="contextBean" name="ContextMgr" 
>property="contexts">
>          <tr>
>            <td><strong><bean:write name="contextBean" 
>property="name"/></strong></td>
>            <td><strong><bean:write name="contextBean" 
>property="description"/></strong></td>
>            <td>
>                <utility:EvalBody id='contextName'><bean:write 
>name="contextBean" property="name"/></utility:EvalBody>
>                <%String fullUrl="viewcontext.do?name="+contextName;%>
>                <strong><html:link href="<%=fullUrl%>">goto 
>context</html:link></strong>
>            </td>
>          </tr>
>        </logic:iterate>
>
>and it fails to find the attribute on the page, here's the error...
>
>org.apache.jasper.JasperException: Unable to compile class for 
>JSPC:\tc3.2.3\work\localhost_8080%2Fcontextuon\_0002fcontextmgr_0002ejsp  
>contextmgr_jsp_58.java:525: Undefined variable: contextName String 
>fullUrl="viewcontext.do?name="+contextName;
>
>ok so it can't find the attribute even though I put it in the 
>pageContext...
>
>wassup?
>
>Clay
>