【问题标题】:Update primefaces panel from inside ui:component从 ui:component 内部更新 primefaces 面板
【发布时间】:2015-02-02 10:15:31
【问题描述】:

当我单击“从包含的页面转到第 1 页”(page2.xhtml) 时,centerPanel (index.xhtml) 将变为空白,并且我的 doNav 方法未按如下方式调用:

index.xhtml

<p:layout fullPage="true">

                <p:layoutUnit position="west" size="245">
                    <h:form>
                        <p:menu>
                            <p:submenu label="Resources">
                                <p:menuitem value="Page 1" actionListener="#{navBean.doNav}" update=":centerPanel">
                                    <f:param name="page" value="page1" />
                                </p:menuitem>
                                <p:menuitem value="Page 2" actionListener="#{navBean.doNav}" update=":centerPanel">
                                    <f:param name="page" value="page2" />
                                </p:menuitem>
                            </p:submenu>
                        </p:menu>
                    </h:form>
                </p:layoutUnit>


                <p:layoutUnit position="center">
                    <p:panel id="centerPanel">
                        <c:if test="#{navBean.page != null}">
                            <ui:include src="#{navBean.page}.xhtml" />
                        </c:if>
                    </p:panel>
                </p:layoutUnit>


            </p:layout>

page1.xhtml

    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

        Page 1

    </ui:composition>

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://xmlns.jcp.org/jsf/core">

page2.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://xmlns.jcp.org/jsf/core">

    <h3>Page 2</h3>

    <p:commandButton value="Go to page 1 from included" actionListener="#{navBean.doNav}" update=":centerPanel">
        <f:param name="page" value="page1" />
    </p:commandButton>

</ui:composition>

NavBean

@ManagedBean(name = "navBean")
public class NavBean {

    private String page = null;

    public void doNav() {
        this.page = FacesContext.getCurrentInstance().getExternalContext()
                .getRequestParameterMap().get("page");
    }

    public String getPage() {
        return page;
    }

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

}

有没有我可以做到的?

【问题讨论】:

    标签: ajax jsf jsf-2 primefaces


    【解决方案1】:

    我看到的问题是您的 NavBean 是 @NoneScoped,因为您没有指定范围。 @NoneScoped 将导致每次从表达式中引用它时都会创建一个 NavBean,因此在您使用它时尚未设置您的页面变量。您需要为您的 NavBean 指定一个至少为@ViewScoped 的范围。同时阅读这些问题:

    【讨论】:

      猜你喜欢
      • 2013-08-30
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 2016-11-01
      • 2012-04-23
      • 2012-09-23
      • 2011-11-10
      • 1970-01-01
      相关资源
      最近更新 更多