Mapping a dynamic message to p: confirmDialog without sending a request to the server

I need to dynamically display a confirmation message on <p:confirmDialog> . This can be done by updating this component using AJAX after sending the request to the server. For instance,

 <p:column selectionMode="multiple"> <f:facet name="footer"> <p:commandButton oncomplete="confirmDeleteMultiple.show()" update=":form:confirmDialogDeleteMultiple" process=":form:dataTable" actionListener="#{bean.deleteMultipleActionListener}"/> </f:facet> </p:column> 

The specified button in the footer <p:dataTable> can update the message that is set inside deleteMultipleActionListener(ActionEvent actionEvent){...} and update the specified confirmation dialog confirmDialogDeleteMultiple , which looks like this.

 <p:confirmDialog id="confirmDialogDeleteMultiple" widgetVar="confirmDeleteMultiple" message="#{bean.deleteMultipleMsg}" header="Header Message" appendToBody="true" closable="true"> <p:commandButton id="confirmDeleteMultiple" value="Yes" process="@this dataTable messages" rendered="#{bean.renderedYesButtonMultipleDelete}" update="messages dataTable" oncomplete="confirmDeleteMultiple.hide()" actionListener="#{bean.deleteMultiple}"/> <p:commandButton id="declineDeleteMultiple" value="#{bean.noButtonTextMultipleDelete}" onclick="confirmDeleteMultiple.hide()" type="button"/> </p:confirmDialog> 

A managed bean just looks like this.

 @ManagedBean @RequestScoped public final class Bean { private String deleteMultipleMsg; //Getter only. private boolean renderedYesButtonMultipleDelete=true; //Getter only. private String noButtonTextMultipleDelete="No"; //Getter only. public void deleteMultipleActionListener(ActionEvent actionEvent) { if(selectedValues!=null&&!selectedValues.isEmpty()) { renderedYesButtonMultipleDelete=true; noButtonTextMultipleDelete="No"; deleteMultipleMsg="Confirmation message."; } else { noButtonTextMultipleDelete="Ok"; renderedYesButtonMultipleDelete=false; deleteMultipleMsg="Row selection message."; } } } 

selectedValues is a list that contains the selected rows in a DataTable . deleteMultipleMsg is a message that displays on <p:confirmDialog> after an AJAX request.


There is no doubt about that. This works as expected. Therefore, I do not study this in detail.

This, however, requires an AJAX request to be sent to the server only to obtain simple confirmation. I feel that this is completely optional. Such a confirmation message should be displayed on the client side before sending the actual request to the server.

So, I'm looking for a way to do this on the client side, possibly using regular JavaScript. Can this be done as usual, in the same way as JavaScript confirm("Message") displayed with the Ok and Cancel ?

I am using Primefaces 3.5. Now it's 4.0 final. Now this is the end of 5.1.

+4
source share
2 answers

Maybe just replaceWith is enough for you:

 <script> jQuery("confirmDeleteMultiple.p").replaceWith(... </script> 
+1
source

You can save the message on your XHTML page using the CSS display:none style and do the validation in JavaScript, and if the validation doesn't work, just change the style to display:block . No AJAX.

0
source

Source: https://habr.com/ru/post/1487640/


All Articles