我正在Liferay開發一個Primefaces應用程序,我需要使用p:treeTable compenent,發生點擊p:commandButton時節點消失。我相信它與阿賈克斯的關係,如果把@PostConstruct內managedBean代碼,它工作正常節點treetable primefaces消失
這是我.xhtml
<h:body>
<h:form id="form">
<p:layout style="min-width:1050px;height:700px" styleClass="semBorda">
<p:layoutUnit position="west" size="900" minSize="40" maxSize="310"
styleClass="semBorda">
<p:panelGrid columns="2" style="width:300px">
<f:facet name="header">
<h:outputText value="Campos" />
</f:facet>
<h:outputText value="Cidade" />
<p:selectCheckboxMenu value="#{relatorioBean.selectedCidades}"
label="Cidades" filter="true">
<f:selectItems value="#{relatorioBean.cidades}" />
</p:selectCheckboxMenu>
<!-- <h:outputText value="Ramal" /> -->
<!-- <p:selectBooleanCheckbox value="" /> -->
<!-- <h:outputText value="Tipo de Ramal" /> -->
<!-- <p:selectBooleanCheckbox value="" /> -->
<!-- <h:outputText value="Suborgao" /> -->
<!-- <p:selectBooleanCheckbox value="" /> -->
<!-- <h:outputText value="Situação" /> -->
<!-- <p:selectBooleanCheckbox value="" /> -->
<h:outputText value="Polo" />
<p:selectBooleanCheckbox value="#{relatorioBean.polo}" />
<!-- <h:outputText value="Categoria Diurna" /> -->
<!-- <p:selectBooleanCheckbox value="" /> -->
<!-- <h:outputText value="Categoria Noturna" /> -->
<!-- <p:selectBooleanCheckbox value="" /> -->
<h:outputText value="Teste" />
<p:inputText value="#{relatorioBean.teste}" />
</p:panelGrid>
<p:panelGrid columns="1" style="margin-left:200px; margin-top:10px">
<p:commandButton actionListener="#{relatorioBean.montarRaiz}"
value="Consultar" update="tree" styleClass="semB" />
</p:panelGrid>
</p:layoutUnit>
<p:layoutUnit position="center" styleClass="">
<p:treeTable value="#{relatorioBean.raiz}" var="ramal" id="tree">
<p:column headerText="Name">
<h:outputText value="#{ramal}" />
</p:column>
</p:treeTable>
</p:layoutUnit>
</p:layout>
</h:form>
</h:body>
我managedBean
package br.jus.tjpe.infosistelecom.controle;
import br.jus.tjpe.infosistelecom.dao.OrgaoDao;
import br.jus.tjpe.infosistelecom.dao.RamalDao;
import br.jus.tjpe.infosistelecom.factory.OrgaoDaoFactory;
import br.jus.tjpe.infosistelecom.factory.RamalDaoFactory;
import br.jus.tjpe.infosistelecom.modelo.Ramal;
import java.io.Serializable;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import org.primefaces.event.NodeCollapseEvent;
import org.primefaces.event.NodeExpandEvent;
import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.TreeNode;
@ManagedBean
@RequestScoped
public class RelatorioBean implements Serializable {
private ArrayList<Ramal> ramais;
private ArrayList<String> cidades;
private String[] selectedCidades;
private TreeNode root = new DefaultTreeNode("Root Node", null);;
private boolean polo;
private String teste;
public String getTeste() {
return teste;
}
public void setTeste(String teste) {
this.teste = teste;
}
public boolean getPolo() {
return polo;
}
public void setPolo(boolean polo) {
this.polo = polo;
}
public String[] getSelectedCidades() {
return selectedCidades;
}
public void setSelectedCidades(String[] selectedCidades) {
this.selectedCidades = selectedCidades;
}
public ArrayList<String> getCidades() {
return cidades;
}
public void setCidades(ArrayList<String> cidades) {
this.cidades = cidades;
}
public TreeNode getRaiz() {
return root;
}
public void setRaiz(TreeNode raiz) {
this.root = raiz;
}
public ArrayList<Ramal> getRamais() {
return ramais;
}
public void setRamais(ArrayList<Ramal> ramais) {
this.ramais = ramais;
}
@PostConstruct
public void init() {
cidades = new ArrayList<String>();
OrgaoDao daoOrgao = OrgaoDaoFactory.createOrgaoDao();
cidades = daoOrgao.listarCidades();
// ramais = new ArrayList<Ramal>();
// RamalDao daoRamal = RamalDaoFactory.createRamalDao();
// ramais = daoRamal.listarTudo();
// DefaultTreeNode no = new DefaultTreeNode("hgshdgs", this.root);
// DefaultTreeNode no1 = new DefaultTreeNode("hgssdsdshdgs", this.root);
// DefaultTreeNode no2 = new DefaultTreeNode("hgshdnjhsdghjdagjhggs", no1);
// DefaultTreeNode no3 = new DefaultTreeNode("hgshdnjhsdghjdagjhggs", this.root);
// DefaultTreeNode no24= new DefaultTreeNode("hgshdnjhsdghjdagjhggs", no3);
}
public void montarRaiz() {
//System.out.println("diuyfuidyfuidyfuidy");
// root = new DefaultTreeNode("Root Node", null);
// ramais = new ArrayList<Ramal>();
// RamalDao daoRamal = RamalDaoFactory.createRamalDao();
// ramais = daoRamal.listarTudo();
// DefaultTreeNode no = new DefaultTreeNode(ramais.get(0), raiz);
// DefaultTreeNode no1 = new DefaultTreeNode(ramais.get(1), raiz);
//
// for (Ramal ramal : ramais) {
//
// new DefaultTreeNode(ramal, this.root);
//
// }
//
DefaultTreeNode no = new DefaultTreeNode("hgshdgs", this.root);
DefaultTreeNode no1 = new DefaultTreeNode("hgssdsdshdgs", this.root);
DefaultTreeNode no2 = new DefaultTreeNode("hgshdnjhsdghjdagjhggs", no1);
DefaultTreeNode no3 = new DefaultTreeNode("hgshdnjhsdghjdagjhggs", this.root);
DefaultTreeNode no24= new DefaultTreeNode("hgshdnjhsdghjdagjhggs", no3);
// System.out.println(selectedCidades[0]);
// System.out.println(selectedCidades[1]);
}
}
我曾嘗試解決它,但沒有成功。
謝謝你,我會去測試。 –