jrobertsz66
jrobertsz66

Reputation: 961

How do you create a dialog programmatically in PrimeFaces?

How do you create a dialog programmatically in Primefaces?

I have a page named tree.xhtml with a <p:tree/> and a tree node with a right-click contextmenu option that selects a bean.edit() method.

When the user clicks on the bean.edit() method, I want the method to display a dialog programmatically and I want to be able to create input elements or a drop down combo box with more than one element and a submit button. I have looked at the User's guide and I do not see such an example so I am hoping you guys can show me how to do it here.

Many thanks in advance.

Joe

Upvotes: 4

Views: 3328

Answers (1)

flash
flash

Reputation: 6810

If you want to trigger the showup of a dialog programmatically you can use the visible attribute to do so:

Your dialog in xhtml:

<h:form id="myForm">
    <p:dialog id="myDialog" header="The Dialog" visible="#{backingBean.showDialog}">  
    ...
    </p:dialog>
</h:form>

Your backing bean:

@ManagedBean
@RequestScoped
public class BackingBean{
    private boolean showDialog;

    public void displayDialog() {
        showDialog = true;
    }

    public boolean getShowDialog() {
        return showDialog;
    }
}

Your trigger e.g. a CommandButton:

<p:commandButton value="Show dialog" action="#{backingBean.displayDialog}" update=":myForm" /> 

Upvotes: 3

Related Questions