add p:ajax open event to the p:dialog

UI Components for JSF
Post Reply
kirpi4ik
Posts: 17
Joined: 16 Mar 2011, 21:19

27 Jun 2011, 14:47

Hi,

I'm using latest version of Primefaces 3(subversion head).
I have seen that there are lot of changes regarding new ajax events. It would be useful to have a new event in the dialog window which will be triggered after the window is displayed.

Code: Select all

<p:dialog>
    <p:ajax event="open" listener="#{initialize dialog window content}" update="dialogUI"/>
   ...
</p:dialog>
I need to initialize the dialog UI window after it is opened, I have tested something like this:

Code: Select all

<p:commandButton actionListener="#{initialize dialog window content}" onclick="myDialog.show();" ajax="true" update="dialogUI"/>
But this approach doesn't work, the UI of dialog window is not updated.


thank you,
Dima

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

27 Jun 2011, 14:57

There is currently no open event.

kirpi4ik
Posts: 17
Joined: 16 Mar 2011, 21:19

27 Jun 2011, 15:13

Thank you for quick response,
Are you considering this as feature, or should we look for some workaround? It would be nice to have such event because the dialog is "rendered" and usually we don't want or can't initialize the content of dialog before displaying it.




regards,
Dima

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

27 Jun 2011, 15:15

We are not considering to add it because you can do it easier with your commandButton.

Code: Select all

<p:commandButton actionListener="#{initialize dialog window content}" oncomplete="myDialog.show();" ajax="true" update="dialogUI"/>

kirpi4ik
Posts: 17
Joined: 16 Mar 2011, 21:19

27 Jun 2011, 18:10

Unfortunately your suggestion doesn't work:

Code: Select all

<p:commandButton actionListener="#{initialize dialog window content}" oncomplete="myDialog.show();" ajax="true" update="dialogUI"/>
the dialog window UI is not updated.

In order to be sure that the problem comes from the update functionality and not from the server, I have added test button on the dialog window :

Code: Select all

<p:dialog>
   ...
    <p:commandButton value="Update"  update="dialogUI" />
 ...
</p:dialog>
On click this button just updates the content with no server side interaction.
So it seems that even the dialog is shown(oncomplete) after the actionListener method is executed, the dialog content is not updated.

Any other suggestion?

Thank you,
Dima

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

27 Jun 2011, 18:25

You have a problem on your end, we use the proposed approach in all our apps and showcase as well.

kirpi4ik
Posts: 17
Joined: 16 Mar 2011, 21:19

27 Jun 2011, 18:28

Yes you right, It seems that I found the problem, but this is very strange problem.
I'm using facelets and my dialog windows are included with the

Code: Select all

 <ui:define name="dialogs">
    <ui:include src="myDialog.xhtml" />
</ui:define>
Unfortunately I need to include the dialogs in this way.


thank you,
Dima

kirpi4ik
Posts: 17
Joined: 16 Mar 2011, 21:19

27 Jun 2011, 19:31

It seems that I have hastened with conclusions. Because even if I removing facelet tag from this particular page, the dialog still doesn't works.

so I'm out of ideas

smotron
Posts: 7
Joined: 03 Jan 2012, 13:08

03 Jul 2012, 10:44

We would also be very keen on the availability of an open event. The reason for prefering an open event to the solution with the command button is that this way the actionListener would be fix linked to the dialog. We intend to use the same dialog many a time and so one would have to remeber every time using the dialog not to forget to include a particular actionListener.

So, you already mentioned that you don't have in mind to implement the open event, but is there another alternative instead of adding the actionlistener to the command button and to link the action Listener to the dialog?

kirpi4ik
Posts: 17
Joined: 16 Mar 2011, 21:19

03 Jul 2012, 15:01

I've designed our application without open event, by using javax.enterprise.event.Event in this way I'm decoupling the dialog bean with the "source view".
Every button which calls popup.show() also invoke actionListener with unique eventId, then in your "view" you must implement the @Observes logic.
Eg:

Code: Select all

...
public class CustomerSelector{
...
	@Inject
	@CustomerSelectionEvent
	private Event<Customer>		selectEvent;
	public void initialize(String eventId) {
		this.eventId = eventId;
	}
	public void select() {
		selectEvent.select(new EventIdQualifier(eventId)).fire(getSelected());
	}
...
}

Code: Select all

public class SomeViewBean{
...
	private void method1(@Observes(notifyObserver = Reception.IF_EXISTS) @EventId("method1.event") @CustomerSelectionEvent customer) {
		this.customer1=customer;
	}
	private void method2(@Observes(notifyObserver = Reception.IF_EXISTS) @EventId("method2.event") @CustomerSelectionEvent customer) {
		this.customer2=customer;
	}
...
}
in your xhtml you would have:

Code: Select all

<p:commandButton value="method1" actionListener="#{customerSelector.initialize('method1.event')}" oncomplete="myDialog.show();">
<p:commandButton value="method2" actionListener="#{customerSelector.initialize('method2.event')}" oncomplete="myDialog.show();">
In this way your button will be connected to the method1/method2 by using unique eventID and not to the dialog, so you will be able to reuse it from many views.

Regards,
Dima

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 44 guests