[英]Primefaces DataTable i can't delete a row when i add requiered to my input
i'm using JSF 2.8 and primefaces 6.0 i have a datatable with 2 actions update and delete. 我正在使用JSF 2.8和primefaces 6.0,我有一个数据表,其中包含2个操作的更新和删除。 and i have a popup which contains a form with required fields displayed by clicking on the create button. 我有一个弹出窗口,其中包含通过单击创建按钮显示带有必填字段的表单。
but when i click on the button delete on datatable the line is not deleted and and a message appears that contains the attributes (of the popup) should'nt be null. 但是,当我单击数据表上的删除按钮时,该行并未被删除,并且出现一条消息,其中包含(弹出窗口的)属性不应该为null。
But when i remove required from inputs it works. 但是,当我从输入中删除所需的东西时,它可以工作。
While it's an action to delete the line has nothing to do with my form. 虽然删除行是与我的表单无关的动作。
Here is my XHTML 这是我的XHTML
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/template.xhtml">
<ui:define name="title">Test</ui:define>
<ui:define name="content">
<h:form id="form">
<div class="ui-g">
<div class="ui-g-12">
<div class="card card-w-title">
<h1>Ressource</h1>
<p:commandButton update=":form:nouvelleRessource" value="Create" oncomplete="PF('createDialog').show()" icon="ui-icon-add" title="Create"/>
<p:commandButton value="Import" icon="ui-icon-import-export" title="Create"/>
<p:dataTable var="ressource" value="#{ressourceBean.ressources}" paginator="true" rows="5" selectionMode="single" reflow="true"
rowKey="#{ressource.idt_ressource}" id="ut" editable="true" emptyMessage="Aucune ressource trouvée">
<f:facet name="header">
Listes des ressources
</f:facet>
<p:ajax event="rowEdit" listener="#{ressourceBean.onEdit}" />
<p:ajax event="rowEditCancel" listener="#{ressourceBean.onCancel}" />
<p:column headerText="Id" filterBy="#{ressource.idt_ressource}" filterMatchMode="contains" filterOptions="">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{ressource.idt_ressource}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{ressource.idt_ressource}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Nom" filterBy="#{ressource.nom}" filterMatchMode="contains">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{ressource.nom}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{ressource.nom}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="prenom" filterBy="#{ressource.prenom}" filterMatchMode="contains" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{ressource.prenom}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{ressource.prenom}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Matricule" filterBy="#{ressource.matricule}" filterMatchMode="contains">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{ressource.matricule}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{ressource.matricule}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Mail" filterBy="#{ressource.mail}" filterMatchMode="contains">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{ressource.mail}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{ressource.mail}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Modifier" >
<p:rowEditor/>
</p:column>
<p:column headerText="Supprimer" >
<center>
<p:commandButton action="#{ressourceBean.delete(ressource)}" icon="ui-icon-delete" update="@ut" ajax="false"/>
</center>
</p:column>
</p:dataTable>
<p:dialog header="Nouvelle ressource" widgetVar="createDialog" modal="true">
<p:panel id="nouvelleRessource" header="Create Ressource">
<p:panelGrid columns="4" columnClasses="ui-grid-col-2,ui-grid-col-4,ui-grid-col-2,ui-grid-col-4" layout="grid" styleClass="ui-panelgrid-blank form-group" style="border:0px none; background-color:transparent;">
<p:outputLabel for="nom1" value="Nom"/>
<h:panelGroup styleClass="md-inputfield">
<p:inputText id="nom1" value="#{ressourceBean.ressource1.nom}" required="true" />
<p:message for="nom1" display="icon" />
<label>nom</label>
</h:panelGroup>
<p:outputLabel for="mail1" value="Mail"/>
<h:panelGroup styleClass="md-inputfield">
<p:inputText id="mail1" value="#{ressourceBean.ressource1.mail}"
requiredMessage="Please enter your email address."
validatorMessage="Invalid email format"
required="true">
<f:validateRegex
pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
</p:inputText>
<label>Mail</label>
</h:panelGroup>
<p:outputLabel for="prenom1" value="Prenom"/>
<h:panelGroup styleClass="md-inputfield">
<p:inputText id="prenom1" value="#{ressourceBean.ressource1.prenom}" required="true" />
<p:message for="prenom1" display="icon" />
<label>prenon</label>
</h:panelGroup>
<p:outputLabel for="telephone1" value="Telephone"/>
<h:panelGroup styleClass="md-inputfield">
<p:inputText id="telephone1" value="#{ressourceBean.ressource1.telephone}" required="true" />
<p:message for="telephone1" display="icon" />
<label>Telephone</label>
</h:panelGroup>
<p:outputLabel for="matricule1" value="Matricule"/>
<h:panelGroup styleClass="md-inputfield">
<p:inputText id="matricule1" value="#{ressourceBean.ressource1.matricule}" required="true"/>
<p:message for="matricule1" display="icon" />
<label>Matricule</label>
</h:panelGroup>
<p:outputLabel for="date1" value="Date d'entree"/>
<h:panelGroup styleClass="md-inputfield">
<p:calendar id="date1" value="#{ressourceBean.ressource1.dateEntree}" required="true"/>
<p:message for="date1" display="icon" />
<label>Matricule</label>
</h:panelGroup>
</p:panelGrid>
<p:commandButton icon="ui-icon-save" actionListener="#{ressourceBean.save}" onclick="PF('createDialog').hide()" value="Save" update="ut" ajax="false" style="display:inline-block;margin-top:5px"/>
<p:commandButton icon="ui-icon-cancel" update="ut" onclick="PF('createDialog').hide()" value="Cancel" />
</p:panel>
</p:dialog>
<p:commandButton update=":form:nouvelleRessource" value="Create" oncomplete="PF('createDialog').show()" icon="ui-icon-add" title="Create"/>
<p:commandButton value="Import" icon="ui-icon-import-export" title="Create"/>
</div>
</div>
</div>
</h:form>
</ui:define>
Use the process attribute: 使用process属性:
<p:ajax process="@form" update="...>
Because the <p:ajax process>
and <f:ajax execute>
defaults to @this
and the modifications won't be executed. 因为<p:ajax process>
和<f:ajax execute>
默认为@this
,并且修改不会执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.