简体   繁体   中英

how to add image from java bean to <p:tree created dynamically?

to display <p: tree I do :

<p:tree id="id" value="#{beanSession.rootAlpha}" var="node" selection="#{beanSession.selectedNode}" selectionMode="single"dynamic="true" cache="false">
    <p:treeNode>
        <h:outputText value="#{node}" />
    </p:treeNode>
</p:tree>

in my java bean I used :

 private TreeNode rootAlpha;

....

output result :

>(not image here) A
   > (image) ALLEMAGNE
      >(image) BERLIN
  >ALGERIA
> B
> C
...

I want to add an image (icon) on the childnode ex : ALLEMAGNE and BERLIN but not in the parent node ex ABC ...

the response is to add type as this :

<p:tree id="id" value="#{beanSession.rootAlpha}" var="node" selection="#{beanSession.selectedNode}" selectionMode="single"dynamic="true" cache="false">
    <p:treeNode>
        <h:outputText value="#{node}" />
    </p:treeNode>
    <p:treeNode type="B">
        <h:outputText value="#{node}" />
    </p:treeNode>
    <p:treeNode type="C">
        <h:outputText value="#{node}" />
    </p:treeNode>
</p:tree>

and in the java bean, we must add this type when we construct the tree : exmple with the seconde noode : // 2eme noeud

DefaultTreeNode node2 = newDefaultTreeNode("B",                                     "ALLEGMAGNE", node1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM