如何从数据表内的selectOneMenu中删除所选项目

How to remove a selected item from a selectOneMenu inside a dataTable?

本文关键字:删除 选项 项目 selectOneMenu 数据表      更新时间:2023-09-26

我有一个<p:dataTable/>,每行都有一个<p:selectOneMenu/>,它们是从1到列表中项目数的整数列表。因此,如果我的<p:dataTable />上有一个包含30个项目的列表,则每个<p:selectOneMenu/>上将显示从1到30的选项。然而,我的<p:dataTable />中的这些<p:selectOneMenu />遇到了问题。如果在一行中选择了一个项目,我必须从其他<p:selectOneMenu/>中删除该项目。例如,如果选择了项目"1",则所有其他项目都不能将数字"1"作为要选择的选项。

那么,有没有一种方法可以在我的托管bean/控制器上实现呢?我曾尝试使用javascript获取<p:selectionOneMenu/>,但没有成功,因为我在获取clientId时遇到了问题,而且selectOneMenu使用div来显示项目。对这个问题有什么想法吗?

这是我的xhtml

<p:dataTable id="dataTableSolicitacoes" value="#{pesquisarItemSolicInvestController.listaSolicitacoes}"
            selectionMode="single" var="_solicitacao" rowKey="#{_solicitacao.index}" rowIndexVar="index"
            selection="#{pesquisarItemSolicInvestController.linhaSelecionada}"
        <p:ajax event="rowSelect" listener="#{pesquisarItemSolicInvestController.onRowSelect}" process="@(#dataTableSolicitacoes)" update="@(#dataTableSolicitacoes), @(#panelBotoes)" />       
        <p:column style="vertical-align: middle; width: 60px !important;">
            <f:facet name="header"> 
                <h:outputText value="#{messages.LABEL_PRIORIDADE}" title="#{messages.TITLE_INFORME_ORDEM_PRIO}"/> 
            </f:facet>
            <p:selectOneMenu id="cbPrioridade" value="#{_solicitacao.prioridade}" style="width:60px !important;"
                styleClass="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all" 
                disabled="#{!mf:hasPermission(securityController,'manterItensEnviados,manter')}">
                    <f:selectItem itemLabel="" itemValue="" noSelectionOption="true" />
                    <f:selectItems value="#{pesquisarItemSolicInvestController.listaPrioridades}" />
                    <p:ajax event="change" listener="#{pesquisarItemSolicInvestController.mudarPrioridade(_solicitacao.index)}" 
                        process="@(#dataTableSolicitacoes), @(#panelBotoes)" update="@(#dataTableSolicitacoes), @(#panelBotoes)" />                 
            </p:selectOneMenu>
        </p:column>
    </p:dataTable>

在支持bean中为每个select one菜单都有不同的选项数组。

然后在f:selectItems中使用它们,如下所示:

<f:selectItems value="#{pesquisarItemSolicInvestController.listaPrioridades[index]}" />

在事件侦听器方法中,获取行索引作为参数,如下所示:

#{pesquisarItemSolicInvestController.mudarPrioridade(_solicitacao.index, index)}

则从除CCD_ 9之外的所有选项阵列中移除所选择的项目。