別のページを含めるために ui:include を使用する基本ページがあります。ui:include は ui:param を使用して、含まれるページにパラメーターを渡します。パラメータは、インクルードされたページのコントローラの PostConstruct メソッドで読み取られます。
このデザインは、基本ページに複合コンポーネントを追加するまで問題なく機能します。追加されると、含まれているページ コントローラーは ui:param の値が null であることを報告します。ページから複合コンポーネントを削除すると、含まれているページのコントローラーによって ui:param を読み取ることができます (つまり、null ではありません)。助けてください!
問題を再現するためのファイル:
myPage.xhtml
<html xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:mycomponents="http://java.sun.com/jsf/composite/mycomponents">
<ui:include src="includePage.xhtml">
<ui:param name="myParam" value="myValue"/>
</ui:include>
<p/>
<mycomponents:myComponent/>
</html>
myIncludedPage.xhtml
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets">
The value of the param is: #{includedPageController.myParam}
</ui:composition>
myComponent.xhtml (「resources/mycomponents」に配置)
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface/>
<composite:implementation>
I am the composite component
</composite:implementation>
</html>
含まれているPageController.java
@ManagedBean
public class IncludePageController
{
String myParam;
@PostConstruct
private void init()
{
FaceletContext faceletContext = (FaceletContext)FacesContext.getCurrentInstance().
getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
myParam = (String)faceletContext.getAttribute("myParam");
}
public String getMyParam()
{
return myParam;
}
public void setMyParam(String myParam)
{
this.myParam = myParam;
}
}