【问题标题】:Can't use composite component on same page with a ui:include that relies on ui:params不能在同一页面上使用复合组件与 ui:include 依赖于 ui:params
【发布时间】:2012-07-06 00:37:52
【问题描述】:

我有一个使用 ui:include 来包含另一个页面的基本页面。 ui:include 使用 ui:param 将参数传递给包含的页面。该参数在包含页面控制器的 PostConstruct 方法中读取。

在我将复合组件添加到基本页面之前,此设计工作正常;添加后,包含的页面控制器会报告 ui:param 的值为 null。一旦我从页面中删除复合组件, ui:param 就可以被包含页面的控制器读取(即不为空)。请帮忙!


重现问题的文件:

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>

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;
    }   
}

【问题讨论】:

    标签: jsf-2


    【解决方案1】:

    请参阅:How do I set Managed Bean field to the value of a ui:param?。在 JSF API 中没有做这类事情的标准。应使用复合或自定义组件,而不是包含/参数标记组合。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-25
      • 2011-07-21
      • 2012-08-11
      • 2013-12-06
      • 2021-12-15
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多