You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Andrea Gianni <a....@infogroup.it> on 2001/07/04 15:31:43 UTC

use JSP Tags and jsp variable

Hi

1^ Problem :

I tryed this

<MT:MiaTagLibrary initValue="<%=initValues%>" >
         <jsp:include page="pp.jsp" />
</MT:MiaTagLibrary>

The tagLib write on the page "The content of tag is [body content]" so I 
had expected

"The content of the body is This is the pp page"

But I obtain

"This is the pp page the content of the body is"

Like first the jsp tag is elaborated and the the tag lib that so has the
body empity.

I am making some errors ?


2^ Problem

how I can read in a tagLib a Java variable defined in a jsp Page directly ?
I think that I can use pageContext(<name of the variable>, 1); but don't work.


A.G.



*******************************
Ing. Andrea Gianni
Software Engineer
Gruppo Monetica e Servizi
Area Internet Professional
Infogroup S.p.a.
Via delle Panche, 140
50141 Firenze
Tel. 055.436.5647
Fax. 055.436.5735
e-mail a.gianni@infogroup.it


RE: use JSP Tags and jsp variable

Posted by Stefan HÃ¥kans <st...@ibfs.com>.
Since you are fetching the String by using pageContext.getAttribute,
you must have set it on the jsp-page with pageContext.setAttribute.

Note that if no scope is specified it implies page scope.

/Steff

-----Original Message-----
From: Andrea Gianni [mailto:a.gianni@infogroup.it]
Sent: den 5 juli 2001 09:12
To: taglibs-user@jakarta.apache.org
Subject: Re: use JSP Tags and jsp variable


At 10.37 04/07/01 -0400, you wrote:
>Andrea Gianni wrote:
>
>>Hi
>>1^ Problem :
>>I tryed this
>><MT:MiaTagLibrary initValue="<%=initValues%>" >
>>         <jsp:include page="pp.jsp" />
>></MT:MiaTagLibrary>
>
>can i see your code in MiaTagLibrary
Here the code, what I don't understand is that If I put iside my tag a
static String al works

public class MiaTagLibrary extends BodyTagSupport {

     static int cont =0;
     private String initValue="-1";
     /** Creates new MiaTagLibrary */
     public MiaTagLibrary()
     {
     }

     public void setInitValue(String nval)
     {initValue=nval;}

     public String getInitValue()
     {return(initValue);}


     public int doStartTag()
     {
         try
         {

         // Here I search barba, a String defined in the jsp


pageContext.getOut().print("----------------------"+pageContext.getAttribute
("barba",PageContext.PAGE_SCOPE)+"<br>");


         }
         catch(Exception e)
         {e.printStackTrace();}

         return EVAL_BODY_TAG;
     }

     public int doAfterBody() throws JspTagException
     {
         try
         {


             BodyContent bc = getBodyContent();
             String corpo = "vuoto";
             if (bc!=null)
              corpo= bc.getString();
             getPreviousOut().print("Il tag ha corpo "+corpo);

         }
         catch(Exception e)
         {e.printStackTrace();}
         return SKIP_BODY;
     }

    public int doEndTag()
    {
         return EVAL_PAGE;
    }
}



>>2^ Problem
>>how I can read in a tagLib a Java variable defined in a jsp Page directly
?
>>I think that I can use pageContext(<name of the variable>, 1); but don't
>>work.
>
>
>use TagExtraInfo.

Sorry I don't understand, I have a JSP like this

<%
         String barba="pippo";
         String p2="pluto";
...
%>

and I want to read these variables in my tag ( by the way I need to access
all the variables defined in the jsp without knowing them ), how the
tagExtraInfo should be written ? ( all examples I read talk about the
opposite problem, put a tag variable into jsp ).

Thanks

A.G.

*******************************
Ing. Andrea Gianni
Software Engineer
Gruppo Monetica e Servizi
Area Internet Professional
Infogroup S.p.a.
Via delle Panche, 140
50141 Firenze
Tel. 055.436.5647
Fax. 055.436.5735
e-mail a.gianni@infogroup.it



Re: use JSP Tags and jsp variable

Posted by Andrea Gianni <a....@infogroup.it>.
At 10.37 04/07/01 -0400, you wrote:
>Andrea Gianni wrote:
>
>>Hi
>>1^ Problem :
>>I tryed this
>><MT:MiaTagLibrary initValue="<%=initValues%>" >
>>         <jsp:include page="pp.jsp" />
>></MT:MiaTagLibrary>
>
>can i see your code in MiaTagLibrary
Here the code, what I don't understand is that If I put iside my tag a 
static String al works

