Ajax 树不加载页面
我尝试在单击 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要那样做。您正在以错误的方式与 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.