如何在primefaces中从backing bean传递变量

时间:2017-06-20 12:07:21

标签: jsf primefaces

我无法传递然后从辅助bean中检索变量。选择树节点时会调用我的add()函数:

public void add(TreeNode selectedTreeNode) {
    setMyid(((MyClass) selectedTreeNode.getData()).getId());

    System.out.println("id : " + getMyid());

    RequestContext.getCurrentInstance().execute("PF('dlgVar').show()");
}
public String saveAction() {
    String myid = FacesContext.getCurrentInstance().
        getExternalContext().getRequestParameterMap().get("myid");
    System.out.println("myid : " + myid);
}

public void setMyid(String myid) {
   this.myid = myid;
}

public String getMyid() {
   return myid;
}

对话框是:

<p:dialog id="dlgId" widgetVar="dlgVar" dynamic="true">
    <h:form>
        <h:panelGrid columns="1"> 
            <h:outputLabel for="nametext" value="Name" />
           <p:inputText id="nametext" value="#{myBean.name}" />
        </h:panelGrid>

        <p:commandButton value="Save" actionListener="#{myBean.saveAction}" >
           <f:param name="myid" value="#{myBean.myid}" />
        </p:commandButton>
    </h:form>
</p:dialog>

在saveAction()中打印的id为null,但在add()中设置时不为null。

如何从支持bean设置myid以便正确传递回saveAction()?

0 个答案:

没有答案
相关问题