简体   繁体   English

如何从dataTable内部的selectOneMenu中删除所选项目?

[英]How to remove a selected item from a selectOneMenu inside a dataTable?

I have a <p:dataTable/> and on each row I have a <p:selectOneMenu/> and they are a list of integers from 1 to the number of items present on the list. 我有一个<p:dataTable/> ,在每一行上都有一个<p:selectOneMenu/> ,它们是从1到列表中存在的项目数的整数列表。 So if I have a list with 30 items on my <p:dataTable /> on each <p:selectOneMenu/> will show the options from 1 to 30. However, I am facing a problem with these <p:selectOneMenu /> inside my <p:dataTable /> . 因此,如果我在每个<p:selectOneMenu/> <p:dataTable />上有30个项目的列表,将显示从1到30的选项。但是,我在内部遇到这些<p:selectOneMenu />我的<p:dataTable /> If an item is selected in one row I have to remove this item from the others <p:selectOneMenu/> . 如果在一行中选择了一项,则必须从其他<p:selectOneMenu/>项中删除该项。 For instance, if the item '1' is selected then all the others cannot have the number '1' available as an option to be selected. 例如,如果选择了项“ 1”,则所有其他项都不能具有数字“ 1”作为要选择的选项。

So is there a way that I can do on my managed bean/controller? 那么,有什么办法可以对我的托管bean /控制器进行处理吗? I've tried to get the <p:selectionOneMenu/> by using javascript but I didn't succeed because I had problems to get the clientId and also the selectOneMenu uses a div in order to show the items. 我尝试使用javascript获取<p:selectionOneMenu/> ,但未成功,因为我在获取clientId时遇到问题,而且selectOneMenu使用div来显示项目。 Any thoughts on this issue? 对这个问题有什么想法吗?

This is my xhtml 这是我的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>

have different option arrays for each select one menu in your backing bean. 对于每个在后备bean中选择一个菜单的菜单,都有不同的选项数组。

then use them in f:selectItems as below: 然后在f:selectItems中使用它们,如下所示:

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

in your event listener method, get your row index as a parameter, as below: 在事件侦听器方法中,将行索引作为参数,如下所示:

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

then remove the selected item from all option arrays except listaPrioridades[index] . 然后从listaPrioridades[index]之外的所有选项数组中删除所选项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM