showcase formulario form example ejemplo after java jsf-2 primefaces

java - formulario - primefaces commandbutton actionlistener example



PrimeFaces commandButton no llama a la acción si ajax habilitado (2)

Aquí está mi página:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:cpanel="http://java.sun.com/jsf/composite/components/cpanel" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head> <title></title> </h:head> <h:body> <ui:composition template="/WEB-INF/templates/cpanelLayout.xhtml"> <ui:define name="metadata"> <f:metadata> <f:viewParam name="id" value="#{linkDoctorBean.incomingDoctorId}" required="true"/> <f:event type="preRenderView" listener="#{linkDoctorBean.preRenderView}"/> </f:metadata> </ui:define> <ui:define name="cpanelContent"> <cpanel:adddedClinicDoctor doctor="#{linkDoctorBean.incomingDoctor}" clinic="#{linkDoctorBean.clinic}"/> <h:form id="form"> <div> <h:panelGrid columns="2"> <p:selectOneMenu id="doctor" value="#{linkDoctorBean.doctor}" converter="#{doctorConverter}" effect="fade" var="d" height="180" validator="#{linkDoctorBean.validateDoctor}"> <f:selectItem itemLabel="Select a doctor" itemValue="" noSelectionOption="true"/> <f:selectItems value="#{linkDoctorBean.doctors}" var="doctor" itemLabel="#{stringBean.doctorToString(doctor)}" itemValue="#{doctor}"/> <p:column> <p:graphicImage value="#{applicationBean.baseResourceUrl}/doc-photo/small/#{d.urlDisplayName}"/> </p:column> <p:column> #{stringBean.doctorToString(d)} </p:column> </p:selectOneMenu> <p:message id="doctorMessage" for="doctor"/> </h:panelGrid> </div> <div style="margin-top:20px;"> <p:commandButton value="Link" action="#{linkDoctorBean.submit()}" update="doctorMessage" process="@all"/> <h:link value="Cancel" outcome="/pages/cpanel/manage-doctors" style="margin-left:10px;"/> </div> </h:form> </ui:define> </ui:composition> </h:body> </html>

Cuando agrego ajax="false" al <p:commandButton/> , funciona bien - se llama al método linkDoctorBean.submit() .

Sin embargo, con ajax habilitado, se llamará al método de acción si el formulario nunca falla la validación en la vista actual, pero si el formulario falla la validación una vez y luego se envía, el mensaje de error se borra, pero el método submit() nunca se llama .

Editar: También traté de reemplazar el p:commandButton con esto:

<h:commandButton value="Link" action="#{linkDoctorBean.submit()}"> <f:ajax execute="@all" render="doctorMessage"/> </h:commandButton>

El comportamiento es exactamente el mismo. En ambos casos, el mensaje de validación parece borrarse cuando se envía una opción válida. Entonces, la actualización / procesamiento está sucediendo, simplemente no es el proceso / ejecución. Todos los intentos posteriores no ejecutan la acción, por lo que el formulario está efectivamente muerto hasta la próxima vez que se carga la página.

Editar: Esto no parece ser un problema PrimeFaces. Aquí está el formulario sin PrimeFaces:

<h:form id="form"> <div> <h:panelGrid columns="2"> <h:selectOneMenu id="doctor" value="#{linkDoctorBean.doctor}" converter="#{doctorConverter}" style="width:200px;" required="true" requiredMessage="Please select a doctor" validator="#{linkDoctorBean.validateDoctor}"> <f:selectItem itemLabel="Select a doctor" itemValue="#{null}" noSelectionOption="true"/> <f:selectItems value="#{linkDoctorBean.doctors}" var="doctor" itemLabel="#{stringBean.doctorToString(doctor)}" itemValue="#{doctor}"/> </h:selectOneMenu> <h:message id="doctorMessage" for="doctor"/> </h:panelGrid> </div> <div style="margin-top:20px;"> <h:commandButton value="Link" action="#{linkDoctorBean.submit()}"> <f:ajax execute="@form" render="doctorMessage"/> </h:commandButton> <h:link value="Cancel" outcome="/pages/cpanel/manage-doctors" style="margin-left:10px;"/> </div> </h:form>

Ahora existen algunas diferencias menores, como las required y el valor del elemento seleccionado del marcador de posición es null . Quizás sería mejor enfocarse en lo que podría estar yendo mal con este último fragmento y olvidarse de PrimeFaces por un momento.

En caso de que ayude, aquí está la clase DoctorConverter :

