コンピュータクワガタ

かっぱのかっぱによるコンピュータ関連のサイトです

SAStrutsというか、Strutsのtiles

以下のような、tilesのcontrollerUrlの検証をしています。

<tiles:include controllerUrl="hoge" page="foo" /> 

動きがよくわからないのでソースをざっと読んでみました。
キーは、org.apache.struts.taglib.tiles.InsertTagクラスです。
最終的には、以下の処理をしています。controllerは、controllerUrlで指定したアクションです。
pageは、そのままタグで指定したpage属性の値です。

pageContext.setAttribute(
    ComponentConstants.COMPONENT_CONTEXT,
    subCompContext,
    PageContext.REQUEST_SCOPE);
try {
    controller.execute(
        subCompContext,
        (HttpServletRequest) pageContext.getRequest(),
        (HttpServletResponse) pageContext.getResponse(),
        pageContext.getServletContext());                        
    } catch (Exception e) {
        throw new ServletException(e);
    }
}
// include requested component.
if (flush) {
    pageContext.getOut().flush();
}

doInclude(page);

というようなことをしています。
controller.executeの実体は、org.apache.struts.tiles.UrlController#executeで、

RequestDispatcher rd = servletContext.getRequestDispatcher(url);
if (rd == null) {
    throw new ServletException(
        "Controller can't find url '" + url + "'.");
}

rd.include(request, response);

doIncludeは、最終的には

pageContext.include(uri);

と、includeしているだけです。

SAStrutsでは、controllerUrlには、以下のように〜〜.doのアクションの形式で書かないと動きません。

<tiles:insert controllerUrl="/test/sample.do?&SAStruts.method=foo" page="hoge.jsp" />