我在TreeTable的同一列中添加许多对象类型时遇到问题。创建TreeNodes的方法如下:
TreeNode taskProject = new DefaultTreeNode("node",projet,root);
for (Tache ta : listTache) {
tache = ta;
TreeNode taskNode = new DefaultTreeNode("node", tache, taskProject);
for (Activite ac : listActivite) {
activite = ac;
Tache tac = ac.getTache();
if (tac.getId() != ta.getId()) {continue;}
TreeNode taskActivite = new DefaultTreeNode("node",activite,taskNode);
for (Phase ph : listPhases){
phase = ph;
Activite act = ph.getActivite();
if (act.getId() != ac.getId()) {continue;}
TreeNode taskPhase = new DefaultTreeNode("leaf",phase,taskActivite);
}
}
}
之后,我尝试调用Treetable中的对象并且它正常工作,但是当我尝试在列中添加这些对象时不起作用。代码部分如下:
<p:treeTable id="treeTable" liveResize="true"
value="#{projetMediatorController.root}" var="projetMediator">
<f:facet name="header">
<h:outputText value="#{bundle.projet}" />
</f:facet>
<!-- column for the task/activities/phases -->
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.name}" />
</f:facet>
<!-- problem -->
<h:outputText value="#{projetMediatorController.projet.nomProjet}" />
<!-- <h:outputText value="#{projetMediatorController.tache.nomTache}"/> -->
<!--<h:outputText value="#{projetMediatorController.activite.nomActivite}"/>-->
<!--<h:outputText value="#{projetMediatorController.phase.phase}"/>-->
</p:column>
</p:treeTable>
问题是列出关于层次结构节点的“名称”列上的对象名称。
有人知道我该怎么做?
我很高兴你的关注。
谢谢!
答案 0 :(得分:2)
我用这段代码解决了我的问题:
root = new DefaultTreeNode("root", null);
TreeNode projetNode = new DefaultTreeNode("node", new Document(projet), root);
for (Tache ta : taches) {
TreeNode tacheNode = new DefaultTreeNode("node", new Document(ta), projetNode);
for (Activite ac : activites) {
Tache tache = ac.getTache();
if (tache.getId() != ta.getId()) { continue;}
TreeNode activiteNode = new DefaultTreeNode("node", new Document(ac), tacheNode);
for (Phase ph : phases) {
Activite activite = ph.getActivite();
if (activite.getId() != ac.getId()) {continue;}
TreeNode phaseNode = new DefaultTreeNode("leaf", new Document(ph), activiteNode);
}
}
}
我正在写这样的Document构造函数:
public class Document implements Serializable {
private static final long serialVersionUID = 1L;
private Projet projet;
private Tache tache;
private Activite activite;
private Phase phase;
private String nameProjet;
public Document(Object obj) {
if (obj instanceof Phase) {
phase = (Phase)obj;
}else if (obj instanceof Activite) {
activite = (Activite)obj;
}else if (obj instanceof Tache) {
tache = (Tache)obj;
}else{
projet = (Projet)obj;
}
}
//gets and sets
}
并完成,xhtml代码渲染每个“对象”行:
<p:treeTable id="treeTable" value="#{documentsController.root}"
var="document" selection="#{documentsController.selectedNode}" selectionMode="single" resizableColumns="true">
<f:facet name="header">
<h:outputText value="#{bundle.update} #{bundle.projet}" />
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.name}" />
</f:facet>
<p:outputLabel value="#{document.projet.nomProjet}" rendered="#{document.projet == null}"/>
<p:outputLabel value="#{document.tache.nomTache}" renderer="#{document.tache == null}" />
<p:outputLabel value="#{document.activite.nomActivite}" rendered="#{document.activite == null}"/>
<p:outputLabel value="#{document.phase.nomPhase}" rendered="#{document.phase == null}"/>
</p:column>
</p:treeTable>
答案 1 :(得分:0)
您不需要为节点数据对象构造特殊的类包装器。 直接在TreeNode中使用您的类实例而不是Document对象。 在xhtml中,在&lt; p:treeNode&gt; 元素上使用呈现属性。