primefaces rowEdit在validationFailed()之后关闭
我使用的是PrimeFaces4.0和JSF2.2。当我使用行编辑创建一个primefaces rowEdit在validationFailed()之后关闭,primefaces,datatable,roweditor,Primefaces,Datatable,Roweditor,我使用的是PrimeFaces4.0和JSF2.2。当我使用行编辑创建一个DataTable并在rowEdit事件上设置一个valdiationFailed()时,行编辑器正在关闭,我想阻止它 我添加了一个oncompletejs函数,如: <p:ajax event="rowEdit" listener="#{customerUI.onInvoiceRowEdit}" oncomplete="if(!args.validationFailed) {updateTable();}"
DataTable
并在rowEdit
事件上设置一个valdiationFailed()
时,行编辑器正在关闭,我想阻止它
我添加了一个oncomplete
js函数,如:
<p:ajax event="rowEdit" listener="#{customerUI.onInvoiceRowEdit}"
oncomplete="if(!args.validationFailed) {updateTable();}" update=":messages" />
我的远程命令如下:
<p:remoteCommand name="updateTable" update=":form:addressTabs:customerTable" />
因此,当验证失败时,这会保留编辑器,但现在编辑器的“接受”和“取消”按钮不起作用,在我手动刷新之前,编辑其他内容也不起作用
我只希望编辑器在验证失败时留下来并更正输入,如果验证成功,编辑器可以关闭
有人对此有任何解决方案吗?所以我遇到了一个与此相关的问题,这个问题帮助我找到了一个解决方案,所以我想我应该在这里分享它,以防其他人遇到类似问题并需要帮助 因此,当编辑行中的单元格时,我对一个函数进行了dataTable和rowEdit ajax调用,在对数据库进行一些更改后,我还使用remoteCommand更新dataTable。问题是,如果单元格编辑值的验证失败,remoteCommand将刷新表单,错误消息将在读取之前消失。我希望只有在没有验证错误的情况下才能执行对rowEdit的ajax调用,否则我希望在行编辑器仍然打开的情况下显示错误消息。因此,我使用了问题中所示的args.validationFailed参数来防止在自定义验证器失败的情况下执行remoteCommand。下面是我所做工作的一个基本示例 JSF页面:-
<h:form id="form_name">
<p:remoteCommand name="refreshForm" update="@form" />
<p:dataTable id="table_id" var="varTableData"
value="#{bean.tablerows}"
editable="true">
<p:ajax event="rowEdit"
listener="#{bean.onRowEdit}"
oncomplete="if(!args.validationFailed) refreshForm()" />
<p:column>
<f:facet name="header">
<h:outputText value="Column Title" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{varTableData.someValue}" />
</f:facet>
<f:facet name="input">
<p:inputText id="cellId"
value="#{varTableData.someValue}"
label="Some Label" required="true" style="width:100%"
validator="#{bean.validationMethod}">
</p:inputText>
<p:message id="someMsg" for="cellId" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</h:form>
自定义验证方法:-
public void validationMethod(FacesContext context, UIComponent comp, Object value) {
int someCellValue = (int) value;
if (someCellValue < 6) {
((UIInput) comp).setValid(false);
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Some error message",
"some error message");
context.addMessage(comp.getClientId(context), message);
}
}
public void validationMethod(FacesContext上下文、UIComponent comp、对象值){
int-someCellValue=(int)值;
if(someCellValue<6){
((UIInput)comp.setValid(false);
FacesMessage=新的FacesMessage(FacesMessage.SEVERITY_错误,
“一些错误消息”,
“某些错误消息”);
addMessage(comp.getClientId(context),message);
}
}
我无法重现错误。我将Primefaces Showcase中的代码与一些required=“true”一起使用。你能为你的问题添加更多的信息吗(包括更完整的代码示例)?我最终自己解决了这个问题,因为你可以在这里阅读,谢谢你的帮助;)我投票结束这个问题,因为OP在一个不清楚的问题上修正了这个问题,没有提供答案,并且提供的链接是“无效的”。