Ajax 从ui:组件内部更新primefaces面板

Ajax 从ui:组件内部更新primefaces面板,ajax,jsf,jsf-2,primefaces,Ajax,Jsf,Jsf 2,Primefaces,当我单击“从包含的内容转到第1页”(page2.xhtml)时,中心面板(index.xhtml)将变为空白,并且不会调用我的doNav方法,如下所示: index.xhtml <p:layout fullPage="true"> <p:layoutUnit position="west" size="245"> <h:form> <

当我单击“从包含的内容转到第1页”(page2.xhtml)时,中心面板(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>
    <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">
<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是
@NoneScoped
,因为您没有指定范围
@NoneScoped
将导致每次从表达式引用NavBean时都会创建一个NavBean,因此在使用它时没有设置页面变量。您需要为NavBean指定一个至少
@viewscope
的范围。请仔细阅读以下问题:

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

}