I have a scenario,
When request comes from IE browser then show login
(which is default behaviour) and when it comes from Chrome browser then show login_chrome
(Layout definition is in Tiles.xml like below)
<definition name="login" path="/login/login1.jsp"></definition>
<definition name="login_chrome" path="/login/login2.jsp"></definition>
And I have CustomizedTileProcessor
public class CustomizedTileProcessor extends TilesRequestProcessor
{
@Override
protected boolean processTilesDefinition(String pDefinitionName, boolean pContextRelative, HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException, ServletException
{
if (isChromeBrowser(pRequest))
{
pDefinitionName+="_chrome";
}
return super.processTilesDefinition(pDefinitionName, true, pRequest, pResponse);
}
}
Note : I don't want to put logic in JSP to select included JSPs as per condition.
Please help me and tell me which method of TilesRequestProcessor
to override to change tile definition dynamically?
After doing lot trial and error I got to know that I have to override processForwardConfig
method of TilesRequestProcessor
. And there I have to override the value of path
value of ForwardConfig
object to my new layout i.e. login_chrome
.
Please see below code :
public class CustomizedTileProcessor extends TilesRequestProcessor
{
@Override
protected void processForwardConfig(HttpServletRequest pRequest,
HttpServletResponse pResponse, ForwardConfig pForward)
throws IOException, ServletException
{
if(isChromeBrowser(pRequest))
{
ForwardConfig newForward = new ForwardConfig(pForward.getName(),
pForward.getPath()+"_chrome", pForward.getRedirect(),
pForward.getContextRelative());
super.processForwardConfig(pRequest, pResponse, newForward);
}
else
{
super.processForwardConfig(pRequest, pResponse, pForward);
}
}
}