Ajax Events with arguments

UI Components for JSF
Post Reply
Laabidi Raissi
Posts: 8
Joined: 12 Aug 2011, 16:15

01 Jan 2012, 14:15

Hello everyone, and Happy new Year,
I am trying to use the primefaces schedule component inside a list of entries (dataGrid).
So every row will have a schedule in it. And what I need when user select a new event, is not only the date of that event, but also to which schedule that event belongs.
So what I think I can do is using a custom listener for the dateSelect event, something like this:

Code: Select all

<p:ajax event="dateSelect" listener="#{scheduleController.onDateSelect(DateSelectEvent, scheduleId)}" update="eventDetails" oncomplete="eventDialog.show()" />
The problem is that I do not know how to build and pass the DateSelectEvent to my managed bean which will have a listener like this:

Code: Select all

public void onDateSelect(DateSelectEvent selectEvent, Long id);

Thanks for any idea
Eclipse Kepler, WAS 8.5.5, Java EE 6, PrimeFaces 4.0, Mojarra 2.2.5 (JSF 2.2)

Posts: 6144
Joined: 10 Sep 2011, 21:10

01 Jan 2012, 23:53

Happy New Year.

1. It would be nice to see your bean and xhtml, to see all code related to p:dataTable and p:schedule.

2. Read this BalusC blog: Pass variables from client side to server side

3. Add following to your XHTML, something similar to the following:

Code: Select all

<h:inputHidden id="selectedScheduleId" value="#{bean.selectedScheduleId}" />
function setSelectedScheduleId(selectedScheduleId) {
   document.getElementById('formID:selectedScheduleId').value = selectedScheduleId;
NOTE: formID:selectedScheduleId in xhtml above, please View Source after page is rendered in browser, and get the element ID of the h:inputHidden.

4. modify the p:ajax as follows:

Code: Select all

<p:ajax event="dateSelect" listener="#{scheduleController.onDateSelect}"
            onstart="setSelectedScheduleId(scheduleId_from_dataTable)" oncomplete="eventDialog.show()" update="eventDetails"/>
5. bean needs the following (or similar):

Code: Select all

    private Integer selectedScheduleId;



6. In the JSF/PrimeFaces web app that I'm developing, I am using javascript to populate h:inputHidden, so that I can pass data back to the server.
See topic: [SOLVED] Unable to fire an action from subtable column

7. Also, it would be nice to know a little more history related to this post/topic of yours. Did you already add p:schedule to p:dataTable, and it is rendering well? I'm asking, because quite honestly, I don't know if it's possible to do so, because I've heard of a Mojarra defect when encapsulating components within components, especially components within p:dataTable, but there has been recent discussion (or other topics) where you can wrap h:panelGroup around p:schedule, and then p:schedule might render/function well within p:dataTable.

8. Please see my signature below and update your signature in your Profile in User Control Panel, or provide those details in your responses and future posts here in this community forum.

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Laabidi Raissi
Posts: 8
Joined: 12 Aug 2011, 16:15

05 Jan 2012, 17:33

Hi smithh032772
I am so sorry for answering so late. It's because I was very busy at work these days.
First of all, thank you for your reply.
I did not try your solution (which seems to work fine). In fact, I used a little workaround:
In changed the datatable to iterate on a DataModel (instead of list), and when a row is clicked on, I call the DataModel#getRowData() to obtain the selected object.
Eclipse Kepler, WAS 8.5.5, Java EE 6, PrimeFaces 4.0, Mojarra 2.2.5 (JSF 2.2)

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests