P: dialog does not fire ajax close event when using dialog.hide ()

I am using <p:dialog> . After submitting the form in it, I use dialog.hide() , and it runs the ajax close event listener method, which will update the List<E> . It worked fine, but when I put some necessary input components and bring in <p:dialog> again, if there is some validation error, it no longer runs the method.

Dialogue:

 <p:outputPanel autoUpdate="true"> <p:dialog id="dialogComentario" header="Deixe sua avaliação" widgetVar="confirmation" showEffect="fade" hideEffect="fade" height="340" width="500" modal="true" visible="#{not empty facesContext.maximumSeverity}" resizable="false" closable="true" draggable="false"> <h:form prependId="false"> ... <p:commandLink styleClass="btn btn-primary btenviacoment" oncomplete="if (!args.validationFailed) confirmation.hide();" actionListener="#{comentario.actEnviarComentario}" global="false"> <i class=" icon-play-circle icon-white"></i> <h:outputText value=" Enviar Comentário" /> <f:param name="codigoplu" value="#{produto.produto.codigoplu}" /> </p:commandLink> ... <p:commandLink styleClass="btn" onclick="confirmation.hide();" global="false" immediate="true"> <h:outputText value=" Cancelar" /> <i class="icon-off"></i> </p:commandLink> ... </h:form> <p:ajax event="close" update=":avaliacoesClientes, :dialogComment" listener="#{produto.atualizarComentarios}" global="false" /> </p:dialog> </p:outputPanel> 

Action Listener Method:

 public void actEnviarComentario(ActionEvent event) { String codigoplu = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("codigoplu"); PegarDadosCliente(); try { DateFormat f = new SimpleDateFormat("dd/MM/yyyy"); java.util.Date utildata = new java.util.Date(); utildata = (java.util.Date) f.parse(String.valueOf(data.getValue())); java.sql.Date datasql = new java.sql.Date(utildata.getTime()); Comentario comentario = new Comentario(Integer.parseInt(usuario.getId()), Integer.parseInt(codigoplu), titulo.getValue().toString(), mensagem.getValue().toString(), datasql, Integer.parseInt(rating.getValue().toString()), new java.sql.Date(new Date().getTime())); listavelComentarios.inserirComentario(comentario); RequestContext.getCurrentInstance().execute("confirmation.hide();"); } catch (NamingException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } } 

I tried to close the dialog with RequestContext , as shown in the action method, but this also will not result in ajax closing event.

Here is the ajax close listening method:

 public void atualizarComentarios(CloseEvent event) { try { comentarios = comentario.listarComentarios(codigoplu); if (comentarios.size() > 0) { msgAvaliacao = "Avaliação do produto."; int votos = 0; for (Comentario comentario : comentarios) { votos += comentario.getAvaliacao(); } rating = votos / comentarios.size(); } } catch (NamingException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } 
+4
source share
1 answer

This issue is not related to validation. Remove all these input components and click the button / link to the command and you will see that it is still not running.

This problem is caused by the unnecessary combination of <p:outputPanel autoUpdate="true"> and visible="#{not empty facesContext.maximumSeverity}" . The output panel saves the dialog box automatically updating, which apparently forces you to set the visible attribute. The dialog is automatically updated immediately before the oncomplete event. If the dialog visible property is visible , then the dialog is already hidden (invisible) until oncomplete .

So, just get rid of the <p:outputPanel> attribute and visible . Your oncomplete already doing the right thing.


Unrelated to a specific problem, the RequestContext string is not needed. You already hide it in oncomplete , which is great. See Also Save p: the dialog is opened if a verification error occurs after sending .

+2
source

All Articles