限制添加节点primefaces

时间:2014-07-08 04:25:39

标签: jsf-2 primefaces treenode

我有这个:

 public void addView(){
        vi.setName_view("View");

        System.out.println(selectedNode.getParent().getData());
         TreeNode node0 = new DefaultTreeNode(new TreeNodeType().getVIEW_TYPE(),vi.getName_view()+""+v++, selectedNode);

        FacesContext context= FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "View "+vi.getName_view()+" Added to "+"Cube "+cub.getName_cube(), ""));
    }

我想在某个父节点中添加一个这种类型的节点,所以如果在这个节点下,我应该进行一次测试,我有多个View你可以帮帮我吗?

2 个答案:

答案 0 :(得分:0)

试试这个解决方案它会对你有用:

   public void addView(){

        vi.setName_view("View");
        //System.out.println(selectedNode.getRowKey()); 
        //System.out.println(selectedNode.getChildCount());
    int i=0;
         TreeNode node0;
            List<TreeNode> testNode=selectedNode.getParent().getChildren();

            for ( i= 0;i<testNode.size();i++){
                FacesContext context= FacesContext.getCurrentInstance();

                System.out.println(testNode.get(i).getChildren());
                if(testNode.get(i).getChildren().isEmpty() || testaddView == false  ){
                    node0 = new DefaultTreeNode(new TreeNodeType().getVIEW_TYPE(),vi.getName_view()+""+v++, selectedNode);

                    context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, vi.getName_view()+" Added to "+cub.getName_cube(), "")); 
             testaddView = true;
             }

                else{
                            FacesContext contexte= FacesContext.getCurrentInstance();
                            contexte.addMessage("Warrning", new FacesMessage(FacesMessage.SEVERITY_WARN, "Warnning", "You can't add other View To this Cube")); 

                        }

            }

    }

答案 1 :(得分:0)

你可以尝试这个代码,它对我有用:

public void changeName(){

        String res =selectedNode.getData().toString();

    voila =root.getChildren().get(0);
        if(selectedNode.getData().toString() !=null){
            res=cubMang.cubUpdate.getName_cube();

            selectedNode= new DefaultTreeNode(new TreeNodeType().getCUBE_TYPE(),res, voila);

        TreeNode test= voila.getChildren().get(0);
        selectedNode.getParent().getChildren().remove(voila.getChildren().lastIndexOf(selectedNode)-1);

    }


    }