tags:

views:

1099

answers:

2

How to call a JSF action mehtod thru jQuery AJAX?

+1  A: 

Calling a JSF view directly through AJAX is unwise unless your JSF stack supports AJAX and you know how to construct the request in such a way that the stack understands. Mistakes here can result in problems with the view state and difficult to diagnose errors.

Core JSF 1.2 (and before) does not have direct AJAX support; 3rd party frameworks provide varying degrees of AJAX support. JSF 2 adds AJAX JavaScript libraries to the core framework (David Geary demonstrates), so use that if possible.

One way round all this is to use a servlet to interact with the model directly (i.e. not posting back to the JSP/Facelet view). This may be adequate, depending on exactly what you are doing.

McDowell
A: 

Have you tried using the data attribute of a4j:jsFunction to return a value? This will mimic a sync call.

eg.

<a4j:jsFunction action="#{myBean.someAction}" data="#{myBean.someResult}" name="whatever" reRender="something"/>
Damo