I usually applaud PrimeFaces for its simplicity, ease of integration with other component kits, and its extensive collection of components. The documentation is pretty good, too, as long as you ignore the myriad typos and just plain wrong things. Recently, it almost officially got Spring Web Flow support in the 1.0.1 snapshot builds. (I had been running it with SWF already, but the 1.0.0 release broke that.) I assume that in the rush to get it up and running, there was an integration oversight, and that means that you can’t run SWF with PrimeFaces and another kit with AJAX components at the same time. That’s okay, because it’s an easy fix.


Here is my updated version of the PrimeFacesAjaxHandler. If you compare it with what’s in the 1.0.1 snapshot, you’ll see that the main difference is that this can take a configurable delegate. (The @PostInitialize annotation basically triggers ApplicationListener<ContextRefreshedEvent> event handling, so you can reimplement it directly like that if you want, or use the old InitializingBean method.) The other difference is the possible bug in sendAjaxRedirect where it could shortcut the delegate if it’s the delegate’s AJAX request. I didn’t investigate, so maybe the original is actually okay.

/*
 * Copyright 2009-2010 Prime Technology.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.faces.primefaces;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.js.ajax.AjaxHandler;
import org.springframework.js.ajax.SpringJavascriptAjaxHandler;

import utils.spring.PostInitialize;

/**
 * PrimeFaces implementation of SpringJavascriptAjaxHandler Only used for Spring
 * WebFlow Integration
 */
public class PrimeFacesAjaxHandler
	implements AjaxHandler
{

	private AjaxHandler delegate;

	@PostInitialize
	public void init() {
		if (delegate == null) {
			delegate = new SpringJavascriptAjaxHandler();
		}
	}

	public boolean isAjaxRequest(HttpServletRequest req, HttpServletResponse resp) {
		return isPrimeFacesAjaxRequest(req) || delegate.isAjaxRequest(req, resp);
	}

	public void sendAjaxRedirect(String targetURL, HttpServletRequest req, HttpServletResponse resp, boolean popup)
		throws IOException
	{
		if (isPrimeFacesAjaxRequest(req)) {
			resp.sendRedirect(targetURL);
		} else {
			delegate.sendAjaxRedirect(targetURL, req, resp, popup);
		}
	}

	public void setDelegate(@SuppressWarnings("hiding") AjaxHandler delegate) {
		this.delegate = delegate;
	}

	private boolean isPrimeFacesAjaxRequest(HttpServletRequest request) {
		return request.getParameterMap().containsKey("primefacesPartialRequest");
	}

}

This now allows this to work and then the AJAX calls are all happy:

	<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">

		<property name="ajaxHandler">

			<bean class="org.springframework.faces.primefaces.PrimeFacesAjaxHandler">

				<property name="delegate">

					<bean class="org.springframework.faces.richfaces.RichFacesAjaxHandler" />

				</property>

			</bean>

		</property>

[...]

	</bean>
  • Digg
  • Delicious
  • StumbleUpon
  • Technorati Favorites
  • Reddit
  • Yahoo Buzz
  • Twitter
  • DZone
  • Google Bookmarks
  • LinkedIn
  • Amazon Wish List
  • Share/Bookmark