如何在 JSF2 和 Primefaces 2 中实现部分导航

发布于 2024-12-12 08:22:14 字数 2107 浏览 0 评论 0原文

我的左侧面板包含不同页面的链接。右侧面板应该根据左侧面板中单击的链接使用新页面进行更新。我希望它是一个 ajax 更新,这样左侧面板、页眉和页脚就不会刷新。我尝试使用 ui:include 但页面仅在第二次单击时刷新。对该线程的引用是

ui:include in richfaces 4仅在第二次单击时更新

有没有其他方法可以在 JSF2 和 Primefaces 2.2.1 中实现相同的目的。 感谢

更新

<ui:define name="content">
    <h:form id="form_01">

    <div style="margin:0; padding:0; float:right; width:740px;background:#FFF; ">
        <p:outputPanel id="pagePanel">
            <ui:include src="#{panelMenu.currentPage}.xhtml"></ui:include>
        </p:outputPanel>
    </div>

    <div style="padding:0; float:left;">
        <p:panel  style="width:205px;" header="User Menu">
            <h:panelGrid columns="1">
                <p:commandLink update="pagePanel" action="#{panelMenu.setCurrentPage('/pages/group_message')}">
                    <h:outputText value="Compose"/>
                </p:commandLink>
                <p:separator/>
                <p:commandLink update="pagePanel" action="#{panelMenu.setCurrentPage('/pages/group_detail')}">
                    <h:outputText value="Groups"/>
                </p:commandLink>
                <p:separator/>

                </h:panelGrid>
        </p:panel>
    </div>
    </h:form>
</ui:define>

支持 Bean

@ManagedBean(name="panelMenu")
@SessionScoped

public class PanelMenu {
private String currentPage = "/pages/group_detail";

public String getCurrentPage() {
    System.out.println(Thread.currentThread().getStackTrace()[1]);
    System.out.println(FacesContext.getCurrentInstance().getCurrentPhaseId());
    return currentPage;
}

public void setCurrentPage(String currentPage) {
    System.out.println(Thread.currentThread().getStackTrace()[1]);
    System.out.println(FacesContext.getCurrentInstance().getCurrentPhaseId());
    this.currentPage = currentPage;
}

}

I have left panel that contains the link to different pages. The right panel is the one that should be updated with the new page based on the link clicked in the left panel. I want it to be an ajax update so that the left panel, header and footer do not refresh. I tried with ui:include but the page only gets refreshed on the second click. The reference to that thread is

ui:include in richfaces 4 only gets updated on second click

Is there any alternative way to achieve the same in JSF2 and Primefaces 2.2.1.
Thanks

Updates

<ui:define name="content">
    <h:form id="form_01">

    <div style="margin:0; padding:0; float:right; width:740px;background:#FFF; ">
        <p:outputPanel id="pagePanel">
            <ui:include src="#{panelMenu.currentPage}.xhtml"></ui:include>
        </p:outputPanel>
    </div>

    <div style="padding:0; float:left;">
        <p:panel  style="width:205px;" header="User Menu">
            <h:panelGrid columns="1">
                <p:commandLink update="pagePanel" action="#{panelMenu.setCurrentPage('/pages/group_message')}">
                    <h:outputText value="Compose"/>
                </p:commandLink>
                <p:separator/>
                <p:commandLink update="pagePanel" action="#{panelMenu.setCurrentPage('/pages/group_detail')}">
                    <h:outputText value="Groups"/>
                </p:commandLink>
                <p:separator/>

                </h:panelGrid>
        </p:panel>
    </div>
    </h:form>
</ui:define>

Backing Bean

@ManagedBean(name="panelMenu")
@SessionScoped

