从外部对话框更新rowexpansion中的行子数据表,而不关闭它

dz6r00yl  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(305)

从外部对话框保存后,我将尝试从外部对话框更新行 rowExpansion 不将整个表单更新为“不关闭”。我只想更新刚从中编辑的子行 dataTable 行的扩展。
这个 idCommandButtonDetailProductChild 按钮调用 idDialogDetailProduct 对话框,可以在其中编辑数据。并在使用 idCommandButtonUpdate 按钮我想要的是 idTableDetailProductChild 在没有 rowExpansion 结束。
我的代码如下:
productslist.xhtml(带行扩展的数据表)

<!-- PRODUCT LIST -->
        <p:dataTable id="idTableDetailProduct"                      
                     paginator="false" 
                     value="#{productController.productDetailDTOs}"
                     var="productDetail"
                     selection="#{productController.selectedProductDTOs}"
                     rowKey="#{productDetail.id}"
                     emptyMessage="#{diccBean.msg['product.productNotFound']]}"
                     scrollable="true"
                     scrollHeight="600">                     
                     ...

                <p:rowExpansion>

                <!-- PRODUCT LIST CHILD -->
                <p:dataTable id="idTableDetailProductChild" 
                            paginator="false" 
                            value="#{productDetail.productDTO.listProductsChild}"
                            var="productChild"
                            rowKey="#{productDetail.id}"                                     
                            emptyMessage="#{diccBean.msg['product.productChildNotFound']}"
                            scrollable="true">  

                            <!-- VIEW PRODUCT DETAIL  -->
                            <p:commandButton 
                                id="idCommandButtonDetailProductChild" 
                                title="#{diccBean.msg['product.detailProduct']}"
                                icon="fa fa-fw fa-search"
                                action="#{productController.initDetailProduct}"
                                oncomplete="PF('widgetVarDetailProduct').show();"
                                update="tabViewDetalle:idDialogDetailProduct">
                                <f:setPropertyActionListener value="#{productChild.productDetailDTO.id}" target="#{productController.productDetailId}"/>                                                                
                            </p:commandButton>

productdialog.xhtml(从中更新行扩展的子行)

<h:body>
        <ui:composition>    
            <p:dialog id="idDialogDetailProduct"            
                header="#{diccBean.msg['product.tittleDetailProduct']]}"
                resizable="false" 
                widgetVar="widgetVarDetailProduct" 
                modal="true"
                width="1200"            
                appendTo="@(body)"
                binding="#{productController.idDialogDetailProduct}">

                <h:form id="formDetailProduct">

                ...

                        <!-- SAVE COMPONENT BUTTON  -->
                        <p:commandButton 
                            id="idCommandButtonUpdate"                         
                            value="Componente: #{diccBean.msg['actions.save']}"
                            action="#{productController.actionUpdate}"
                            process="@form"
                            icon="fa fa-fw fa-check" 
                            update="tabViewDetalle:idTableDetailProduct" /> 

                </h:form>                           
            </p:dialog>         
        </ui:composition>
    </h:body>
uwopmtnx

uwopmtnx1#

通过将父行的索引放入“更新”属性中,可以只更新行扩展(子数据表)的一行,而不关闭它。
例如,如果父行是项目3,则如下所示:

update=":tabViewDetail:idTableDetailProduct:3:idTableDetailProductChild"

要动态执行此操作,我们可以通过传递父元素的索引来执行此操作:

update=":tabViewDetail:idTableDetailProduct:#{productController.indexParent}:idTableDetailProductChild"

父行的索引可以通过在父数据表中添加以下属性获得:

rowIndexVar="indexParent"

我们将其设置为bean,如下所示:

<f:setPropertyActionListener value="#{indexParent}" target="#{productController.indexParent}" />

那么解决方案如下:
productslist.xhtml

<!-- PRODUCT LIST -->
            <p:dataTable id="idTableDetailProduct"  
                         value="#{productController.productDetailDTOs}"
                         var="productDetail"            
                         ...
                         rowIndexVar="indexParent">

                <p:rowExpansion>

                    <!-- PRODUCT LIST CHILD -->
                    <p:dataTable id="idTableDetailProductChild"                                 
                                value="#{productDetail.productDTO.listProductsChild}"
                                var="productChild"  
                                ...>                                

                                <!-- VIEW PRODUCT DETAIL  -->
                                <p:commandButton 
                                    id="idCommandButtonDetailProductChild"
                                    ...>                                    
                                    <f:setPropertyActionListener value="#{indexParent}" target="#{productController.indexParent}" />                                                                            
                                </p:commandButton>

productcontroller bean(java)

@ManagedBean(name="productController")      
        public class ProductController{

            int indexParent;

            public int getIndexParent() {
                return indexParent;
            }

            public void setIndexParent(int indexParent) {
                this.indexParent = indexParent;
            }

        }

productdialog.xhtml

<h:body>
    <ui:composition>    
        <p:dialog id="idDialogDetailProduct"            
                ...>                            

            <!-- SAVE COMPONENT BUTTON  -->
            <p:commandButton 
                id="idCommandButtonUpdate"                         
                ... 
                update=":tabViewDetail:idTableDetailProduct:#{productController.indexParent}:idTableDetailProductChild" />  

        </p:dialog>         
    </ui:composition>
</h:body>

相关问题