Marco Gustavo
Marco Gustavo

Reputation: 69

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:

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

}

Is there anyway i can do this?

Upvotes: 1

Views: 1141

Answers (1)

Mark
Mark

Reputation: 17182

The issue I see is your NavBean is @NoneScoped because you have not specified a scope. @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. You need to specify a scope for your NavBean to be at least @ViewScoped. Read over these questions as well:

Upvotes: 1

Related Questions