如何从支持 bean 突出显示 primefaces 树节点
我正在使用 primefaces 树组件。树有一个上下文菜单(添加节点、编辑节点、删除节点)。执行某些操作后,我需要刷新树,然后突出显示添加或编辑的节点。
这是我的代码。
index.xhtml
<p:treeNode>
<h:outputText value="#{node}" />
</p:treeNode>
</p:tree>
<p:contextMenu for="pTree" id="cmenu">
<p:menuitem value="Add topic as child" update="pTree, cmenu"
actionListener="#{treeBean.addChildNode}" />
<p:menuitem value="Add topic Below" update="pTree, cmenu"
actionListener="#{treeBean.addTopicBelow}" />
<p:menuitem value="Delete Topic" update="pTree, cmenu"
actionListener="#{treeBean.deleteNode}" />
</p:contextMenu>
treeBean.java
公共类 TreeBean 实现 Serialized {
private TreeNode root;
public TreeBean() {
root = new DefaultTreeNode("Root", null);
// GET the root nodes first L0
List<TracPojo> rootNodes = SearchDao.getRootNodes111();
Iterator it = rootNodes.iterator();
while (it.hasNext()) {
TracPojo t1 = (TracPojo) it.next();
String tid = t1.getTopicID();
TreeNode node1 = new DefaultTreeNode(t1, root);
}
}
public TreeNode getRoot() {
return root;
}
public void addChildNode(ActionEvent actionEvent)
{
List record = NewSearchDao.getRecord(selectedNode);
Iterator it = record.iterator();
while (it.hasNext()) {
Object[] record1 = (Object[]) it.next();
setParentID_dlg((String) record1[0]);
setSortIndex((Integer) record1[2]);
}
}
public void saveChilddNode() {
System.out.println("Save as Child Node ........");
}
}
I am working with primefaces tree component. There is a context menu for the tree (add a node, edit node, delete node). After performing some operation, I need to refresh the tree and then highlight the node added or edited.
This is my code.
index.xhtml
<p:treeNode>
<h:outputText value="#{node}" />
</p:treeNode>
</p:tree>
<p:contextMenu for="pTree" id="cmenu">
<p:menuitem value="Add topic as child" update="pTree, cmenu"
actionListener="#{treeBean.addChildNode}" />
<p:menuitem value="Add topic Below" update="pTree, cmenu"
actionListener="#{treeBean.addTopicBelow}" />
<p:menuitem value="Delete Topic" update="pTree, cmenu"
actionListener="#{treeBean.deleteNode}" />
</p:contextMenu>
treeBean.java
public class TreeBean implements Serializable {
private TreeNode root;
public TreeBean() {
root = new DefaultTreeNode("Root", null);
// GET the root nodes first L0
List<TracPojo> rootNodes = SearchDao.getRootNodes111();
Iterator it = rootNodes.iterator();
while (it.hasNext()) {
TracPojo t1 = (TracPojo) it.next();
String tid = t1.getTopicID();
TreeNode node1 = new DefaultTreeNode(t1, root);
}
}
public TreeNode getRoot() {
return root;
}
public void addChildNode(ActionEvent actionEvent)
{
List record = NewSearchDao.getRecord(selectedNode);
Iterator it = record.iterator();
while (it.hasNext()) {
Object[] record1 = (Object[]) it.next();
setParentID_dlg((String) record1[0]);
setSortIndex((Integer) record1[2]);
}
}
public void saveChilddNode() {
System.out.println("Save as Child Node ........");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Primefaces
p:treeNode
有一个属性styleClass
。您可以从支持 bean 动态设置它。视图将如下所示:然后使用 get/set 方法将成员 styleClass 添加到您的 TreeBean,该方法返回表示样式类的字符串:
不要忘记将样式类添加到您的 css。
Primefaces
p:treeNode
has an attributestyleClass
. You could set this dynamically from your backing bean. The view would look like:Then add a member styleClass to your TreeBean with get/set method that returns a string representing the style class:
Don't forget to add the style classes to your css.
除非您将声明为 selection="#{treeBean.selectedNode}" 的 selectedNode 设置为 null,否则它已被选中,您唯一要做的就是从触发元件;在你的情况下是:
Unless you set the selectedNode, which you declare as selection="#{treeBean.selectedNode}", to null, it is already selected and the only thing you have to do is to update the tree component from the triggering component; in your case it is: