我有一个数据表,其中第一个colm是删除而最后一个colm是默认复选框, 我想在选中默认值时禁用删除命令链接
<p:dataTable value="#{itemRelationshipBean.selectedItemsList}" var="selectedItem" styleClass="selected_item_table">
<p:column styleClass="delete" headerText="#{msg['item.relationship.delete.column']}">
<h:commandLink styleClass="cross_icon">
<p:ajax immediate="true" event="click" update=":relationshipForm:selectedItemsPanel"
listener="#{itemRelationshipBean.updateRelatedItemsList(true,selectedItem.itemId,selectedItem.itemName)}"
process="@this" onstart="loadingDialog.show();"
oncomplete="loadingDialog.hide();addCSS();"/>
</h:commandLink>
</p:column>
<p:column headerText="Item Name">#{selectedItem.itemName}</p:column>
<p:column styleClass="variants" headerText="#{msg['item.relationship.variants.column']}">
<h:selectOneMenu value="#{selectedItem.relationId}" style="width:80px; font-size:12px;" id="selectedCategoryId" styleClass="category">
<f:selectItem itemValue="#{null}" itemLabel="Select" />
<f:selectItems value="#{itemRelationshipBean.selRelationVariants}" var="relVariant" itemLabel="#{relVariant.relationForm}"
itemValue="#{relVariant.relationId}" />
<f:ajax />
</h:selectOneMenu>
</p:column>
<p:column styleClass="default" headerText="#{msg['item.relationship.is.default.column']}">
<h:selectBooleanCheckbox id="checkBoxDefault" value="#{selectedItem.defaultVal}" onclick="dataTableSelectOneRadio(this);" disabled="true">
<f:ajax/>
</h:selectBooleanCheckbox>
</p:column>
</p:dataTable>
答案 0 :(得分:0)
改为使用p:commandLink
,它提供开箱即用的disabled
属性:
<p:commandLink styleClass="cross_icon" disabled="#{selectedItem.defaultVal}" />
答案 1 :(得分:0)
为简单起见,您可以使用Primefaces中的commandLink和selectBooleanCheckbox(如Xtreme Biker所述)。
我注意到您的 selectBooleanCheckbox 设置为禁用(禁用=“true”)。这将阻止该组件的模型更新,并且 selectedItem.defaultVal 值可能永远不会更改。
您可能需要重新访问 dataTableSelectOneRadio 函数并进行适当的修改(请注意,在Primefaces的selectBooleanCheckbox组件中未定义onclick);
以下是我对数据表的建议:
<p:dataTable value="#{itemRelationshipBean.selectedItemsList}" var="selectedItem" styleClass="selected_item_table">
<p:column styleClass="delete" headerText="#{msg['item.relationship.delete.column']}">
<p:commandLink id="deleteCl" styleClass="cross_icon" process="@this" immediate="true" update=":relationshipForm:selectedItemsPanel"
actionListener="#{itemRelationshipBean.updateRelatedItemsList(true,selectedItem.itemId,selectedItem.itemName)}"
onstart="loadingDialog.show();" oncomplete="loadingDialog.hide();addCSS();" />
</p:column>
<p:column headerText="Item Name">#{selectedItem.itemName}</p:column>
<p:column styleClass="variants" headerText="#{msg['item.relationship.variants.column']}">
<h:selectOneMenu value="#{selectedItem.relationId}" style="width:80px; font-size:12px;" id="selectedCategoryId" styleClass="category">
<f:selectItem itemValue="#{null}" itemLabel="Select" />
<f:selectItems value="#{itemRelationshipBean.selRelationVariants}" var="relVariant" itemLabel="#{relVariant.relationForm}"
itemValue="#{relVariant.relationId}" />
<f:ajax />
</h:selectOneMenu>
</p:column>
<p:column styleClass="default" headerText="#{msg['item.relationship.is.default.column']}">
<p:selectBooleanCheckbox id="checkBoxDefault" value="#{selectedItem.defaultVal}">
<p:ajax process="@this" update="deleteCl" />
</p:selectBooleanCheckbox>
</p:column>
</p:dataTable>