问题
I am using actionListener ajax call inside datatable and trying to do the following :
- skip validation
- 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