0
我想在選中表
「dataTableSupUserRoles」的一個元素後更新Button「buttonEditRole」。當選擇了一個元素
時,該按鈕應該啓用。行選擇後的偵聽器方法被調用。
在這個方法中,我將「disableNewSupUserRoleButton」設置爲true。這也適用,但按鈕不啓用。
這裏是我的XHTML:JSF Primefaces Commandbutton沒有更新AJAX
<?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;
}
只是爲了測試嘗試刪除標記直接或值更改爲false,如果不行試試改變你的更新代碼ajav事件@form –
感謝您的答覆! 我試過了你的兩個提示,但它仍然不起作用。 – hiaslosch17
@ hiaslosch17支持bean的範圍是什麼?總是建議使用'@ ViewScoped'來獲得使用ajax操作的最佳結果 – kolossus