mirror of
https://github.com/apache/struts.git
synced 2026-08-31 19:35:40 +00:00
Defines helper method to fetch ActionContext from request
This commit is contained in:
+26
-4
@@ -36,7 +36,9 @@ import org.apache.struts2.views.freemarker.StrutsBeanWrapper;
|
||||
import org.apache.tiles.freemarker.template.TilesFMModelRepository;
|
||||
import org.apache.tiles.impl.InvalidTemplateException;
|
||||
import org.apache.tiles.request.Request;
|
||||
import org.apache.tiles.request.jsp.JspRequest;
|
||||
import org.apache.tiles.request.render.Renderer;
|
||||
import org.apache.tiles.request.servlet.ServletRequest;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -51,10 +53,7 @@ public class StrutsFreeMarkerAttributeRenderer implements Renderer {
|
||||
if (path != null) {
|
||||
LOG.trace("Rendering freemarker tile ...");
|
||||
|
||||
ActionContext ctx = ServletActionContext.getActionContext((HttpServletRequest) request);
|
||||
if (ctx == null) {
|
||||
throw new ConfigurationException("There is no ActionContext for current request!");
|
||||
}
|
||||
ActionContext ctx = readActionContext(request);
|
||||
|
||||
registerTilesBeanModel(ctx);
|
||||
|
||||
@@ -77,6 +76,29 @@ public class StrutsFreeMarkerAttributeRenderer implements Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Depending how Tiles definition was defined, request can an instance of JspRequest (for JSPs)
|
||||
* or a ServletRequest (FreeMarker)
|
||||
*/
|
||||
protected ActionContext readActionContext(Request request) {
|
||||
ActionContext ctx = null;
|
||||
|
||||
if (request instanceof ServletRequest) {
|
||||
HttpServletRequest httpRequest = ((ServletRequest) request).getRequest();
|
||||
ctx = ServletActionContext.getActionContext(httpRequest);
|
||||
}
|
||||
if (request instanceof JspRequest) {
|
||||
HttpServletRequest httpRequest = (HttpServletRequest) ((JspRequest) request).getPageContext().getRequest();
|
||||
ctx = ServletActionContext.getActionContext(httpRequest);
|
||||
}
|
||||
|
||||
if (ctx == null) {
|
||||
throw new ConfigurationException("There is no ActionContext for current request!");
|
||||
}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRenderable(String path, Request request) {
|
||||
return path != null && path.startsWith("/") && path.endsWith(".ftl");
|
||||
|
||||
Reference in New Issue
Block a user