@Named("doctorConverter") @RequestScoped public class DoctorConverter implements Converter, Serializable { @Override public Object getAsObject(FacesContext context, UIComponent component, String value) { UIInput in = (UIInput) component; String s = in.getSubmittedValue() != null ? in.getSubmittedValue().toString() : ""; try { long doctorId = Long.parseLong(s); Doctor doctor = doctorDao.findByDoctorId(doctorId); if (doctor == null) { throw new Exception("Doctor not found."); } return doctor; } catch (Exception e) { throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please enter a valid doctor", null), e); } } @Override public String getAsString(FacesContext context, UIComponent component, Object value) { if (value == null || value.toString().length() == 0) { return ""; } Doctor doctor = (Doctor) value; return doctor.getDoctorId().toString(); } @EJB private DoctorDao doctorDao; }

Editar: ... y aquí hay un par de métodos de la clase de entidad Doctor :

@Override public int hashCode() { int hash = 0; hash += (doctorId != null ? doctorId.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { if (!(object instanceof Doctor)) { return false; } Doctor other = (Doctor) object; if ((this.doctorId == null && other.doctorId != null) || (this.doctorId != null && !this.doctorId.equals(other.doctorId))) { return false; } return true; }

Editar: como se comenta en los comentarios, DoctorConverter.getAsObject se llama tres veces. Aquí están los rastros de pila para las tres llamadas en orden:

1

at java.lang.Thread.dumpStack(Thread.java:1342) at com.localgp.jsf.converter.DoctorConverter.getAsObject(DoctorConverter.java:34) at com.localgp.jsf.converter.org$jboss$weld$bean-localgp-server-web-1$0-SNAPSHOT_war-ManagedBean-class_com$localgp$jsf$converter$DoctorConverter_$$_WeldClientProxy.getAsObject(org$jboss$weld$bean-localgp-server-web-1$0-SNAPSHOT_war-ManagedBean-class_com$localgp$jsf$converter$DoctorConverter_$$_WeldClientProxy.java) at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:171) at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:202) at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:319) at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030) at javax.faces.component.UIInput.validate(UIInput.java:960) at javax.faces.component.UIInput.executeValidate(UIInput.java:1233) at javax.faces.component.UIInput.processValidators(UIInput.java:698) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) at javax.faces.component.UIForm.processValidators(UIForm.java:253) at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:508) at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1589) at javax.faces.component.UIForm.visitTree(UIForm.java:344) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600) at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376) at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252) at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183) at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1170) at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at com.localgp.NoCacheFilter.doFilter(NoCacheFilter.java:36) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:785) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:649) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:483) at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:454) at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:350) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:300) at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828) at com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:444) at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:308) at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:87) at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:171) at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:143) at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:94) at com.sun.grizzly.http.TaskBase.run(TaskBase.java:193) at com.sun.grizzly.http.TaskBase.execute(TaskBase.java:175) at com.sun.grizzly.arp.DefaultAsyncHandler.handle(DefaultAsyncHandler.java:145) at com.sun.grizzly.arp.AsyncProtocolFilter.execute(AsyncProtocolFilter.java:204) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:722)

2

at java.lang.Thread.dumpStack(Thread.java:1342) at com.localgp.jsf.converter.DoctorConverter.getAsObject(DoctorConverter.java:34) at com.localgp.jsf.converter.org$jboss$weld$bean-localgp-server-web-1$0-SNAPSHOT_war-ManagedBean-class_com$localgp$jsf$converter$DoctorConverter_$$_WeldClientProxy.getAsObject(org$jboss$weld$bean-localgp-server-web-1$0-SNAPSHOT_war-ManagedBean-class_com$localgp$jsf$converter$DoctorConverter_$$_WeldClientProxy.java) at javax.faces.component.SelectUtils.doConversion(SelectUtils.java:191) at javax.faces.component.SelectUtils.matchValue(SelectUtils.java:99) at javax.faces.component.UISelectOne.validateValue(UISelectOne.java:153) at javax.faces.component.UIInput.validate(UIInput.java:967) at javax.faces.component.UIInput.executeValidate(UIInput.java:1233) at javax.faces.component.UIInput.processValidators(UIInput.java:698) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) at javax.faces.component.UIForm.processValidators(UIForm.java:253) at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:508) at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1589) at javax.faces.component.UIForm.visitTree(UIForm.java:344) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600) at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376) at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252) at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183) at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1170) at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at com.localgp.NoCacheFilter.doFilter(NoCacheFilter.java:36) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:785) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:649) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:483) at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:454) at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:350) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:300) at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828) at com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:444) at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:308) at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:87) at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:171) at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:143) at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:94) at com.sun.grizzly.http.TaskBase.run(TaskBase.java:193) at com.sun.grizzly.http.TaskBase.execute(TaskBase.java:175) at com.sun.grizzly.arp.DefaultAsyncHandler.handle(DefaultAsyncHandler.java:145) at com.sun.grizzly.arp.AsyncProtocolFilter.execute(AsyncProtocolFilter.java:204) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:722)

3

