我试图用备用的页面 UI:包括
上点击阿贾克斯(PrimeFaces)树节点。第一个页面加载默认正确加载所有的组件激活,但是当我点击其他的树节点,以显示不正常另一页,后面的页面加载就像对话框下方可见,页面手中。
我觉得如果我可以强制页面重新加载部分为默认的 nodeSelect
index.jsf
(在登录时被加载)
<电话号码:layoutUnit位置=西部大开发大小=270标题=菜单可折叠=假调整大小=真正的>
<电话号码:ajaxStatus风格=宽度:16px的;高度:16px的;>
< F:面NAME =开始>
< H:graphicImage的价值=../设计/ ajaxloading.gif/>
< / F:面>
< F:面NAME =完整的>
< H:的outputText值=/>
< / F:面>
< / P:ajaxStatus>
< H:格式ID =appsMainControl>
<用户界面:包括SRC =/ UI / appServices.jsf/>
< /小时:形式GT;
< / P:layoutUnit>
<电话号码:layoutUnit位置=中心>
< H:格式ID =centerControl>
<用户界面:包括SRC =/ UI /#{amb.appToGet} .jsf/>
< /小时:形式GT;
< / P:layoutUnit>
与听众行动树形视图组件。在节点选择我想要的子页面加载适当
<电话号码:layoutUnit位置=西部大开发大小=270标题=菜单可折叠=假调整大小=真正的>
<电话号码:ajaxStatus风格=宽度:16px的;高度:16px的;>
< F:面NAME =开始>
< H:graphicImage的价值=../设计/ ajaxloading.gif/>
< / F:面>
< F:面NAME =完整的>
< H:的outputText值=/>
< / F:面>
< / P:ajaxStatus>
< H:格式ID =appsMainControl>
<用户界面:包括SRC =/ UI / appServices.jsf/>
< /小时:形式GT;
< / P:layoutUnit>
<电话号码:layoutUnit位置=中心>
< H:格式ID =centerControl>
<用户界面:包括SRC =/ UI /#{amb.appToGet} .jsf/>
< /小时:形式GT;
< / P:layoutUnit>
支持bean:
公共无效onNodeSelect(NodeSelectEvent事件)抛出异常{
的ExternalContext EC = FacesContext.getCurrentInstance()getExternalContext()。
尝试 {
appToGet = appsMainDAO.appToGet(event.getTreeNode()的toString());
// ec.redirect(index.jsf);
//的System.out.println(得到+ appToGet);
// appSubList = appsMainDAO.appsSubServicesList(appToGet,表单);
}赶上(例外前){
ex.printStackTrace();
。Logger.getLogger(appsMainBean.class.getName())日志(Level.SEVERE,空,前);
} 最后 {
}
}
解决方案
不要那样做。您正在揉JSF错误的方式,从而走向成一场大灾难。
这是不可能解释这里的整个生命周期,但是 - 直到你真正了解各地JSF自己的方式 - 只是假设的facelet页面_not_supposed_工作,如HTML页面
相反,他们应该像窗口的应用程序,在这里你有一定数目真的不出现或消失的小部件 - 它们可以被放在选项卡,就可以成为残疾人,但他们留在他们从一开始就。
如果存在的东西,以包括有限数量,最简单的方法是,以包括所有这些,加上一些渲染=#{gui.current =='COMPONENT1'},所以只组分之一是可见的。
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 {
}
}
解决方案
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.