简体   繁体   English

从ui:component内部更新primefaces面板

[英]Update primefaces panel from inside ui:component

When i click the 'Go to page 1 from included' (page2.xhtml) the centerPanel (index.xhtml) just go blank and my doNav method is not called as follows: 当我单击“从包含的页面转到第1页”(page2.xhtml)时,centerPanel(index.xhtml)变为空白,而我的doNav方法未按如下方式调用:

index.xhtml 的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 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 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 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;
    }

}

Is there anyway i can do this? 反正我能做到吗?

The issue I see is your NavBean is @NoneScoped because you have not specified a scope. 我看到的问题是您的NavBean为@NoneScoped因为您尚未指定范围。 @NoneScoped will cause a NavBean to be created every time you reference it from an expression, so your page variable has not been set when you use it. 每次您从表达式引用NavBean时, @NoneScoped都会导致创建NavBean,因此在使用它时未设置页面变量。 You need to specify a scope for your NavBean to be at least @ViewScoped . 您需要为NavBean指定一个范围,至少为@ViewScoped Read over these questions as well: 还要阅读以下问题:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM