我想用primefaces树元素创建时间轴。我有月份名单。我想把这个列表放在每年,如下图所示。
我使用jsf和ManagedBean命名TreeBean。
我的jsf:
enter code here <h:form id="tmLine">
<div style="width:30%; float:left; ">
<p:tree id="treeSingle" value="#{treeBean.root}" var="node"
style="border:none; border-right:1px solid #aaa;width:100%; border-radius:0px;background:#fff; font-size:100%; "
selectionMode="single"
selection="#{treeBean.selectedNode}" animate="true" >
<p:ajax event="select" update=":tmLine:info"/>
<p:treeNode>
<h:outputText value="#{node}" />
</p:treeNode>
</p:tree>
</div>
<div style="width:69%; float:left; margin-left:1%;">
<h:outputText value="#{treeBean.testt}" id="info"/>
</div>
<div style="clear:both"/>
</h:form>
TreeBean是:
enter code here public class TreeBean{
private TreeNode root;
private TreeNode selectedNode;
public TreeBean() {
root = new DefaultTreeNode("Root", null);
TreeNode node0 = new DefaultTreeNode("2011", root);
TreeNode node1 = new DefaultTreeNode("2012", root);
TreeNode node2 = new DefaultTreeNode("2013", root);
TreeNode node00 = new DefaultTreeNode("Ýanwar", node0);
TreeNode node01 = new DefaultTreeNode("Fewral", node0);
TreeNode node02 = new DefaultTreeNode("Mart", node0);
TreeNode node03 = new DefaultTreeNode("Aprel", node0);
TreeNode node04 = new DefaultTreeNode("Maý", node0);
TreeNode node05 = new DefaultTreeNode("Iýun", node0);
TreeNode node06 = new DefaultTreeNode("Iýul", node0);
TreeNode node07 = new DefaultTreeNode("Awgust", node0);
TreeNode node08 = new DefaultTreeNode("Sentýabr", node0);
TreeNode node09 = new DefaultTreeNode("Oktýabr", node0);
TreeNode node10 = new DefaultTreeNode("Noýabr", node0);
TreeNode node11 = new DefaultTreeNode("Dekabr", node0);
TreeNode node100 = new DefaultTreeNode("Node 1.0.0", node10);
}
public TreeNode getRoot() {
return root;
}
public TreeNode getSelectedNode() {
return selectedNode;
}
public void setSelectedNode(TreeNode selectedNode) {
this.selectedNode = selectedNode;
}
public void displaySelectedSingle(ActionEvent event) {
if(selectedNode != null) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Selected", selectedNode.getData().toString());
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
public String getTestt()
{
if(selectedNode!=null)
return selectedNode.getData().toString()+" of 2011 ............Events....";
else
return "";
}
}
答案 0 :(得分:0)
我解决了我的问题。这是一个正确的bean代码:
public class TreeBean{
private TreeNode root;
private TreeNode selectedNode;
public TreeBean() {
root = new DefaultTreeNode("Root", null);
TreeNode node0 = new DefaultTreeNode("2011", root);
TreeNode node1 = new DefaultTreeNode("2012", root);
TreeNode node2 = new DefaultTreeNode("2013", root);
EnumMonths[] arrayMonth=EnumMonths.values();
TreeNode[] treelar=new TreeNode[arrayMonth.length];
for (int i = 0; i < arrayMonth.length; i++) {
treelar[i]=new DefaultTreeNode(arrayMonth[i], node0);
}
for (int i = 0; i < arrayAylar.length; i++) {
treelar[i]=new DefaultTreeNode(arrayMonth[i], node1);
}
for (int i = 0; i < arrayMonth.length; i++) {
treelar[i]=new DefaultTreeNode(arrayMonth[i], node2);
}
}
public TreeNode getRoot() {
return root;
}
public TreeNode getSelectedNode() {
return selectedNode;
}
public void setSelectedNode(TreeNode selectedNode) {
this.selectedNode = selectedNode;
}
public void displaySelectedSingle(ActionEvent event) {
if(selectedNode != null) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Selected", selectedNode.getData().toString());
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
public String getTestt()
{
if(selectedNode!=null)
return selectedNode.getData().toString()+" of "+ selectedNode.getParent().getData().toString()+" ............Events....";
else
return "";
}
}