java 选择复选框数据表primefaces上的行选择

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7454353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 20:02:22  来源:igfitidea点击:

row selection on selection checkbox datatable primefaces

javajsf-2primefaces

提问by Vish

we need to fire ajax event on row selection on toggle of checkbox..i tried to find example but they are only doing row selection on click of p:command button.we are using primefaces 2.2

我们需要在复选框切换时在行选择上触发 ajax 事件。

Code

代码

<p:dataTable id="insList" var="insured"
                        value="#{policyHandler.insuredList}" paginator="true"
                        rows="#{label.insuredList_defaultNumberOfRows}"
                        paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                        rowsPerPageTemplate="#{label.insuredList_numberOfRows}"
                        style="width: 98%;" selection="#{policyHandler.inquiryInsureds}">                           <!--<p:column>
                            <f:facet name="header">
                                <h:outputLabel value="Select" />
                            </f:facet>
                            <h:selectBooleanCheckbox id="selection"
                                value="#{insured.status}">
                                <p:ajax event="click" update="insuredOrder, selection" />
                            </h:selectBooleanCheckbox>
                        </p:column>
                        -->
                        <p:column selectionMode="multiple" />  
                        <p:column>
                            <f:facet name="header">
                                <h:outputLabel value="Sequence" />
                            </f:facet>
                            <p:cellEditor id="insuredOrder" disabled="#{!insured.status}">
                                <f:facet name="output">
                                    <h:outputText value="#{insured.sequence}" />
                                </f:facet>
                                <f:facet name="input">
                                    <p:inputText value="#{insured.sequence}" />
                                </f:facet>
                            </p:cellEditor>
                                <p:rowEditor />
                        </p:column>
                        <p:column headerText="Name"
                            sortBy="#{insured.generalPartyInfo.nameInfo.commlName.commercialName}"
                            filterMatchMode="contains" style="text-align:center;">
                            <h:outputText
                                value="#{insured.generalPartyInfo.nameInfo.commlName.commercialName}" />
                        </p:column>
                        <p:column sortBy="#{insured.generalPartyInfo.addr.city}"
                            style="text-align:center;">
                            <f:facet name="header">
                                <h:outputLabel value="Street Address" />
                            </f:facet>
                            <h:outputText value="#{insured.generalPartyInfo.addr.city}" />
                        </p:column>
                        <p:column sortBy="#{insured.generalPartyInfo.addr.city}"
                            style="text-align:center;" width="10%">
                            <f:facet name="header">
                                <h:outputLabel value="#{label.city}, #{label.state} " />
                                <h:outputLabel value=" #{label.postalcode}" />
                            </f:facet>
                            <h:outputText
                                value="#{insured.generalPartyInfo.addr.city}, #{insured.generalPartyInfo.addr.stateProv} #{insured.generalPartyInfo.addr.postalCode}" />
                        </p:column>
                        <p:column headerText="Policy Type">
                            <h:outputText value="#{insured.policyType}" />
                        </p:column>
                        <p:column headerText="Action" style="text-align:center;">
                            <p:commandLink>
                                <h:outputText value="Change" />
                            </p:commandLink>
                        </p:column>
                    </p:dataTable>

采纳答案by Vish

Instead of doing row selection event on toggle,we followed a diffrent approach using datatable attribute.This work magicaly

我们没有在切换时执行行选择事件,而是使用数据表属性遵循了不同的方法。这项工作很神奇

 <p:dataTable id="insList" var="insured"
                        value="#{policyHandler.insuredList}" paginator="true"
                        rows="#{label.insuredList_defaultNumberOfRows}"
                        paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                        rowsPerPageTemplate="#{label.insuredList_numberOfRows}"
                        style="width: 98%;">
                        <p:column>
                            <f:facet name="header">
                                <h:outputLabel value="Select" />
                            </f:facet>
                            <h:selectBooleanCheckbox id="selection"
                                value="#{insured.status}">
                                <f:ajax execute="@this" 
                                listener="#{policyHandler.DoPathProcessing2}" render="insList"/>
                                <f:attribute name="insured" value="#{insured}" />
                            </h:selectBooleanCheckbox>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputLabel value="Sequence" />
                            </f:facet>
                            <p:cellEditor id="insuredOrder" disabled="#{!insured.status}">
                                <f:facet name="output">
                                    <h:outputText value="#{insured.sequence}" />
                                </f:facet>
                                <f:facet name="input">
                                    <p:inputText value="#{insured.sequence}" />
                                </f:facet>
                            </p:cellEditor>
                            <p:rowEditor />
                        </p:column>
                        <p:column headerText="Name"
                            sortBy="#{insured.generalPartyInfo.nameInfo.commlName.commercialName}"
                            filterMatchMode="contains" style="text-align:center;">
                            <h:outputText
                                value="#{insured.generalPartyInfo.nameInfo.commlName.commercialName}" />
                        </p:column>
                        <p:column sortBy="#{insured.generalPartyInfo.addr.city}"
                            style="text-align:center;">
                            <f:facet name="header">
                                <h:outputLabel value="Street Address" />
                            </f:facet>
                            <h:outputText value="#{insured.generalPartyInfo.addr.city}" />
                        </p:column>
                        <p:column sortBy="#{insured.generalPartyInfo.addr.city}"
                            style="text-align:center;" width="10%">
                            <f:facet name="header">
                                <h:outputLabel value="#{label.city}, #{label.state} " />
                                <h:outputLabel value=" #{label.postalcode}" />
                            </f:facet>
                            <h:outputText
                                value="#{insured.generalPartyInfo.addr.city}, #{insured.generalPartyInfo.addr.stateProv} #{insured.generalPartyInfo.addr.postalCode}" />
                        </p:column>
                        <p:column headerText="Policy Type">
                            <h:outputText value="#{insured.policyType}" />
                        </p:column>
                        <p:column headerText="Action" style="text-align:center;">
                            <p:commandLink>
                                <h:outputText value="Change" />
                            </p:commandLink>
                        </p:column>
                    </p:dataTable>