JSF Primefaces Commandbutton没有更新AJAX

时间:2014-04-25 15:48:23

标签: ajax jsf-2 primefaces

我想在表格的元素之后更新Button“buttonEditRole” 选择了“dataTableSupUserRoles”。当元素为
时,该按钮应该被启用 选择。调用行选择后的监听器方法 在这个方法中,我将“disableNewSupUserRoleButton”设置为true。这也有效,但按钮无法启用 这是我的xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
    <ui:composition>
        <h:form id="formUserSettingsTabRole">
            <p:panelGrid>

                <p:row>
                    <p:column>
                        <p:dataTable id="dataTableSupUserRoles"
                            value="#{userSettingBean.supplierUserRoleList}" var="roles"
                            rowKey="#{roles.ID}"
                            selection="#{userSettingBean.selectedSupUserRole}"
                            selectionMode="single" paginator="true"
                            paginatorPosition="bottom" rows="10">

                            <p:ajax event="rowSelect"
                                update=":tabViewUserSettings:formUserSettingsTabRole:buttonEditRole"
                                listener="#{userSettingBean.onSupplierUserRoleRowSelect}" />

                            <p:column headerText="#{msg['global_company_tile']}">
                                <h:outputText value="#{roles.SUPPLIER.NAME}"
                                    styleClass="#{roles.IS_CONFIRMED ? 'textGreen' : 'textRed'}" />
                            </p:column>
                            <p:column headerText="#{msg['global_address_location']}">
                                <h:outputText
                                    value="#{roles.SUPPLIER.CITY}, #{roles.SUPPLIER.COUNTRY}"
                                    styleClass="#{roles.IS_CONFIRMED ? 'textGreen' : 'textRed'}" />
                            </p:column>
                            <p:column headerText="#{msg['global_role']}">
                                <h:outputText value="#{roles.ROLE.NAME}"
                                    styleClass="#{roles.IS_CONFIRMED ? 'textGreen' : 'textRed'}" />
                            </p:column>


                            <p:column>
                                <p:commandButton id="ComButSeeCurrentRole" icon="ui-icon-search"
                                styleClass="ui-blockui"/>

                                <p:overlayPanel for="ComButSeeCurrentRole">
                                    <p:outputLabel value="bababubu"/>
                                </p:overlayPanel>
                            </p:column>




                            <p:column headerText="#{msg['global_company_delete']}">
                                <p:commandButton id="ComButtDeleteSupUsRole" title="Delete"
                                    immediate="true" type="submit" update="dataTableSupUserRoles"
                                    actionListener="#{userSettingBean.deleteSupplierUserRole}"
                                    icon="ui-icon-trash">
                                    <f:param name="delteSupUserRole" value="#{roles.ID}" />
                                </p:commandButton>
                            </p:column>

                        </p:dataTable>
                    </p:column>
                </p:row>

                <p:row>
                    <p:column>
                        <p:commandButton id="buttonAddRole" value="#{msg['global_new']}" />

                        <p:overlayPanel id="OverLayPanelNewRole" for="buttonAddRole"
                            styleClass="ui-blockui">

                            <p:dataTable id="DataTableCompany"
                                value="#{userSettingBean.supplierList}" var="company"
                                selectionMode="single" rowKey="#{company.ID}"
                                selection="#{userSettingBean.selectedSupplier}" paginator="true"
                                paginatorPosition="bottom">

                                <p:ajax event="rowSelect" listener="#{userSettingBean.onNewSupUserRoleTableSelect}"
                                update=":tabViewUserSettings:formUserSettingsTabRole:CommandButtonSaveNewRole"/>


                                <p:column headerText="#{msg['global_company_tile']}">
                                    <p:outputLabel value="#{company.NAME}" />
                                </p:column>
                                <p:column headerText="Location">
                                    <p:outputLabel value="#{company.location}" />
                                </p:column>

                            </p:dataTable>

                            <p:outputLabel value="#{msg['global_role']}" />

                            <p:selectOneMenu id="SelectOneMenuRoles"
                                value="#{userSettingBean.selectedRole}" converter="roleIDConverter">

                                <f:selectItems value="#{userSettingBean.roleList}" var="role"
                                    itemLabel="#{role.NAME}" itemValue="#{role}" style="width:100%" />
                            </p:selectOneMenu>


                            <p:outputLabel value="#{msg['global_company_comment']}" />

                            <p:inputTextarea id="inpTxtACompCommentMyRole" rows="6" cols="33"
                                value="#{userSettingBean.newRoleComment}" maxlength="1000"
                                style="width:97%" />

                            <p:commandButton id="CommandButtonSaveNewRole" value="#{msg['global_company_form_status_create']}"
                                actionListener="#{userSettingBean.addSupplierUserRole}"
                                immediate="true" disabled="#{userSettingBean.disableNewSupUserRoleButton}"
                                update="dataTableSupUserRoles formUserSettingsTabRole" />


                        </p:overlayPanel>




                        <p:commandButton id="buttonEditRole" value="#{msg['global_company_form_status_edit']}"
                            disabled="#{userSettingBean.disableNewSupUserRoleButton}"
                            actionListener="#{userSettingBean.editSupplierUserRole}"
                            update="buttonEditRole outPLabelCompNameEdit dataTableSupUserRoles"
                            immediate="true" />


                        <p:outputLabel id="testLabel"
                            value="#{selectedSupUserRole.SUPPLIER.NAME}" />


                        <p:overlayPanel id="OverLayPanelEditRole" for="buttonEditRole"
                            styleClass="ui-blockui">
                            <p:panelGrid columns="2">

                                <p:outputLabel value="#{msg['global_company_tile']}" />

                                <p:outputLabel id="outPLabelCompNameEdit" disabled="true"
                                    value="#{selectedSupUserRole.SUPPLIER.NAME}" />

                                <p:outputLabel value="#{msg['global_role']}" />



                                <p:selectOneMenu id="SelectOneMenuRolesEdit"
                                    value="#{userSettingBean.selectedRole}" onchange="submit()"
                                    valueChangeListener="#{userSettingBean.roleChanged}">
                                    <f:selectItems value="#{userSettingBean.roleList}" var="role"
                                        itemLabel="#{role.NAME}" style="width:100%" />
                                </p:selectOneMenu>

                            </p:panelGrid>

                            <p:outputLabel value="#{msg['global_company_comment']}" />
                            <p:inputTextarea id="inpTxtACompCommentMyRoleEdit" rows="6"
                                cols="33" value="#{userSettingBean.newRoleComment}"
                                maxlength="1000" style="width:97%" />

                            <p:commandButton value="#{msg['global_company_save']}"
                                actionListener="#{userSettingBean.saveEditedSupUserRole}"
                                immediate="true"
                                update="dataTableSupUserRoles formUserSettingsTabRole" />
                        </p:overlayPanel>
                    </p:column>
                </p:row>


            </p:panelGrid>
        </h:form>

    </ui:composition>
</h:body>
</html>

听众方法:

public void onSupplierUserRoleRowSelect(SelectEvent e){

    this.disableSupUserRoleButtons=false;
}

1 个答案:

答案 0 :(得分:0)

您可以更新整个表单而不是命令按钮。

试试这个:

update = "@form"