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

发布于 2024-12-05 05:34:22 字数 4321 浏览 1 评论 0原文

我们需要在复选框切换的行选择上触发 ajax 事件..i 试图找到示例,但他们只在单击时进行行选择 p:命令按钮。我们使用的是primefaces 2.2

代码

<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>

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铃予 2024-12-12 05:34:23

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

 <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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文