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.
精彩评论