来自另一个bean的getselectednode(primefaces)

时间:2014-07-25 04:16:22

标签: jsf jsf-2 primefaces treenode

我有一个treeNode和其他托管bean的ManagedBean,我希望得到selectedNode,并且从getType我想执行一些代码,但问题是每次我得到这个问题时都无法得到selectedNode:< / p>

 java.lang.NullPointerException: javax.faces.FacesException: #{dimMan.makeDim()}: java.lang.NullPointerException

这是我的两个Managed bean:

@ManagedBean
@ViewScoped
public class TreeBean implements Serializable {

    private static final long serialVersionUID = 2417620239014385855L;
    private TreeNode root;
    private TreeNode selectedNode;
.....

另一个我想测试所选节点的类型:

@ManagedBean(name = "dimMan")
@SessionScoped
public class DimenssionManaged {

    @EJB
    DimensionDaoRemote dimService;

    @Inject
    TreeBean treeSelected;
    String select;

    public TreeBean getTreeSelected() {
        return treeSelected;
    }
    public void setTreeSelected(TreeBean treeSelected) {
        this.treeSelected = treeSelected;
    }
    public void makeDim(){

        System.out.println("adding dimen");
        fkey=tTable.getSelectedFk();
        dimUpdate.setFk_dimension(fkey);
        dimUpdate.setType_dimension(selectedType);
        select=treeSelected.getSelectedNode().getParent().getType();

        System.out.println(select);

        if (select=="cube"){
            CubeBase cub=cubManged.getCubUpdate();
            dimUpdate.setCube(cub);
            dimService.creat_dimension(dimUpdate);
        }
        else {
            SchemaBase sh=shmanged.getSchema();
            dimUpdate.setSchema(sh);
            dimService.creat_dimension(dimUpdate);
        }


    }

我也尝试使用这个注释@ManagedProperty(value =***),但它不起作用,我应该如何从其他ManagedBean中获取selectedNode类型?

1 个答案:

答案 0 :(得分:0)

DimenssionManaged ManagedBean与其他页面关联?如果是这样,导航TreeBean将导致@ViewScoped以来的数据丢失。

TreeBean更改为@SessionScoped即使在导航后也会保留数据,但是再次清除/刷新数据是一个问题。