我有一个使用 ui:include 包含另一个页面的基本页面。ui:include 使用 ui:param 将参数传递给包含的页面。该参数在包含页面控制器的 PostConstruct 方法中读取。
在我将复合组件添加到基本页面之前,此设计工作正常;添加后,包含的页面控制器会报告 ui:param 的值为 null。一旦我从页面中删除复合组件, ui:param 就可以被包含页面的控制器读取(即不为空)。请帮忙!
重现问题的文件:
我的页面.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>
IncludedPageController.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;
}
}