Create PrimeFaces dialogs dynamically

2020-03-24 03:16发布

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?

3条回答
Evening l夕情丶
2楼-- · 2020-03-24 03:39

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");
查看更多
地球回转人心会变
3楼-- · 2020-03-24 03:44

@newuserua Your code is not working widgetVar value is setted only once when page load

...
requestContext.update("panel_id");

the above line updated complete panel its refreshing all the existing dialog and its contents.

查看更多
劫难
4楼-- · 2020-03-24 03:51

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>
查看更多
登录 后发表回答