RequestContext.getCurrentInstance()。update不起作用

时间:2016-11-22 03:42:03

标签: java primefaces commandbutton requestcontext

我有一个带有commandbutton的JSF页面来显示对话框并显示来自datatable的数据,但问题RequestContext.getCurrentInstance()。update没有更新对话框,有人能告诉我我的代码有什么问题吗?

这是我的JSF代码

    <h:form id="formEmp">
        <p:commandButton value="Edit"
                         id="buttonUpdate"
                         actionListener="#{masterRoleController.doUpdate()}"/>

        <br/>
        <p:separator/>

        <p:dataTable id="dtEmployee" 
                     value="#{masterRoleController.lazyUserRole}" var="dtEmp"
                     selectionMode="single"
                     selection="#{masterRoleController.userRole}"
                     rowKey="#{dtEmp.roleId}"
                     paginator="true"
                     rowsPerPageTemplate="15, 25, 50"
                     rows="15"
                     lazy="true"
                     resizableColumns="true"
                     emptyMessage="No Data"
                     styleClass="eric-panelgrid">

                                <p:ajax event="rowSelect"
                                        listener="#{masterRoleController.enableButtonEdit()}"
                                        update=":formEmp:buttonDelete, :formEmp:buttonUpdate" />

            <p:column headerText="Id">
                <h:outputText value="#{dtEmp.roleId}" styleClass="eric-textInput"/>
            </p:column>
            <p:column headerText="Role Name">
                <h:outputText value="#{dtEmp.roleName}" styleClass="eric-textInput"/>
            </p:column>
            <p:column headerText="Role Desc" style="width: 50%">
                <h:outputText value="#{dtEmp.roleDesc}" styleClass="eric-textInput"/>
            </p:column>

        </p:dataTable>
    </h:form>
</center>

<h:form id="formDlgUpdate">
            <p:dialog id="dlgUpdate"
                      widgetVar="widDlgUpdate"
                      header="Update Role"
                      modal="true"
                      resizable="false"
                      dynamic="true"
                      showEffect="fade"
                      hideEffect="fade"
                      draggable="false">
                <p:panelGrid id="pgridUpdate" columns="3" >
                    <h:outputText value="Role Name"/>
                    <h:outputText value=":"/>
                    <p:inputText id="inEmpTpName"
                                 value="#{masterRoleController.userRole.roleName}"
                                 required="true"
                                 requiredMessage="Name must be filled."
                                 maxlength="50"
                                 onblur="value = value.toUpperCase();
                                             value = trim(this.value)"
                                 onkeypress="return checkAlpNumeric(event)">
                        <f:validator validatorId="com.hospital.util.validator.UniqueValidator"/>
                        <f:attribute name="table" value="user_role"/>
                        <f:attribute name="column" value="role_name" />
                        <f:attribute name="info" value="Test Role"/>
                        <f:attribute name="actInfo" value="#{masterRoleController.actInfo}"/>
                        <f:attribute name="compare" value="#{masterRoleController.nameTemp}"/>
                    </p:inputText>

                    <h:outputText value="Role Desc"/>
                    <h:outputText value=":"/>
                    <p:inputTextarea value="#{masterRoleController.userRole.roleDesc}"
                                     required="true"
                                     requiredMessage="Description must be filled."
                                     maxlength="100"
                                     onblur="value = value.toUpperCase();
                                                 value = trim(this.value)"
                                     onkeypress="return checkAlpNumeric(event)"/>

                    <h:outputText value=""/>
                    <h:outputText value=""/>
                    <p:commandButton value="Edit"
                                     actionListener="#{masterRoleController.update()}"
                                     update="pgridUpdate">
                    </p:commandButton>
                </p:panelGrid>
            </p:dialog>
        </h:form>

,这是我的托管

public void doUpdate() {
        headerInsUpd = "Update";
        toggleBtnInsUpd = false;
        actInfo = "U";
        nameTemp = userRole.getRoleName();
        RequestContext.getCurrentInstance().execute("PF('widDlgUpdate').show()");
        RequestContext.getCurrentInstance().update("formDlgUpdate:dlgUpdate");
    }

1 个答案:

答案 0 :(得分:-1)

它不起作用,因为您的对话框是动态的( dynamic =“true”)。 您应该禁用动态行为以实现您想要的。或者在对话框打开后不更新对话框itselt,而是更新对话框内的组件。