ManagedBean不声明公共无参数构造函数

时间:2016-02-29 10:59:55

标签: jsf constructor managed-bean

我正在使用PrimeFaces 5.0并希望在点击事件后在弹出框内创建<p:treeTable>,但其显示以下错误

  

无法创建托管bean popupTreeTableManagedBean。下列   发现问题: - 托管bean类   托管bean的beans.PopupTreeTableManagedBean   popupTreeTableManagedBean未声明公开的无争论   构造函数。 - 托管bean类beans.PopupTreeTableManagedBean   托管bean popupTreeTableManagedBean不声明公开   无参数构造函数。

以下是我的代码段

的index.xhtml:

<p:dialog header="" widgetVar="dlg1" minHeight="200">
    <p:treeTable value="#{popupTreeTableManagedBean.root}" var="node" style="" >
        <p:column>
            <f:facet name="header">Name</f:facet>
            <h:outputText value="#{node.name}"></h:outputText>
        </p:column>

        <p:column>
            <f:facet name="header">Value</f:facet>
            <h:inputText value="#{node.value}" style="border-style: hidden;"/>
        </p:column>
    </p:treeTable>
</p:dialog>

PopupTreeTableManagedBean.java

@ManagedBean
@SessionScoped
public class PopupTreeTableManagedBean {

    private TreeNode root = new DefaultTreeNode("Root Node", null);
    List<String> selectedParams;
    TreeNode scanParamsRoot = null;

    PopupTreeTableManagedBean() {
        selectedParams = GenrateScanList.getParamList();
        createRootAndLeafNodes();
    }

    private TreeNode createRootAndLeafNodes() {
        TreeNode scanSubRoot = null;
        int size = selectedParams.size();
        TreeNode scanRoot = new DefaultTreeNode(new Document("scanParams", ""), this.root);
        scanSubRoot = new DefaultTreeNode(new Document("Sub Root", ""), scanRoot);

        Document relationshipValue = new Document("Hi", "");
        TreeNode documentss06 = new DefaultTreeNode(relationshipValue, scanSubRoot);
        return root;
    }

    private DefaultTreeNode getTreeNodeObject() {
        return new DefaultTreeNode();
    }

    private Document getDocumentObject() {
        return new Document(null, null);
    }

    public TreeNode getRoot() {
        return root;
    }

    public void setRoot(TreeNode root) {
        this.root = root;
    }
}

1 个答案:

答案 0 :(得分:4)

错误消息显示您需要public构造函数,但构造函数 package private 。添加public关键字应该会有所帮助。