|
|
Tiles forward and RequestURI
I have an application using JSF (MyFaces), Tiles and Acegi.
I have two pages, and a post to the first page can result in a forward to the second page.
The problem is that, for the forward, the fromServletRequest's RequestURI is set to the quot;layout.jspquot; page (which is my Tiles master layout for all my pages).
So I can't put any ucl security on any page that is the result of JSF navigation, because they all end up as forwards, and they all end up with the ucl quot;layout.jspquot;.
(I know I can use lt;redirect/gt; in all my navigation rules, but I'd rather not if possible).
Just wondering if anyone else using Tiles and Acegi has run into this issue. Has anyone done any customizations where they can specify ViewIDs instead of ucls in the definition source?
Thanks,
Christopher Pierce
mons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tiles.Attribute;
import org.apache.tiles.AttributeContext;
import org.apache.tiles.context.TilesRequestContext;
import org.apache.tiles.preparer.PreparerException;
import org.apache.tiles.preparer.ViewPreparer;
/*** This ViewPreparer makes the last bit of the URI available to help the menu know which version of the button to display. For example,* a request for /spring/index means that the home page was requested and, thus, the selected version of the home page button* should be displayed. I tried using pageContext.request.requestURI in the jsp, but that only gives you the Tiles template URI. Research* indicates that this has something to do with Servlet 2.4 and not Tiles.*/
public class MenuViewPreparer implements ViewPreparer {
protected final Log logger = LogFactory.getLog(getClass());
public void execute(TilesRequestContext tilesContext, AttributeContext attributeContext)
throws PreparerException {
fromServletRequest request = (fromServletRequest) tilesContext.getRequest(); String uri = request.getRequestURI();
logger.debug(quot;RequestURI is: quot; + request.getRequestURI());
// get rid of any jsessionid int i = uri.indexOf(';'); if (i gt; 0)uri = uri.substring(0, i); // find the last slash and extract the text after that (e.g., extract quot;blahquot; from quot;/spring/blahquot;) i = uri.lastIndexOf(quot;/quot;); if (i gt;= 0) { uri = uri.substring(i);// will include the slash if (uri.length() gt; 1) uri = uri.substring(1);// get rid of the slash else throw new PreparerException(quot;URI ended with forward slash. Some string must exist after the last slash.quot;); } else throw new PreparerException(quot;Could not find a forward slash in the URI.quot;);
logger.debug(quot rocessed URI: quot; + uri);
Attribute attribute = new Attribute();
attribute.setType(Attribute.AttributeType.STRING);// set the type to string or else Tiles will try to insert the view
attribute.setBody(uri);
attributeContext.putAttribute(quot;pageNamequot;, attribute);
}
}
In layouts.xml:
Code:
lt;definition name=quot;standardLayoutquot; template=quot;/WEB-INF/layouts/standard.jspquot; preparer=quot;com.somecompany.tiles.view.preparer.MenuViewPreparerquot; /gt;
In standard.jsp:Code:
lt;tiles:insertAttribute name=quot;pageNamequot; /gt;Or you could just put the info on the request and access that in your jsp...Code:
request.setAttribute(quot AGE_NAMEquot;, uri);This seems to work:
Code:
${requestScope['javax.servlet.forward.request_uri']} |
|