Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

p:dataTable - refresh datatable after delete row

following is my data table pic and i want when i delete a row, data table refreshes. but row deleted from DB but doesnot delete from data table after that. enter image description here i try following codes but they could not help me.

<h2>مشاهده اطلاعات پرسنل</h2>   
 <h:form id="f2" prependId="false">  

    <p:dataTable id="pdataTable" var="personel" value="#{personelMB.personelList}" rowKey="#{personelMB.personel_id}"
    >  

        <f:facet name="header">  
            اطلاعات پرسنل 
        </f:facet>  

        <p:column>  
            <f:facet name="header">  
               شماره پرسنلی  
            </f:facet>  

            <h:outputText value="#{personel.personel_id}" />  

            <f:facet name="footer">  
                کدملی 
            </f:facet>  
        </p:column>  

        <p:column headerText="نام">  
            <h:outputText value="#{personel.pname}" />  
        </p:column>  

        <p:column headerText="نام خانوادگی">  
            <h:outputText value="#{personel.pfamily}" />  
        </p:column>  

        <p:column headerText="آدرس">  
            <h:outputText value="#{personel.paddress}" />  
        </p:column>  
   <p:column headerText="تلفن">  
            <h:outputText value="#{personel.pphone}" />  
        </p:column>
        <p:column>
      <f:facet name="حذف">
         <h:outputText value="" />
      </f:facet>
      <p:commandButton icon="ui-icon-close" title="حذف"
                       actionListener="#{personelMB.deletePersonel(personel.personel_id)}" update="pdataTable"/>
   </p:column>
        <f:facet name="footer">  
            تعداد رکورد#{fn:length(personelMB.getPersonelList())} میباشد.  
        </f:facet>  

    </p:dataTable>  

</h:form> 

2.second try:

<p:commandButton icon="ui-icon-close" title="حذف"
 actionListener="#{personelMB.deletePersonel(personel.personel_id)}" reRender="pdataTable"/>
                   </p:column>

3.third try: personelBean.java

public void deletePersonel(int personel_id){
        Personel personel=(Personel)personelservice.getPersonelId(personel_id);
        getPersonelservice().deletePersonel(personel);
    }
    public String deleteAction(Personel personel) {
        personelList.remove(personel);
        return null;
      }

xhtml file

<p:commandButton icon="ui-icon-close" title="حذف"
                       actionListener="#{personelMB.deletePersonel(personel.personel_id)}" action="#{personelMB.deleteAction(personel)}"/>
   </p:column>

please help me.

like image 401
samira Avatar asked Feb 19 '26 18:02

samira


1 Answers

Instead of ajax to be false made it true.

actionListener="#{personelMB.deletePersonel(personel.personel_id)}"  update="@form" ajax="true"/>
like image 156
samira Avatar answered Feb 21 '26 08:02

samira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!