Ajax 树不加载页面

发布于 2024-11-30 11:58:40 字数 2492 浏览 0 评论 0原文

我尝试在单击 ajax (PrimeFaces) 树节点时使用 ui:include 来交替页面。默认情况下加载的第一个页面在所有组件处于活动状态的情况下正确加载,但是当我单击另一个树节点以显示另一个页面时,后一个页面加载异常,就像下面可见对话框和页面指针一样。

我觉得如果我可以强制页面在 nodeSelect

index.jsf (登录时加载)

<p:layoutUnit position="west" size="270" header="Menu" collapsible="false" resizable="true">
    <p:ajaxStatus style="width:16px;height:16px;">
        <f:facet name="start">
            <h:graphicImage value="../design/ajaxloading.gif"/>
        </f:facet>
        <f:facet name="complete">
            <h:outputText value=""/>
        </f:facet>
    </p:ajaxStatus>
    <h:form id="appsMainControl">
        <ui:include src="/ui/appServices.jsf"/>
    </h:form>
</p:layoutUnit>
<p:layoutUnit position="center">
    <h:form id="centerControl">                    
        <ui:include src="/ui/#{amb.appToGet}.jsf"/>                   
    </h:form>
</p:layoutUnit>

上部分重新加载,带有侦听器操作的树视图组件。在选择节点时,我希望子页面能够正确加载

<p:layoutUnit position="west" size="270" header="Menu" collapsible="false" resizable="true">
    <p:ajaxStatus style="width:16px;height:16px;">
        <f:facet name="start">
            <h:graphicImage value="../design/ajaxloading.gif"/>
        </f:facet>
        <f:facet name="complete">
            <h:outputText value=""/>
        </f:facet>
    </p:ajaxStatus>
    <h:form id="appsMainControl">
        <ui:include src="/ui/appServices.jsf"/>
    </h:form>
</p:layoutUnit>
<p:layoutUnit position="center">
    <h:form id="centerControl">                    
        <ui:include src="/ui/#{amb.appToGet}.jsf"/>                   
    </h:form>
</p:layoutUnit>

支持 bean:

public void onNodeSelect(NodeSelectEvent event) throws Exception {
    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();

    try {
        appToGet = appsMainDAO.appToGet(event.getTreeNode().toString());
        // ec.redirect("index.jsf");
        // System.out.println("Got "+appToGet);
        // appSubList = appsMainDAO.appsSubServicesList(appToGet, "Forms");
    } catch (Exception ex) {
        ex.printStackTrace();
        Logger.getLogger(appsMainBean.class.getName()).log(Level.SEVERE, null, ex);
    } finally {

    }

}

I tried to alternate pages using ui:include on click of ajax (PrimeFaces) treenodes. The first page that load by default loads properly with all the components active but when I click on the other treenode to display another page, the latter page loads abnormally like having the dialog box visible below and the page hands.

I feel if I can force the page to reload partially as default on nodeSelect

index.jsf (gets loaded on login)

<p:layoutUnit position="west" size="270" header="Menu" collapsible="false" resizable="true">
    <p:ajaxStatus style="width:16px;height:16px;">
        <f:facet name="start">
            <h:graphicImage value="../design/ajaxloading.gif"/>
        </f:facet>
        <f:facet name="complete">
            <h:outputText value=""/>
        </f:facet>
    </p:ajaxStatus>
    <h:form id="appsMainControl">
        <ui:include src="/ui/appServices.jsf"/>
    </h:form>
</p:layoutUnit>
<p:layoutUnit position="center">
    <h:form id="centerControl">                    
        <ui:include src="/ui/#{amb.appToGet}.jsf"/>                   
    </h:form>
</p:layoutUnit>

The treeview component with the listener action. On node selection I want the child page to load appropriately

<p:layoutUnit position="west" size="270" header="Menu" collapsible="false" resizable="true">
    <p:ajaxStatus style="width:16px;height:16px;">
        <f:facet name="start">
            <h:graphicImage value="../design/ajaxloading.gif"/>
        </f:facet>
        <f:facet name="complete">
            <h:outputText value=""/>
        </f:facet>
    </p:ajaxStatus>
    <h:form id="appsMainControl">
        <ui:include src="/ui/appServices.jsf"/>
    </h:form>
</p:layoutUnit>
<p:layoutUnit position="center">
    <h:form id="centerControl">                    
        <ui:include src="/ui/#{amb.appToGet}.jsf"/>                   
    </h:form>
</p:layoutUnit>

The backing bean:

public void onNodeSelect(NodeSelectEvent event) throws Exception {
    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();

    try {
        appToGet = appsMainDAO.appToGet(event.getTreeNode().toString());
        // ec.redirect("index.jsf");
        // System.out.println("Got "+appToGet);
        // appSubList = appsMainDAO.appsSubServicesList(appToGet, "Forms");
    } catch (Exception ex) {
        ex.printStackTrace();
        Logger.getLogger(appsMainBean.class.getName()).log(Level.SEVERE, null, ex);
    } finally {

    }

}

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

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

发布评论

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

评论(1

旧梦荧光笔 2024-12-07 11:58:40

不要那样做。您正在以错误的方式与 JSF 发生冲突,从而导致一场重大灾难。

在这里解释整个生命周期是不可能的,但是 - 直到您真正了解 JSF 的方式 - 假设 Facelet 页面_不_应该_像 HTML 页面一样工作。

相反,它们应该像窗口应用程序一样工作,其中您有一定数量的小部件,它们不会真正出现或消失 - 它们可以放入选项卡中,它们可以被禁用,但它们从一开始就保持在原来的位置。

如果要包含的内容数量有限,最简单的选择是将它们全部包含并添加一些 render="#{gui.current=='component1'}",这样只有一个组件可见。

Don't do that. You are rubbing JSF the wrong way and thus heading into a major catastrophe.

It's impossible to explain the whole life cycle here, but - until you really know your way around JSF - just assume that facelet pages are _not_supposed_ to work like HTML pages.

Instead, they should work like window applications, where you have a certain number of widgets that don't really appear or disappear - they can be put in tabs, they can become disabled, but they stay where they were from the beginning.

If there is a finite number of things to include, the easiest option is to include them all and add some rendered="#{gui.current=='component1'}", so only one of the components is visible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文