ignoreValidationFailed doesn´t work inside p:dataTable

試著忘記壹切 提交于 2019-12-13 02:07:27

问题


I am using actionListener ajax call inside datatable and trying to do the following :

  1. skip validation
  2. update the model with the inserted values

I knew that omnifaces utility liberary by BalusC can do this using o:ignoreValidationFailed But it failed with me to work inside primefaces datatable.

Also I found that it failed to work inside ui:repeat in another post here I dont know if its a bug or not. here is my code example

<o:form id ="trans_desc_form">          
      <p:outputPanel id="stkdetailsid">                 
    <p:dataTable id="transactiondetailsid" value="#{stockTransactionsBean.stkTransHeader.stkTransDetailsList}" 
                 var="stkTransDet"  rowIndexVar="rowIndex">            
         <p:column>  
                    <f:facet name="header">  
                        <h:outputText value="Item Code" />  
                    </f:facet>                         
        <p:autoComplete id="dd" required="true" 
                            value="#{stkTransDet.item}" var="i" itemLabel="#{i.itemno}   #{i.itemnamee}" 
                            itemValue="#{i}" converter="itemsConverter"
                            completeMethod="#{stockTransactionsBean.completeItems}"/>            
          </p:column>                          
           <p:column>
                 <p:commandButton  value="-"  update="@form"  process="@form"
                                    actionListener="#{stockTransactionsBean.removeRow(rowIndex)}"> 
                                    <o:ignoreValidationFailed />
                    </p:commandButton>                                   
           </p:column>                
            </p:dataTable> 

      </p:outputPanel>
      </o:form>  

As a workaround, I added

1- add a condition to the required field to know if the ajax come from submit button or not to the autoComplete component where the trans_desc_form is thte entire form id and savetransid is the submit button save id

required="#{!empty param['trans_desc_form:savetransid']}"/> 

2- I removed @NotNull from my JPA entity which force the validation

@JoinColumn(name = "ITEMNO", referencedColumnName = "ITEMNO")
@ManyToOne(optional = false, fetch = FetchType.LAZY)
//@NotNull
private Item item;

回答1:


To skip validation you can use the immediate="true" attribute on your p:commandButton



来源:https://stackoverflow.com/questions/17752516/ignorevalidationfailed-doesn%c2%b4t-work-inside-pdatatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!