You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Krishna Kottamasu <kk...@workforcesoftware.com> on 2004/04/12 22:12:18 UTC

Java scriplets inside veltags

Hello,

 

I'm trying to include java scriplets inside veltags in my jsp and the
scriplets are not getting evaluated.  I'm using Tomcat 5.0.1.9 and
Velocity 1.3.1-rc2.

 

My JSP looks something like this:

 

<%@ page language="java" %>

<%@ taglib uri="/WEB-INF/veltag.tld" prefix="vel" %>

 

<html>

<head>

  <title>Create Time Off Request</title>

  <vel:velocity strictaccess="true" >

    #set ( $trSession = $scopetool.getSessionScope("<%=
TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME%>") )

  </vel:velocity>

</head>

<body>

</body>

</html>

 

I looked in the compiled java source code for this jsp in Tomcat's work
directory and it looks like this:

 

out.write("    #set ( $trSession = $scopetool.getSessionScope(\"<%=
TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME%>\") )\r\n");

 

I'd expect it to look something like this instead:

 

out.write("    #set ( $trSession = $scopetool.getSessionScope(\"");

out.print( TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME);

out.write("\") )\r\n");

 

In the above jsp, if I replace the <%=
TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME%> with the actual
string value of that static variable, then $trSession has the reference
to the object in the session.  Also, I tried printing the value of
TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME outside the
<vel:velocity> tag and it works fine.  I don't understand why a standard
java scriplet wouldn't work from inside a <vel:velocity> tag.

 

I didn't have this problem with Tomcat 3.2.4.

 

Please advice.

 

Thanks in advance.

 

--Krishna Kottamasu

 

 

 

 


RE: Java scriplets inside veltags

Posted by Krishna Kottamasu <kk...@workforcesoftware.com>.
Thanks Tim for the response.  One of the other developers here was able
to do some research and we were able to solve this problem by setting
    <bodycontent>JSP</bodycontent>
in veltag.tld

The article http://www.onjava.com/pub/a/onjava/2001/01/18/jsptags.html
was somewhat helpful.

The following is an extract from it:

"First the tag definition in the TLD file needs to set <bodyContent> to
either JSP or tagdependent. JSP indicates that the body is evaluated by
the JSP container and then is possibly processed by the tag itself.
Tagdependent indicates that the body is only processed by the tag."

--Krishna


> This is how the java snippet is in Tomcat 3.x:
...
> I'm using Tomcat 5.0.1.9 and Velocity 1.3.1-rc2.

If I recall correctly, we had the same issue when moving from TC3 to
4... i.e. the Servlet specification changed between them. And some of
the Veltags stopped working (not many, because scriptlets are bad, evil,
and just not something you really want to do because your Mom told you
it was naughty). I seem to recall that veltag implemented tagbody
'incorrectly' according to the newer Servlet specification. 

Sorry, not too much to go on, but hope that leads you in the right
direction. ;-)

Timo


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


RE: Java scriplets inside veltags

Posted by Tim Colson <tc...@cisco.com>.
> This is how the java snippet is in Tomcat 3.x:
...
> I'm using Tomcat 5.0.1.9 and Velocity 1.3.1-rc2.

If I recall correctly, we had the same issue when moving from TC3 to
4... i.e. the Servlet specification changed between them. And some of
the Veltags stopped working (not many, because scriptlets are bad, evil,
and just not something you really want to do because your Mom told you
it was naughty). I seem to recall that veltag implemented tagbody
'incorrectly' according to the newer Servlet specification. 

Sorry, not too much to go on, but hope that leads you in the right
direction. ;-)

Timo


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


RE: Java scriplets inside veltags

Posted by Krishna Kottamasu <kk...@workforcesoftware.com>.
Thanks for the response.

This is how the java snippet is in Tomcat 3.x:

out.write("    #set ( $trSession = $scopetool.getSessionScope(\"");
out.print( TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME);
out.write("\") )\r\n");

Thanks,
Krishna

On Apr 12, 2004, at 4:12 PM, Krishna Kottamasu wrote:

> Hello,
>
> I'm trying to include java scriplets inside veltags in my jsp and the
> scriplets are not getting evaluated.  I'm using Tomcat 5.0.1.9 and
> Velocity 1.3.1-rc2.
>
> My JSP looks something like this:
>

[SNIP]

>   <vel:velocity strictaccess="true" >
>
>     #set ( $trSession = $scopetool.getSessionScope("<%=
> TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME%>") )
>
>   </vel:velocity>
>

[SNIP]

>
> I looked in the compiled java source code for this jsp in Tomcat's
work
> directory and it looks like this:
>
>
>
> out.write("    #set ( $trSession = $scopetool.getSessionScope(\"<%=
> TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME%>\") )\r\n");
>
>

I'm surprised - I would have thought that instead of an out.write() of 
the vel content, it would just defer the execution of that tag to 
veltag.  What does the .java look like under tomcat 3.x?


>
> I'd expect it to look something like this instead:
>
>
>
> out.write("    #set ( $trSession = $scopetool.getSessionScope(\"");
>
> out.print( TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME);
>
> out.write("\") )\r\n");
>
> In the above jsp, if I replace the <%=
> TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME%> with the actual
> string value of that static variable, then $trSession has the
reference
> to the object in the session.  Also, I tried printing the value of
> TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME outside the
> <vel:velocity> tag and it works fine.  I don't understand why a 
> standard
> java scriplet wouldn't work from inside a <vel:velocity> tag.
>
>
>
> I didn't have this problem with Tomcat 3.2.4.
>


-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Java scriplets inside veltags

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Apr 12, 2004, at 4:12 PM, Krishna Kottamasu wrote:

> Hello,
>
> I'm trying to include java scriplets inside veltags in my jsp and the
> scriplets are not getting evaluated.  I'm using Tomcat 5.0.1.9 and
> Velocity 1.3.1-rc2.
>
> My JSP looks something like this:
>

[SNIP]

>   <vel:velocity strictaccess="true" >
>
>     #set ( $trSession = $scopetool.getSessionScope("<%=
> TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME%>") )
>
>   </vel:velocity>
>

[SNIP]

>
> I looked in the compiled java source code for this jsp in Tomcat's work
> directory and it looks like this:
>
>
>
> out.write("    #set ( $trSession = $scopetool.getSessionScope(\"<%=
> TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME%>\") )\r\n");
>
>

I'm surprised - I would have thought that instead of an out.write() of 
the vel content, it would just defer the execution of that tag to 
veltag.  What does the .java look like under tomcat 3.x?


>
> I'd expect it to look something like this instead:
>
>
>
> out.write("    #set ( $trSession = $scopetool.getSessionScope(\"");
>
> out.print( TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME);
>
> out.write("\") )\r\n");
>
> In the above jsp, if I replace the <%=
> TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME%> with the actual
> string value of that static variable, then $trSession has the reference
> to the object in the session.  Also, I tried printing the value of
> TimeoffRequestAction.TIMEOFF_REQUEST_SESSION_NAME outside the
> <vel:velocity> tag and it works fine.  I don't understand why a 
> standard
> java scriplet wouldn't work from inside a <vel:velocity> tag.
>
>
>
> I didn't have this problem with Tomcat 3.2.4.
>


-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org