at java.lang.Thread.dumpStack(Thread.java:1342) at com.localgp.jsf.converter.DoctorConverter.getAsObject(DoctorConverter.java:34) at com.localgp.jsf.converter.org$jboss$weld$bean-localgp-server-web-1$0-SNAPSHOT_war-ManagedBean-class_com$localgp$jsf$converter$DoctorConverter_$$_WeldClientProxy.getAsObject(org$jboss$weld$bean-localgp-server-web-1$0-SNAPSHOT_war-ManagedBean-class_com$localgp$jsf$converter$DoctorConverter_$$_WeldClientProxy.java) at javax.faces.component.SelectUtils.doConversion(SelectUtils.java:191) at javax.faces.component.SelectUtils.valueIsNoSelectionOption(SelectUtils.java:150) at javax.faces.component.UISelectOne.validateValue(UISelectOne.java:159) at javax.faces.component.UIInput.validate(UIInput.java:967) at javax.faces.component.UIInput.executeValidate(UIInput.java:1233) at javax.faces.component.UIInput.processValidators(UIInput.java:698) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) at javax.faces.component.UIForm.processValidators(UIForm.java:253) at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:508) at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1589) at javax.faces.component.UIForm.visitTree(UIForm.java:344) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600) at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376) at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252) at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183) at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1170) at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at com.localgp.NoCacheFilter.doFilter(NoCacheFilter.java:36) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:785) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:649) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:483) at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:454) at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:350) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:300) at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828) at com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:444) at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:308) at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:87) at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:171) at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:143) at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:94) at com.sun.grizzly.http.TaskBase.run(TaskBase.java:193) at com.sun.grizzly.http.TaskBase.execute(TaskBase.java:175) at com.sun.grizzly.arp.DefaultAsyncHandler.handle(DefaultAsyncHandler.java:145) at com.sun.grizzly.arp.AsyncProtocolFilter.execute(AsyncProtocolFilter.java:204) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:722)

Y aquí está el formulario actual en la página JSF:

<h:form id="form"> <!-- Validating here instead of at the selectOneMenu level due to its invalidity not being cleared. --> <div style="clear:both;"> <h:panelGrid columns="2"> <h:selectOneMenu id="doctor" value="#{linkDoctorBean.doctor}" converter="#{doctorConverter}" converterMessage="Please select a doctor" style="width:200px;" required="true"> <f:selectItem itemLabel="Select a doctor" itemValue="" noSelectionOption="true"/> <f:selectItems value="#{linkDoctorBean.doctors}" var="doctor" itemLabel="#{stringBean.doctorToString(doctor)}" itemValue="#{doctor}"/> </h:selectOneMenu> <p:message id="doctorMessage" for="doctor"/> </h:panelGrid> </div> <div style="margin-top:20px;"> <h:commandButton value="Link" action="#{linkDoctorBean.submit()}"> <f:ajax execute="@form" render="doctorMessage"/> </h:commandButton> <h:link value="Cancel" outcome="/pages/cpanel/manage-doctors" style="margin-left:10px;"/> </div> </h:form>

Editar: eliminado <f:ajax/> y DoctorConverter.getAsObject todavía se está llamando tres veces.


El seguimiento:

converter="#{doctorConverter}"

debe escribirse como:

converter="doctorConverter"


Tu convertidor está roto. Tiene que convertir el valor basado en el argumento de value , no en el UIInput#getSubmittedValue() . El valor de noSelectionOption también se pasa a través del convertidor (como el tercer indicio de rastreo). Si su valor real presentado es igual al valor noSelectionOption , entonces el valor se considera no válido, de ahí el error de validación.

También sugiero otras reescrituras menores; las cadenas vacías deben ser nulas.

@Override public String getAsString(FacesContext context, UIComponent component, Object modelValue) { if (modelValue == null) { return ""; } if (modelValue instanceof Doctor) { Long id = ((Doctor) modelValue).getId(); return (id != null) ? String.valueOf(id) : null; } else { throw new ConverterException(new FacesMessage(modelValue + " is not a valid Doctor")); } } @Override public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) { if (submittedValue == null || submittedValue.isEmpty()) { return null; } try { Long id = Long.valueOf(submittedValue); return doctorService.find(id); } catch (NumberFormatException e) { throw new ConverterException(new FacesMessage(submittedValue + " is not a valid Doctor ID")); } }

Tenga en cuenta que también tengo esto en mi web.xml :

<context-param> <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name> <param-value>true</param-value> </context-param>

Actualización : según los comentarios, gracias a <h:messages/> resulta que hay algo más que se requiere. Finalmente resulta ser un <f:viewParam required="true"> que ha sido reinvocado en la devolución de datos de ajax. Para evitar esto, en su lugar use

<f:viewParam ... required="#{not facesContext.postback}" />