Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 803
jrobertsz66 Avatar asked Oct 26 '25 07:10

jrobertsz66


1 Answers

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" /> 
like image 82
flash Avatar answered Oct 29 '25 07:10

flash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!