【问题标题】:Dynamic rendering of ui:include won't work when ui:repeat is used in included facelet在包含的 facelet 中使用 ui:repeat 时,ui:include 的动态呈现将不起作用
【发布时间】:2014-09-04 11:03:31
【问题描述】:

你好,

我将ui:include 放入h:panelGroup 并在需要时动态呈现它。

通常的假设和理论是,当 ui:include 未呈现时,与包含页面关联的 ManagedBean 不应被初始化。

当我在包含页面中使用ui:repeat 时,不会发生这种情况。

这是一个重复问题的示例:

page.1.xhtml

<h:body>
    <h:form>
        <p:outputLabel value="#{mBeanOne.beanOnetxt}"/><br/>
    </h:form>

    <h:panelGroup rendered="false" layout="block">
        <ui:include src="page2.xhtml"/>
    </h:panelGroup>
</h:body>

MBeanOne.java

@ManagedBean
@ViewScoped
public class MBeanOne implements Serializable{

    private String beanOnetxt;

    public MBeanOne() {
        System.out.println("MBeanOne - Constructor");
    }

    @PostConstruct
    public void init(){
        beanOnetxt = "This is Managed Bean 1";
        System.out.println("MBeanOne - Postconstruct");
    }
    //SETTERS and GETTERS
}

page2.xhtml

<h:body>
    <h:outputText value="#{mBeanTwo.beanTwotxt}"/><br/>

    <ui:repeat var="var" value="#{mBeanTwo.versionList}">
        <h:outputText value="#{var}"/><br/>
    </ui:repeat>
</h:body>

MBeanTwo.java

@ManagedBean
@ViewScoped
public class MBeanTwo implements Serializable{

    private String beanTwotxt;
    private List<String> versionList;

    public MBeanTwo() {
        System.out.println("MBeanTwo - Constructor");
    }

    @PostConstruct
    public void init(){
        beanTwotxt = "This is Managed Bean 2";

        versionList = new ArrayList<String>();
        versionList.add("Playground");
        versionList.add("Kestrel");
        versionList.add("Merlin");
        versionList.add("Tiger");

        System.out.println("MBeanTwo - Postconstruct");
    }
    //SETTER and GETTER
}

正如您在page1.xhtml 中看到的那样,我使用rendered="false" 来表示封装ui:include 的h:paneGroup,但当我加载page1.xhtml 时,MBeanTwo 仍在初始化。

如果我从page2.xhtml 中删除ui:repeat,则MBeanTwo 不会被初始化。

这是 JSF 中的一个错误,如果有的话,有什么可用的解决方法吗?

使用和测试的版本:
Primefaces 3.5
JSF 2.1.13 和 2.2.0-m05

【问题讨论】:

    标签: jsf jsf-2 primefaces


    【解决方案1】:

    &lt;ui:include /&gt; 与您的问题无关,它可能是在相同的视图中以相同的行为完成的所有操作。

    无论如何,&lt;ui:repeat /&gt; 标签似乎在进行 bean 初始化之前并没有检查其父 rendered 属性。但是,mBeanTwo#getVersionList 方法永远不会被评估,只是创建了托管 bean。如果您在构建 bean 时执行数据访问,这可能会使您放慢速度,但绝不应该破坏您的视图。我能够在 Mojarra 2.1.x 版本中重现该问题,但是他们已经为 2.2.x 最新的未成年人修复了它。

    似乎是 Mojarra 实现错误,而不是预期的行为。

    另请参阅:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 2014-12-11
      • 2015-09-03
      • 2013-12-06
      相关资源
      最近更新 更多