Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create PrimeFaces dialogs dynamically

I'm using primefaces 3.3.1 and JSF 2 (Mojarra 2.1.9).

I have a page with a DataTable component and Dialog to show details of DataTable entries. That's very simple when I have one dialog. What I want is to try to allow users to open two or three dailogs with details of different entries in the same time. Does somebody have any idea how to get whole dialog with AJAX from server, not just a dialog content?

like image 941
partlov Avatar asked Jun 22 '12 08:06

partlov


2 Answers

Yes I did. For this purpose I created necessary dialogs programmatically in backing bean. I know this is not really best practice, but in this moment I think this is only possible solution. First of all I added one group panel which is container for dialogs on my JSF page. Then on backing bean I have some code like this:

UIComponent panelGroup = facesContext.getViewRoot().findComponent("panel_id");
Dialog dialog = new Dialog();
dialog.setHeader("Sample");
dialog.setVisible(true);
dialog.setMinimizable(true);
...
panelGroup.getChildren().add(dialog);
...
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.update("panel_id");
like image 100
partlov Avatar answered Oct 04 '22 15:10

partlov


Dialog id also can be dynamic so you can create some id or some other value and give it him.

<p:dialog header="Choose Delimiter Type" id="dialog"
    widgetVar="exportDialog#{p.Id}" resizable="false" >

and calling via button ;

<p:commandButton id="id" value="xxx"
            actionListener="#{p.export2CSV}" ajax="false"
            onclick="exportDialog#{p.tabId}.show()">                
        </p:commandButton>
like image 24
newuserua Avatar answered Oct 04 '22 14:10

newuserua