public class MiaTagLibrary extends BodyTagSupport {

     static int cont =0;
     private String initValue="-1";
     /** Creates new MiaTagLibrary */
     public MiaTagLibrary()
     {
     }

     public void setInitValue(String nval)
     {initValue=nval;}

     public String getInitValue()
     {return(initValue);}


     public int doStartTag()
     {
         try
         {

         // Here I search barba, a String defined in the jsp

             pageContext.getOut().print("----------------------"+pageContext.getAttribute("barba",PageContext.PAGE_SCOPE)+"<br>"); 


         }
         catch(Exception e)
         {e.printStackTrace();}

         return EVAL_BODY_TAG;
     }

     public int doAfterBody() throws JspTagException
     {
         try
         {


             BodyContent bc = getBodyContent();
             String corpo = "vuoto";
             if (bc!=null)
              corpo= bc.getString();
             getPreviousOut().print("Il tag ha corpo "+corpo);

         }
         catch(Exception e)
         {e.printStackTrace();}
         return SKIP_BODY;
     }

    public int doEndTag()
    {
         return EVAL_PAGE;
    }
}



>>2^ Problem
>>how I can read in a tagLib a Java variable defined in a jsp Page directly ?
>>I think that I can use pageContext(<name of the variable>, 1); but don't 
>>work.
>
>
>use TagExtraInfo.

Sorry I don't understand, I have a JSP like this

<%
         String barba="pippo";
         String p2="pluto";
...
%>

and I want to read these variables in my tag ( by the way I need to access 
all the variables defined in the jsp without knowing them ), how the 
tagExtraInfo should be written ? ( all examples I read talk about the 
opposite problem, put a tag variable into jsp ).

Thanks

A.G.

*******************************
Ing. Andrea Gianni
Software Engineer
Gruppo Monetica e Servizi
Area Internet Professional
Infogroup S.p.a.
Via delle Panche, 140
50141 Firenze
Tel. 055.436.5647
Fax. 055.436.5735
e-mail a.gianni@infogroup.it


Re: use JSP Tags and jsp variable

Posted by James Strachan <ja...@yahoo.co.uk>.
Hi Andrea

From: "Andrea Gianni" <a....@infogroup.it>
> I tryed this
>
> <MT:MiaTagLibrary initValue="<%=initValues%>" >
>          <jsp:include page="pp.jsp" />
> </MT:MiaTagLibrary>
>
> The tagLib write on the page "The content of tag is [body content]" so I
> had expected
>
> "The content of the body is This is the pp page"
>
> But I obtain
>
> "This is the pp page the content of the body is"
>
> Like first the jsp tag is elaborated and the the tag lib that so has the
> body empity.
>
> I am making some errors ?

It looks like the <jsp:include> is going to the request OutputStream not the
<MT:MiaTagLibrary> tags body content. This could be due to restrictions in
Servlet 2.2 and JSP 1.1.

Try running your code on Tomcat 4.0 and see if this fixes the problem.
The whole issue of doing <jsp:include> inside a BodyTag has been fixed in
Servlet 2.3 & JSP 1.2.

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Re: use JSP Tags and jsp variable

Posted by franciscallo <fr...@thefrancis.net>.
Andrea Gianni wrote:

> Hi
> 
> 1^ Problem :
> 
> I tryed this
> 
> <MT:MiaTagLibrary initValue="<%=initValues%>" >
>         <jsp:include page="pp.jsp" />
> </MT:MiaTagLibrary>
> 
> The tagLib write on the page "The content of tag is [body content]" so I 
> had expected
> 
> "The content of the body is This is the pp page"
> 
> But I obtain
> 
> "This is the pp page the content of the body is"
> 
> Like first the jsp tag is elaborated and the the tag lib that so has the
> body empity.
> 
> I am making some errors ?
> 


can i see your code in MiaTagLibrary


> 
> 2^ Problem
> 
> how I can read in a tagLib a Java variable defined in a jsp Page directly ?
> I think that I can use pageContext(<name of the variable>, 1); but don't 
> work.


use TagExtraInfo.

> 
> 
> A.G.
> 
> 
> 
> *******************************
> Ing. Andrea Gianni
> Software Engineer
> Gruppo Monetica e Servizi
> Area Internet Professional
> Infogroup S.p.a.
> Via delle Panche, 140
> 50141 Firenze
> Tel. 055.436.5647
> Fax. 055.436.5735
> e-mail a.gianni@infogroup.it
> 



-- 
Francis Dione V. Callo          __
http://www.thefrancis.net    __|__|__
http://www.fracafican.com     (   )
spam-me@spammemore.net       ( . . )
                              ( ~ )
                                U