Received the following errors while compiling:
========
compile:
[javac] Compiling 2 source files to
D:\VelocitySource\jakarta-velocity\contrib\temporary\veltag\target\class
es
[javac]
D:\VelocitySource\jakarta-velocity\contrib\temporary\veltag\src\java\org
\apache\taglibs\velocity\JSPContext.java:41: cannot resolve symbol
[javac] symbol : constructor ChainedContext
(<nulltype>,javax.servlet.ServletRequest,javax.servlet.ServletResponse,j
avax.servlet.ServletContext)
[javac] location: class
org.apache.velocity.tools.view.context.ChainedContext
[javac] super(null,
[javac] ^
[javac]
D:\VelocitySource\jakarta-velocity\contrib\temporary\veltag\src\java\org
\apache\taglibs\velocity\VelocityTag.java:185: cannot resolve symbol
[javac] symbol : variable TOOLBOX_KEY
[javac] location: class org.apache.taglibs.velocity.VelocityTag
[javac] String file = config.getInitParameter(TOOLBOX_KEY);
[javac] ^
[javac]
D:\VelocitySource\jakarta-velocity\contrib\temporary\veltag\src\java\org
\apache\taglibs\velocity\VelocityTag.java:190: cannot resolve symbol
[javac] symbol : variable TOOLBOX_KEY
[javac] location: class org.apache.taglibs.velocity.VelocityTag
[javac] file =
servletContext.getInitParameter(TOOLBOX_KEY);
[javac] ^
=============
I had to add a couple of import statements in the VelocityTag.java and
fix a semi-colon. I will send out the final code once I have tested it.
I have the following in the lib directory:
velocity-1.4-rc1.jar
velocity-tools-1.1-rc1.jar
velocity-tools-generic-1.1-rc1.jar
velocity-tools-view-1.1-rc1.jar
Servlet.jar
Thanks,
-AG
-----Original Message-----
From: Nathan Bubna [mailto:[EMAIL PROTECTED]
Sent: Friday, April 16, 2004 12:44 PM
To: Velocity Users List
Subject: Re: More Veltag questions...
Nathan Bubna said:
> i've attached hastily thrown together versions of VelocityTag and
> JSPContext that ought to do the trick. i think this code should work,
> but i actually haven't even tried to compile this code yet, much less
> run it. hopefully it'll give an idea of what needs to happen before
> things like MessageTool work.
of course, the mailing list has decided to strip the files off. argh.
seriously, who configures a java software mailing list to swallow *.java
attachments?
here they are again...
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.taglibs.velocity;
import java.io.Reader;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.ServletContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.context.Context;
import org.apache.velocity.tools.view.ToolboxManager;
import org.apache.velocity.tools.view.servlet.ServletToolboxManager;
/**
* <p>
* Simple implementation of JSP tag to allow
* use of VTL in JSP's.
* </p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id: VelocityTag.java,v 1.1 2001/08/14 00:07:39 geirm Exp $
*/ public class VelocityTag implements BodyTag {
protected Tag parent = null;
protected BodyContent bodyContent = null;
protected PageContext pageContext = null;
private ToolboxManager toolboxManager = null;
/*
* strictaccess : determines if the JSPContext is used
* to autofetch information from the 'scopes'
* or if the scopetool() is used
*/
protected boolean strictAccess = false;
/**
* CTOR : current implementation uses the Singleton
* model for velocity.
*/
public VelocityTag()
{
try
{
Velocity.init();
}
catch(Exception e)
{
System.out.println("VelocityTag() : " + e );
}
}
/**
* switch for strictaccess
*
* @param sa if true, then normal VelocityContext is used
* and template must directly get beans from scopes
* Otherwise, the JSPContext is used which searches for
* objects/beans in the scopes automatically.
*/
public void setStrictaccess( boolean sa )
{
this.strictAccess = sa;
}
public Tag getParent()
{
return parent;
}
public void setParent( Tag parent)
{
this.parent = parent;
return;
}
public int doStartTag()
throws JspException
{
return EVAL_BODY_TAG;
}
public void setBodyContent( BodyContent bc )
{
this.bodyContent = bc;
return;
}
public void setPageContext( PageContext pc )
{
this.pageContext = pc;
return;
}
public void doInitBody()
throws JspException
{
return;
}
public int doAfterBody()
throws JspException
{
return 0;
}
public void release()
{
return;
}
/**
* This is the real worker for this taglib.
* There are efficiencies to be added - the plan
* is to cache the AST to avoid reparsing every
* time.
*/
public int doEndTag()
throws JspException
{
/*
* if there is no body, we are done
*/
if ( bodyContent == null)
return EVAL_PAGE;
try
{
JspWriter writer = pageContext.getOut();
/* get our body */
Reader bodyreader = bodyContent.getReader();
/* setup/retrieve the toolbox */
initToolbox(pageContext.getServletConfig());
/* now make a Context */
Context vc = createContext()
Velocity.evaluate( vc , writer, "JSP for me!", bodyreader );
}
catch( Exception e )
{
System.out.println( e.toString() );
}
return EVAL_PAGE;
}
/**
* Initializes the ServletToolboxManager for this servlet's
* toolbox (if any).
*
* @param config servlet configuation
*/
protected void initToolbox(ServletConfig config) throws
ServletException
{
ServletContext servletContext = config.getServletContext();
/* check the servlet config for a toolbox */
String file = config.getInitParameter(TOOLBOX_KEY);
/* check the servlet context for a toolbox */
if (file == null || file.length() == 0)
{
file = servletContext.getInitParameter(TOOLBOX_KEY);
}
/* if we have a toolbox, get a manager for it */
if (file != null)
{
toolboxManager =
ServletToolboxManager.getInstance(servletContext, file);
}
else
{
Velocity.info("No toolbox entry in configuration.");
}
}
protected Context createContext() {
/*
* if strictAccess == true, then we want to use a regular
* VelocityContext, as we assume that the template will
* bring into the context any beans using the scope tool
* or the like
*/
if (strictAccess)
{
Context vc = new VelocityContext();
/*
* add the scope tool
*/
vc.put("scopetool", new ScopeTool(pageContext));
}
else
{
JSPContext ctx = new JSPContext(pageContext);
/* if we have a toolbox manager, get a toolbox from it */
if (toolboxManager != null)
{
ctx.setToolbox(toolboxManager.getToolboxContext(ctx));
}
return ctx;
}
}
}
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.taglibs.velocity;
import javax.servlet.jsp.PageContext;
import org.apache.velocity.tools.view.context.ChainedContext;
/**
* <p>
* Velocity Context implementationfor use in JSP's,
* where the servlet API 'scope' is used directly.
* </p>
* <p>
* This context will 'search' the scopes looking for an
* item, working outwards
* page->request->session->application
* </p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @version $Id: JSPContext.java,v 1.1 2001/08/14 00:07:39 geirm Exp $
*/ public class JSPContext extends ChainedContext {
private PageContext pageContext = null;
public JSPContext(PageContext pageContext)
{
super(null,
pageContext.getRequest(),
pageContext.getResponse(),
pageContext.getServletContext());
this.pageContext = pageContext;
}
public Object getAttribute(String key)
{
Object o = pageContext.getAttribute(key,
PageContext.PAGE_SCOPE);
if (o == null)
{
o = super.getAttribute(key);
}
return o;
}
}
---------------------------------------------------------------------
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]