从对话框更新PrimeFaces数据表行

问题描述 投票:0回答:1

我有一个数据表,其中有一个rowexpandor,其中包含两个面板,一个是常规文本,另一个是注释列表。我有一个允许用户添加新评论的按钮。现在该对话框是单独的形式,请参阅下面的代码。我的问题是,一旦添加了评论,包含所有评论的面板就不会被刷新。这是一个代码示例。

 <h:form id="formName">


        <p:dataTable  id="prTable" rowIndexVar="index" sortMode="multiple" styleClass="iris_table" var="value" value="#{bean.listValues}"  
                     paginator="true"  rows="10" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                     rowsPerPageTemplate="5,10,15">
            <p:ajax event="rowToggle" onstart="rowMutalExclusive();"/>


            <p:column style="width:2%">  
                <p:rowToggler />

            </p:column> 



            <p:column id="message"   
                      headerText="Description" 
                      filterMatchMode="contains" filterStyle="display: none;">  
                <h:outputText value="#{value.description}" />  
            </p:column>  


            <p:column id="deadline" headerText="Deadline" filterStyle="display: none;">  

                <h:outputText  value="#{value.endDate}">
                    <f:convertDateTime pattern="dd.MM.yyyy " />
                </h:outputText>
            </p:column>  
            <p:rowExpansion > 

                <div class="iris_peerreview_details">

                    <div class="comments">

                        <p:commandButton value="Comment" process="@this" update=":dialogForm:commentDlg" oncomplete="commentDialog.show()">  
                            <f:setPropertyActionListener target="#{bean.review}" rendered="check" value="#{value.review}"></f:setPropertyActionListener>     
                        </p:commandButton>
                        <div class="clear"></div>
                    </div>
                    <p:panel id="pnlHelp"  style='border:none'>
                        <p:dataList id="check" rowIndexVar="index" value="#{bean.commentsFromCase(value.review)}" var="commentReview"> 
                            <div class="messages">
                                <p> 
                                    <h:outputText value="#{commentReview.date}">
                                        <f:convertDateTime pattern="MM.dd.yyyy 'at' h:mm a"></f:convertDateTime>
                                    </h:outputText>  

                                </p>
                                <p class="message">
                                    <h:outputText styleClass="message"  value="#{commentReview.comment}"/>

                                </p>

                            </div>
                        </p:dataList>
                    </p:panel> 
                </div>


            </p:rowExpansion> 
        </p:dataTable> 
    </h:form>
    <h:form id="dialogForm" >
        <p:dialog id="commentDlg" header="Comment" widgetVar="commentDialog" resizable="false" 
                  modal="true">

            <h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">

                <h:outputText value="Comment"" />
                <h:inputText value="#{bean.comment}" required="true" requiredMessage="Please enter a comment" style="font-weight:bold"/>                                               
                <p:commandButton id="save" actionListener="#{bean.commentCase()}" update=":formName:prTable:pnlHelp" oncomplete="commentDialog.hide();" 
                                  value="Comment"/>
                <p:commandButton id="cancelButton" onclick="commentDialog.hide()" value="Cancel"/>
            </h:panelGrid>
        </p:dialog>
    </h:form>

你不得不原谅我,因为我必须删除一些代码并掩盖其中的一些但通常这就是它的作用。现在,一旦点击了注释按钮,就会出现对话框并且注释存储在数据库中,一切正常,但是我无法让它更新包含注释的那一行的面板。我猜的问题是以下一旦这个页面实际呈现面板ID

 formName:prTable:0:pnlHelp

并且每行的值都会更改。现在我明白我在对话框中的更新无法找到id,但如果我输入索引并尝试在render上创建此特定id,则会抛出一个无法找到的异常。

我已经尝试将对话框放在dataTable中,并且它可以正常更新,但它会导致更多问题,所以我不得不放弃该选项。此外,如果我更新完整的表它没关系,但问题是rowexpandor关闭哪不是它的要求,加上它不是真的不喜欢刷新整个表,因为这不是这个目的。如果这有帮助,我正在使用Primeface 4.0。用jsf 2.0。

jsf-2 primefaces
1个回答
0
投票

是的,每行的id值都会改变。尝试使用css选择器更新它,将按钮更改为

<p:commandButton id="save" actionListener="#{bean.commentCase()}" update="@([id$=pnlHelp])" oncomplete="commentDialog.hide();" 
                                  value="Comment"/>

代码将更新以“pnlHelp”结尾的所有组件。更多信息:http://www.w3schools.com/cssref/css_selectors.asp

© www.soinside.com 2019 - 2024. All rights reserved.