public class PanelMenu {
private String currentPage = "/pages/group_detail";

public String getCurrentPage() {
    System.out.println(Thread.currentThread().getStackTrace()[1]);
    System.out.println(FacesContext.getCurrentInstance().getCurrentPhaseId());
    return currentPage;
}

public void setCurrentPage(String currentPage) {
    System.out.println(Thread.currentThread().getStackTrace()[1]);
    System.out.println(FacesContext.getCurrentInstance().getCurrentPhaseId());
    this.currentPage = currentPage;
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如梦亦如幻 2024-12-19 08:22:14

这是一个示例:

Managed-bean:

@ManagedBean
@ViewScoped
public class PartialNavBean {
    private String pageName = "/pages/group_member";

    public String getPageName() {
        return pageName;
    }

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

View:

<p:panel id="leftPanel">
    <h:form>
        <p:commandLink value="Group member"
                       action="#{partialNavBean.setPageName('/pages/group_member')}"
                       update="rightPanel"/>
        <br/>
        <p:commandLink value="Group detail"
                       action="#{partialNavBean.setPageName('/pages/group_detail')}"
                       update="rightPanel"/>
    </h:form>
</p:panel>

<p:panel id="rightPanel">
    <ui:include src="#{partialNavBean.pageName}.xhtml"/>
</p:panel>

Update:

我尝试了以下操作:

public String getPageName() {
    System.out.println(Thread.currentThread().getStackTrace()[1]);
    System.out.println(FacesContext.getCurrentInstance().getCurrentPhaseId());
    return pageName;
}

public void setPageName(String pageName) {
    System.out.println(Thread.currentThread().getStackTrace()[1]);
    System.out.println(FacesContext.getCurrentInstance().getCurrentPhaseId());
    this.pageName = pageName;
}

输出如下:

INFO: pkg.PartialNavBean.getPageName(PartialNavBean.java:14)
INFO: RESTORE_VIEW 1
INFO: pkg.PartialNavBean.setPageName(PartialNavBean.java:20)
INFO: INVOKE_APPLICATION 5
INFO: pkg.PartialNavBean.getPageName(PartialNavBean.java:14)
INFO: RENDER_RESPONSE 6
INFO: pkg.PartialNavBean.getPageName(PartialNavBean.java:14)
INFO: RESTORE_VIEW 1
INFO: pkg.PartialNavBean.setPageName(PartialNavBean.java:20)
INFO: INVOKE_APPLICATION 5
INFO: pkg.PartialNavBean.getPageName(PartialNavBean.java:14)
INFO: RENDER_RESPONSE 6

Here is an example:

Managed-bean:

@ManagedBean
@ViewScoped
public class PartialNavBean {
    private String pageName = "/pages/group_member";

    public String getPageName() {
        return pageName;
    }

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

View:

<p:panel id="leftPanel">
    <h:form>
        <p:commandLink value="Group member"
                       action="#{partialNavBean.setPageName('/pages/group_member')}"
                       update="rightPanel"/>
        <br/>
        <p:commandLink value="Group detail"
                       action="#{partialNavBean.setPageName('/pages/group_detail')}"
                       update="rightPanel"/>
    </h:form>
</p:panel>

<p:panel id="rightPanel">
    <ui:include src="#{partialNavBean.pageName}.xhtml"/>
</p:panel>

Update:

I tried with the following:

public String getPageName() {
    System.out.println(Thread.currentThread().getStackTrace()[1]);
    System.out.println(FacesContext.getCurrentInstance().getCurrentPhaseId());
    return pageName;
}

public void setPageName(String pageName) {
    System.out.println(Thread.currentThread().getStackTrace()[1]);
    System.out.println(FacesContext.getCurrentInstance().getCurrentPhaseId());
    this.pageName = pageName;
}

And the output is as follows:

INFO: pkg.PartialNavBean.getPageName(PartialNavBean.java:14)
INFO: RESTORE_VIEW 1
INFO: pkg.PartialNavBean.setPageName(PartialNavBean.java:20)
INFO: INVOKE_APPLICATION 5
INFO: pkg.PartialNavBean.getPageName(PartialNavBean.java:14)
INFO: RENDER_RESPONSE 6
INFO: pkg.PartialNavBean.getPageName(PartialNavBean.java:14)
INFO: RESTORE_VIEW 1
INFO: pkg.PartialNavBean.setPageName(PartialNavBean.java:20)
INFO: INVOKE_APPLICATION 5
INFO: pkg.PartialNavBean.getPageName(PartialNavBean.java:14)
INFO: RENDER_RESPONSE 6
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文