【问题标题】:Trying to change <ui:include> src tag dynamically尝试动态更改 <ui:include> src 标签
【发布时间】:2011-05-15 00:14:57
【问题描述】:

我的主页看起来像这样:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
    <title>Facelet Title</title>
</h:head>
<h:body>
    <h:form>
        <p:panel id="panel">
            <ui:include src="#{bean.page}">
            </ui:include>
        </p:panel>
        <p:commandButton actionListener="#{bean.changePage}" value="Push" ajax="true" update="panel"/>
    </h:form>
</h:body>
</html>

我想要做的是拥有一个这样的 bean 并动态更改包含的页面。这是 bean 的样子:

 @ManagedBean
 @SessionScoped
 public class Bean {
    private String page = "";

    public Bean() {
    }

    public String getPage() {
       return page;
    }

    public void setPage(String page) {
       this.page = page;
    }

    public void changePage(ActionEvent e) {
       page = "Page.xhtml";
    }   
}

当我单击按钮 Push 时,我希望包含此页面:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets">
   <h:head>
       <title>Facelet Title</title>
</h:head>
<h:body>
    <h:form>
        <ui:component>
            Hello from facelets
        </ui:component>
    </h:form>
</h:body>

问题是我必须按两次按钮才能包含页面。当我按下按钮第一次包含页面时,如何做到这一点?

【问题讨论】:

  • 什么 JSF impl/version?什么PF版本?无法在 Mojarra 2.1.1 和 PF 2.2.1 上重现您的问题。请注意,您的包含页面模板组合非常......奇怪(但它应该可以工作,我什至自己测试了它以排除它成为问题的原因)。

标签: jsf facelets


【解决方案1】:

这种模板通常使用&lt;ui:insert&gt;&lt;ui:define&gt; 标签来实现。查看 Java EE 教程的this page

【讨论】:

  • 嗨,我遇到了类似的问题,我也不明白模板文件在这种情况下如何提供帮助。有没有其他方法可以一键显示要收录的页面?
  • 对不起,我不太清楚你在问什么。最好提出一个新问题,而不是在 cmets 中提出。您可以随时链接到此问题以供参考。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-05
  • 1970-01-01
  • 2012-01-13
  • 2020-08-12
  • 2018-09-15
  • 2023-03-11
  • 1970-01-01
相关资源
最近更新 更多