1

I want to get an return value from the a4j:jsFunction. But I don't know how to get this done.

Here's the JSF code:

<h:form>
    <a4j:jsFunction name="createEvent" data="#{calendarController.eventId}" action="#{calendarController.createEvent()}">
        <a4j:param name="eventTitle"
            assignTo="#{calendarController.eventTitle}" />
    </a4j:jsFunction>
</h:form>

And I call the a4j:jsFunction like this:

var id = createEvent(event.title);

The Beans method calendarController.createEvent() returns an integer value. The property eventId holds this value to. How can I pass this value back to the javascript code on the page?

user1451130
  • 135
  • 1
  • 10

1 Answers1

3

As the ajax call is asynchronous you cannot get the value directly from the 'createEvent' method. You can however obtain it if you use the 'oncomplete' attribute for example like this:

<h:form>
    <a4j:jsFunction name="createEvent" data="#{calendarController.eventId}" action="#{calendarController.createEvent()}" oncomplete="alert(data)">
        <a4j:param name="eventTitle"
            assignTo="#{calendarController.eventTitle}" />
    </a4j:jsFunction>
</h:form>

See here for a similar problem.

dratewka
  • 2,104
  • 14
  • 15