Tomcat 7で実行されているPrimefacesでJSF2を使用しています。以下のようにbaseLayout.xhtmlにレイアウトを作成しました:-
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="50" id="top">
<h:form>
<ui:include src="/template/header.xhtml" />
</h:form>
</p:layoutUnit>
<p:layoutUnit position="south" size="20">
<h:form>
<ui:include src="/template/footer.xhtml" />
</h:form>
</p:layoutUnit>
<p:layoutUnit position="west" size="400">
<h:form>
<ui:include src="/template/menu.xhtml" />
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center" size="400">
<h:panelGroup id="centerContentPanel">
<ui:include src="#{navigationBean.pageName}.xhtml" />
</h:panelGroup>
</p:layoutUnit>
</p:layout>
</h:body>
ページ全体とcenterContentPanelだけを更新せずに、 centerContentPanelのソースを動的に変更したい。つまり、以下のようにmenu.xhtmlにあるリンクをクリックするだけです。
<h:form id="form2">
<f:ajax render=":centerContentPanel" execute="@this">
<h:commandLink value="page1" action="#{navigationBean.doNav}" >
<f:param name="test" value="/pages/page1" />
</h:commandLink>
<h:commandLink value="page2" action="#{navigationBean.doNav}" >
<f:param name="test" value="/pages/page2" />
</h:commandLink>
</f:ajax>
</h:form>
。やってみましたが、URLを変えずにページ全体を更新し、再度更新すると新しいページが含まれています。何が起こっているのかわかりません。以下のように私のNavigationBean:-
public class NavigationBean {
private String pageName="/template/body";
public NavigationBean() {
}
public String doNav() {
System.out.println("Hello");
String str = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("test");
this.pageName = str;
return pageName;
}
public String getPageName() {
return pageName;
}
public void setPageName(String pageName) {
this.pageName = pageName;
}
}