I am trying out Primefaces 3 using glassfish and eclipse.
I wanted to utilize Primefaces Dialog when creating or entering user details.
Suppose for example in a page, I have a Create button that when clicked would show this dialog.
<p:dialog id="dialog" widgetVar="dlg1">
<h:form id="addMemberForm">
<!-- More code here -->
<f:facet name="footer">
<p:commandButton value="Save"
actionListener="#{myBean.save}"
oncomplete="dlg1.hide()" />
</f:facet>
</p:panelGrid>
</h:form>
</p:dialog>
..and when my save button is clicked, execute this code.
public class MyBean{
public void save(ActionEvent event) {
try{
myEJB.addMember(newMember);
//how to show message
}catch(Exception e){
e.printStackTrace();
}
}
}
How do I show a dialog popup message to the user when the add is successful.
I tried it with this code but this doesn’t show up and the dialog gets dismissed.
FacesMessage facesMessage = new FacesMessage("Successful add!");
FacesContext.getCurrentInstance().addMessage(null, facesMessage);
I was thinking that this is an ajax submit so everything gets cleared.
I think I have to execute some code during the oncomplete but I dont know how to do it?
You should update a message tag from your ajax request.
Assuming you have a global message tag like this on your page:
Since it is not inside the dialog’s form you need to address it in the
updateattribute ofp:commandButtonwith an absolute id: