You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Christopher Schultz (JIRA)" <ve...@apache.org> on 2005/10/17 23:08:46 UTC

[jira] Closed: (VELTOOLS-16) StrutsLinkTool.setForward requires trip through Struts ActionServlet

     [ http://issues.apache.org/jira/browse/VELTOOLS-16?page=all ]
     
Christopher Schultz closed VELTOOLS-16:
---------------------------------------


I noticed that this bug wasn't CLOSED. I was the original reporter, so I'll go ahead and CLOSE it.

> StrutsLinkTool.setForward requires trip through Struts ActionServlet
> --------------------------------------------------------------------
>
>          Key: VELTOOLS-16
>          URL: http://issues.apache.org/jira/browse/VELTOOLS-16
>      Project: VelocityTools
>         Type: Bug
>  Environment: Operating System: other
> Platform: Other
>     Reporter: Christopher Schultz
>  Attachments: forwardurl.diff
>
> When using StrutsLinkTool.setForward, if your request does not first go through
> the Struts ActionServlet (say, by being processed by an action, then forwarded
> to a Velocity template), you get the following exception:
> java.lang.NullPointerException
> 	at org.apache.struts.util.RequestUtils.forwardURL(RequestUtils.java:1534)
> 	at org.apache.velocity.tools.struts.StrutsUtils.getForwardURL(StrutsUtils.java:597)
> 	at
> org.apache.velocity.tools.struts.StrutsLinkTool.setForward(StrutsLinkTool.java:82)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> This exception does *not* occur if you have an action forward in
> struts-config.xml which forwards to a Velocity template. This exception is also
> not thrown in version 1.3 of Velocity-Tools, which I used until recently.
> Finally, using $link.setAction works without going through the ActionServlet --
> it only appears to be the $link.setForward that suffers from this problem.
> I asked around on the Struts user mailing list and got some feedback. Original
> post: http://www.junlu.com/msg/89307.html (Sorry, the Struts-user archives
> haven't caught up with the latest messages, I guess, so I can't provide a direct
> link to the mailing list archives).
> Anyway, in the short discussion that followed, I asked about how the Struts
> "forward" tag worked that comes with struts -- did it require that the request
> go through the ActionServlet? The answer was "no": if the request hasn't been
> through the ActionServlet, yet, there's a bit of code to insert the proper
> attribute into the session before calling RequestUtils.forwardURL().
> The bit of code is essentially this:
>         StringBuffer url = new StringBuffer();
>         if (fc.getPath().startsWith("/"))
>         {
>             url.append(request.getContextPath());
>             // <new>
> 	    if(null == request.getAttribute(Globals.MODULE_KEY))
> 		request.setAttribute(Globals.MODULE_KEY, moduleConfig);
>             // </new>
>             url.append(RequestUtils.forwardURL(request, fc));
>         }
> I have made this change for my project and it works like a charm. Since the
> Struts forward tag also uses this technique, I figure that it's a decent fix.
> I'll provide a patch which includes this fix.
> Thanks,
> -chris

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


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