0

I'm trying to set a dialog title at runtime (dynamically) but update with @widgetVar expression cannot do the trick. Any ideas?

The first command button renders the dialog with the dynamic title but the second command fail to render the title! Why? Here the example is simplified but the real page is more complex and it is difficult to specify the id of the dialog to render.

<h:form>
    <p:commandButton value="Basic" ajax="true" process="@this"
        update=":dlg1" oncomplete="PF('widget-dialog').show();"
        actionListener="#{dialogView.changeTitle('Dynamic title')}" />

    <p:commandButton value="Widget" ajax="true" process="@this"
        update="@widgetVar('widget-dialog')"
        oncomplete="PF('widget-dialog-1').show();"
        actionListener="#{dialogView.changeTitle('Dynamic title')}" />
</h:form>
<p:dialog id="dlg1" header="#{dialogView.title}"
    widgetVar="widget-dialog" dynamic="true">
    <h:outputText value="Resistance to PrimeFaces is futile!!!" />
</p:dialog>


@ManagedBean(name = "dialogView")
@ViewScoped
public class DialogView {

    private String title = null;
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public void changeTitle(String title) {
        setTitle(title);
    }
}
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
jpl
  • 347
  • 3
  • 11
  • No it's not the same question (it's only related to the same subject "dynamic dialog setup") – jpl Jan 10 '17 at 15:33
  • What PF version are you using? How does the network traffic look like? Any errors (client or server side) etc... – Kukeltje Jan 10 '17 at 16:17
  • PF version 5.3.17, a request is sent to the server and a partial response is returned. There is error on client and server except a warning on client console "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/." The dialog is shown but there is no title. The only difference between the 2 command button is how we update the dialog. – jpl Jan 10 '17 at 19:03
  • It seems like widgetVar="widget-dialog" doesn't target the dialog component. – jpl Jan 10 '17 at 19:18
  • I read http://stackoverflow.com/questions/19095787/using-the-component-id-as-widgetvar-name and http://blog.hatemalimam.com/intro-to-primefaces-widgetvar/ but for the moment i don't know how to address the dialog component. – jpl Jan 10 '17 at 19:30
  • Ok i found! Thanks for the links from @balusc. I investigate the dom and found how to address dialog component by id. – jpl Jan 10 '17 at 19:41
  • 1
    Uhhhmmmm that is what you do in the first button... I fail to see in what direction your are trying to solve the @widgetVar issue – Kukeltje Jan 10 '17 at 20:19
  • You made a typo with "widget-dialog-1" or is there a component with this widgetVar name? – furkan Jan 11 '17 at 12:32
  • Yes it's a typo. I resolve the problem with the first solution because if i understand the balusc link i can not use @widgetVar to do this – jpl Jan 13 '17 at 16:36

0 Answers0