2

I'm using JSF2 with Primefaces running on Tomcat 7. I have created a layout in baseLayout.xhtml as below: -

<h:body>
    <p:layout fullPage="true">
        <p:layoutUnit position="north" size="50" id="top">
            <h:form>
                <ui:include src="/template/header.xhtml" />
            </h:form>
        </p:layoutUnit>
        <p:layoutUnit position="south" size="20">
            <h:form>
                <ui:include src="/template/footer.xhtml" />
            </h:form>
        </p:layoutUnit>
        <p:layoutUnit position="west" size="400">
            <h:form>
                <ui:include src="/template/menu.xhtml" />
            </h:form>
        </p:layoutUnit>
        <p:layoutUnit position="center" size="400">
            <h:panelGroup id="centerContentPanel">
                <ui:include src="#{navigationBean.pageName}.xhtml" />
            </h:panelGroup>
        </p:layoutUnit>
    </p:layout>
</h:body>

I want to dynamically change the source of centerContentPanel without refreshing the whole page and just the centerContentPanel i.e for on click of link present in the menu.xhtml as below: -

<h:form id="form2">
       <f:ajax render=":centerContentPanel" execute="@this">
           <h:commandLink value="page1" action="#{navigationBean.doNav}" >
             <f:param name="test" value="/pages/page1" />
           </h:commandLink>
           <h:commandLink value="page2" action="#{navigationBean.doNav}" >
             <f:param name="test" value="/pages/page2" />
           </h:commandLink>
    </f:ajax>
</h:form>

. I tried doing that, but instead it refreshes the whole page without changing the URL, and when I refresh it again, the new page is included. I don't know what is happening. My NavigationBean as below:-

public class NavigationBean {

    private String pageName="/template/body";

    public NavigationBean() {
    }

    public String doNav() {
        System.out.println("Hello");
        String str = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("test");
        this.pageName = str;
        return pageName;
    }

    public String getPageName() {
        return pageName;
    }

    public void setPageName(String pageName) {
        this.pageName = pageName;
    }
}
4

1 回答 1

4

更改doNav()为 void ,无需返回值...(因为它会导致您的 commandLink 重新加载页面...)您已经更新了pageName正在使用的<ui:include src="#{navigationBean.pageName}.xhtml" />

doNav应该是这样的:

public void doNav() {
    System.out.println("Hello");
    String str = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("test");
    this.pageName = str;

}

action="..."您的原因的返回值refreshes the whole page without changing the URL

于 2012-04-26T18:48:41.760 回答