[
https://issues.apache.org/jira/browse/VELOCITY-181?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Henning Schmiedehausen closed VELOCITY-181.
-------------------------------------------
> Velocity Template with HTTPRequest object
> -----------------------------------------
>
> Key: VELOCITY-181
> URL: https://issues.apache.org/jira/browse/VELOCITY-181
> Project: Velocity
> Issue Type: Bug
> Components: Build
> Affects Versions: 1.3
> Environment: Operating System: All
> Platform: PC
> Reporter: Sushma
> Assigned To: Velocity-Dev List
>
> Hi,
> I am having a problem with velocity.
> I am using:
> 1. Tomcat version 4.1.18
> 2. velocity-dep-1.3.jar
> 3. Java1.4.0( build 1.4.0-b92)
> 4. Windows 2000.
> I am using velocity template with servlets.
> Problem Description:
> 1.Whenever one of the parameters for a method is HTTPRequest object in the
> velocity template the
> link does not get translated.
> 2.If the method has only HTTPRequest object as the parameter it works.
> 3.But HTTPRequest in combination with other parameters does not seem to work.
> For Example:
> Following DO NOT WORK:
> <h2> <a href="$link.getBrowseURL($request, "A", 1, 15)">REQ + String + Int =
> NOT WORKING</a></h2>
> <h2> <a href="$link.getBrowseURL( "A", 1, 15,$request)">String + Int + REQ =
> NOT WORKING</a></h2>
> <h2> <a href="$link.getBrowseURL( $request,1, 15)">REQ + Integer = NOT
> WORKING</a> </h2>
> Following WORK:
> <h2> <a href="$link.getBrowseURL("A", 1, 15)">String + Int = Working</a> </h2>
> <h2> <a href="$link.getBrowseURL( 1, 15)">Only Integer = WORKING </a> </h2>
> <h2> <a href="$link.getBrowseURL( $request)">Only REQ = WORKING</a> </h2>
> IS this a BUG or mistake on my part.ANY suggestions are welcome.
> THANK YOU
> Sushma
> Following is the code for velocity and servlet.
> +++++++++++++++++++++++++++++homepage3.vm+++++++++++++++++++++++++++++++++++++++
> <html>
> <body>
> <h2> <a href="$link.getBrowseURL($request, "A", 1, 15)"> REQ + String + Int =
> NOT WORKING</a></h2>
> <h2> <a href="$link.getBrowseURL( "A", 1, 15,$request)">String + Int + REQ =
> NOT WORKING</a></h2>
> <h2> <a href="$link.getBrowseURL( $request,1, 15)">REQ + Integer = NOT
> WORKING</a> </h2>
> <h2> <a href="$link.getBrowseURL("A", 1, 15)">String + Int = Working</a> </h2>
> <h2> <a href="$link.getBrowseURL( 1, 15)">Only Integer = WORKING </a> </h2>
> <h2> <a href="$link.getBrowseURL( $request)">Only REQ = WORKING</a> </h2>
> </body>
> </html>
> -----------------------------homepage3.vm---------------------------------------
> +++++++++++++++++++++++++++++WorkingServlet.java++++++++++++++++++++++++++++++++
> import java.text.*;
> import java.util.*;
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import org.apache.velocity.*;
> import org.apache.velocity.app.Velocity;
> import org.apache.velocity.context.Context;
> import org.apache.velocity.runtime.RuntimeSingleton;
> import org.apache.velocity.util.SimplePool;
> import org.apache.velocity.exception.*;
> public class WorkingServlet extends HttpServlet {
> String encoding;
> private SimplePool writerPool = new SimplePool(40);
>
> public void init() throws UnavailableException {
> String prefix = getServletContext().getRealPath("/");
> String file = getInitParameter("velocity-init-file");
> if(file != null) {
> try {
> String propertiesFile = prefix+file;
> String filePath= prefix;
> Properties p = new Properties();
> p.load(new FileInputStream(propertiesFile));
> p.setProperty( Velocity.FILE_RESOURCE_LOADER_PATH, filePath );
> Velocity.init(p);
> encoding = RuntimeSingleton.getString(
> RuntimeSingleton.OUTPUT_ENCODING,
> "ISO-8859-1");
> } catch (Exception e) {
> throw new UnavailableException(e.getMessage());
> } //end of catch
>
> }//end of if
> }//end of init
>
> public void doGet(HttpServletRequest request,
> HttpServletResponse response)
> throws IOException, ServletException
> {
> response.setContentType("text/html");
> PrintWriter out = response.getWriter();
> try{
> VelocityContext context = new VelocityContext();
> context.put("link", new WorkingServlet());
> context.put("request", request);
> Template tpl = RuntimeSingleton.getTemplate("homepage3.vm");
> tpl.merge( context,out);
> }catch (Exception e){
> }//end of catch
> }//end of doGet
>
> public String getBrowseURL(HttpServletRequest request,String startStr,int
> startPt, int fetchCount)
> {
> return("HEllO REQUEST");
> }
> public String getBrowseURL(String startStr,int startPt, int
> fetchCount,HttpServletRequest request)
> {
> return("HEllO REQUEST");
> }
> public String getBrowseURL(HttpServletRequest request, int startPt, int
> fetchCount)
> {
> return("HEllO REQUEST");
> }
> public String getBrowseURL(String startStr,int startPt, int fetchCount)
> {
> return("HEllO REQUEST");
> }
> public String getBrowseURL(int startPt, int fetchCount)
> {
> return("HEllO REQUEST");
> }
> public String getBrowseURL(HttpServletRequest request)
> {
> return("HEllO REQUEST");
> }
> }//end of class
> -----------------------------WorkingServlet.java--------------------------------
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]