3

I'm working with JSF and PrimeFaces, and I can't handle the following situation: I have a dialog, and I placed a dataTable on it. In one of the cells of the table I would like to display given data in 3 different ways, and I'd like to switch between them. So far I managed to switch between these rendering types via commandLink, but my problem is that when I click on one of the 3 links, the dialog closes! Can I update the content of the dialog, and be able to keep it open the same time? (I'm updating which render type to use via myMethod)

my commandLink looks like this:

<p:commandLink id="id" update=":myForm:myDialog" ajax="false"
               action="#{myBean.myMethod}" oncomplete="dialog.show()">

If i don't use the ajax=false attribute, the method is not called, and I also tried imediate=true, but that's not it either.

bajla
  • 163
  • 2
  • 2
  • 12

2 Answers2

6

You need to define an p:outputPanel inside your dialog and update the outputpanel, not the dialog itself (that's why your dialog closes):

<p:dialog id="myDialog" ...>
  <p:outputPanel id="myOutputPanel">
    ... your dialog content goes here
  </p>
</p:dialog>

and change your commandlink

<p:commandLink id="id" update=":myForm:myDialog:myOutputPanel" ajax="true"
           action="#{myBean.myMethod}" oncomplete="dialog.show()">

Regarding the oncomplete="dialog.show()" - I'm not entirely sure if you need that. A precise answer can be given if you provide more code regarding your table and code.

Manuel
  • 3,481
  • 6
  • 30
  • 45
  • I don't think including the output panel and updating it makes any difference. I had the same problem and I tested this theory without adding oncomplete="dialog.show()" and the dialog still closes. oncomplete="dialog.show()" will make it show again, but it is not an ideal solution because there will be a flicker when the dialog disappears and reappears. – jrobertsz66 Jul 15 '15 at 03:10
  • You don't think it makes a difference? Try it, it does make one. Because in one case the whole dialog gets updated (update: remove it from DOM and re-add it to the DOM), or in the second just the outputpanel inside the dialog gets updated and the dialog stays the same. – Manuel Jul 15 '15 at 04:56
  • What makes the the difference is that the Q has `ajax="false"` (where onComplete does dot work...) and you use the implicit `ajax="true"`, so both are right (if the ajax part was not changed) – Kukeltje Feb 16 '17 at 11:27
0

I had the same problem, and solution is to update a form instead of dialog. For example:

<p:dialog id="id_dialog" ...>
  <h:form id="id_form">
      ... content
  </h>
</p:dialog>

and commandLink:

<p:commandLink update=":id_form" process="@all" ...>

This worked for me!

akelec
  • 3,075
  • 3
  • 36
  • 35
  • Your answer is effectively identical to the one already given. The only difference is that you put a form instead of a panel inside it. Off-topic: `process="@all"` is not advised. Could result in weird effects when multiple forms are present. – Kukeltje Feb 16 '17 at 11:23
  • Thank you for an advice, but I do not agree with you. My answer is similar to the given, but with one big difference: this solution works. I also tried with the given solution but without success. OK, `process="@all"` is not neccesarry. – akelec Feb 16 '17 at 17:07
  • hi I also have the same issue but your solution is not working for me. Does it depend on primefaces version? – Moussa Nov 22 '19 at 11:51
  • Hi @Moussa. Yes, it is possible that this is a version related issue. I'm sorry, but I don't remember what version was in my case. Unfortunately, I have no longer an access to the project. – akelec Nov 22 '19 at 20:27
  • Ok thanks @akelec finally got another solution by avoiding use of the commandButton for my case. – Moussa Nov 23 '19 at 23:42
  • You welcome @Moussa. Please, feel free to share your solution with the community. – akelec Nov 25 '19 at 12:51