Class AjaxPhaseListener

  extended by com.mizar.faces.ajax.phaseListener.AjaxPhaseListener
All Implemented Interfaces:, java.util.EventListener, javax.faces.event.PhaseListener

public class AjaxPhaseListener
extends java.lang.Object
implements javax.faces.event.PhaseListener

The AjaxPhaseListener is designed to handle Ajax Requests that require access to resources of the Faces application. An independent AjaxServletclass is available to handle requests that do not require access to the application.

In addition to being inside the scope of the Faces application this AjaxPhaseListener also has access to the SessionConstants EntityManager, something the AjaxServlet does not. The SessionConstants EntityManager SessionConstants.getCurrentInstance().getEm() returns RowInterface instances for any entity bean that has been registered in the faces-config.xml file SessionConstants managed-bean beanTableMap and beanRowMap Map definitions. Beans identified in these properties are assigned to a RowFactory that returns the implementing RowInterface instance instead of the JPA Entity bean superclass.

From Javascript the function phaseListenerRequest(requestName,message,getResponse) may be used to send requests to this AjaxPhaseListener class. The third argument getResponse should be false if the handler does not return a message and true if the calling Javascript anticipates a response.

 if (getResponse){
 return client.responseText;
Example Javascript:
Example Handler:
 public class ParcelQuickPickHandler extends AjaxHandler {
 public ParcelQuickPickHandler() {

 public boolean processRequest(HttpServletRequest request, HttpServletResponse response) {
 boolean rtn = false;
 String pkey = request.getParameter("pkey");
 if (StringUtils.isNotEmpty(pkey)) {
 try {
 rtn = true;
 EntityManager em = SessionConstants.getCurrentInstance().getEm();
 if (em != null) {
 //Note: that em.find actually returns a ParcelRow because of the RowFactory used to create the EntityManager.
 ParcelBean row = em.find(ParcelBean.class, pkey);
 if (row != null) {
 } catch (Exception e) {
 return rtn;

The Ajax Phase Listener must be registered in the WEB-INF/faces-config.xml file.


Handlers must be registed in the WEB-INF/faces-config.xml file in the ApplicationConstants eventHandlerNames property


There is always a 'Ping' handler, which be default is @{link PingHandler PingHandler} and There is always a 'SearchArea' handler, which be default is @{link SearchAreaHandler SearchAreaHandler}. Ping is required by the mizarMaps.js in order to keep the main application alive when the recipient is working in the Maps <div> for an extended period of time. You can override these handlers by adding a 'Ping' or 'SearchArea' handler definition to the faces-config.xml as per the example above.

See Also:
ApplicationConstants.getEventHandlers(), PingHandler, Serialized Form

Field Summary
protected  org.apache.commons.logging.Log _Logger
Constructor Summary
Method Summary
 void afterPhase(javax.faces.event.PhaseEvent e)
 void beforePhase(javax.faces.event.PhaseEvent e)
 javax.faces.event.PhaseId getPhaseId()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected org.apache.commons.logging.Log _Logger
Constructor Detail


public AjaxPhaseListener()
Method Detail


public void afterPhase(javax.faces.event.PhaseEvent e)
Specified by:
afterPhase in interface javax.faces.event.PhaseListener


public void beforePhase(javax.faces.event.PhaseEvent e)
Specified by:
beforePhase in interface javax.faces.event.PhaseListener


public javax.faces.event.PhaseId getPhaseId()
Specified by:
getPhaseId in interface javax.faces.event.PhaseListener