Announcement Announcement Module
Collapse
No announcement yet.
PrimeFaces partial page rendering with Spring Web Flow Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PrimeFaces partial page rendering with Spring Web Flow

    I have managed to set up PrimeFaces 1.0.0.RC (on Sun RI JSF 1.2) with Web Flow 2.0.8, but I cannot get partial page rendering (AJAX-requests) to work properly.

    I have written an AjaxHandler implementation for PrimeFaces, which seems to work fine, and I can even get the PrimeFaces <partialResponse> AJAX response XML document back to the browser when using PrimeFaces <p:commandLink> to update page components using AJAX.

    However, the problem is that Spring Web Flow seems to append the corresponding full XHTML page to the AJAX response just as if the request was a normal GET request, so PrimeFaces JavaScript library cannot process the response as it is no more a valid XML document as it contains two root elements.

    I've done some research on PrimeFaces server-side implementation and the AJAX response is written in a JSF PhaseListener. Web Flow seems to anyway want to write its own XHTML response after calling PrimeFaces PhaseListener without caring about my AjaxHandler result as it clearly states that the request is an AJAX request and Web Flow should not handle it in the normal way.

    For reference, here's the AjaxHandler I wrote (this might be useful for others too!):
    Code:
    public class PrimeFacesAjaxHandler
    extends WebApplicationObjectSupport implements AjaxHandler {
      public static final String PARAMETER_NAME_PRIMEFACES_AJAX =
        "primefacesAjaxRequest";
    
    	private final AjaxHandler delegate = new SpringJavascriptAjaxHandler();
    
    	public boolean isAjaxRequest(
    	    HttpServletRequest request, HttpServletResponse response) {
    		if (isPrimeFacesAjaxRequest(request, response)) {
    			return true;
    		} else {
    			return delegate.isAjaxRequest(request, response);
    		}
    	}
    
    	public void sendAjaxRedirect(String targetUrl,
    	    HttpServletRequest request, HttpServletResponse response,
    			boolean popup) throws IOException {
    		if (isPrimeFacesAjaxRequest(request, response)) {
    			response.sendRedirect(response.encodeRedirectURL(targetUrl));
    		} else {
    			delegate.sendAjaxRedirect(targetUrl, request, response, popup);
    		}
    	}
    
    	protected boolean isPrimeFacesAjaxRequest(
    	    HttpServletRequest request, HttpServletResponse response) {
    	  String ajaxStatus = request.getParameter(PARAMETER_NAME_PRIMEFACES_AJAX);
    	  
    	  if ((ajaxStatus != null) && ajaxStatus.equals("true")) {
    	    return true;
    	  }
    	  
    	  return false;
    	}
    }
    And here are the AJAX XmlHttpRequest request and response:

    Code:
    * Request Headers:
    Host	localhost:8080
    User-Agent	Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.1) Gecko/20090717 Fedora/3.5.1-1.fc11 Firefox/3.5.1
    Accept	application/xml, text/xml, */*
    Accept-Language	en-us,en;q=0.5
    Accept-Encoding	gzip,deflate
    Accept-Charset	ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive	300
    Connection	keep-alive
    Content-Type	application/x-www-form-urlencoded; charset=UTF-8
    X-Requested-With	XMLHttpRequest
    Referer	http://localhost:8080/jsfwebapp/app/main?execution=e1s1
    Content-Length	117
    Cookie	JSESSIONID=63030352699839a2d169da980a02; treeForm:tree-hi=treeForm:tree:applications; JSESSIONID=c6d9c5fe6f8b7e4aca1cd05a5524; com.sun.faces.context.flash.PostbackRequest=1775
    
    * Response Headers:
    X-Powered-By	Servlet/3.0, JSF/1.2, JSF/1.2, JSF/1.2
    Server	GlassFish v3
    Pragma	no-cache
    Expires	Thu, 01 Jan 1970 00:00:00 GMT
    Cache-Control	no-cache, no-store
    Content-Type	text/html;charset=ISO-8859-1
    Content-Length	6519
    Date	Fri, 22 Jan 2010 13:29:13 GMT
    
    * POST parameters:
    j_id12	j_id12
    j_id47_link	j_id47_link
    javax.faces.ViewState	e1s1
    name	This text should appear in a label
    primefacesAjaxRequest	true
    update	display
    
    * Response:
    <partialResponse>
      <components>
        <component>
          <id>display</id>
          <output><![CDATA[<span id="display">This text should appear in a label</span>]]></output>
        </component>
      </components>
      <state><![CDATA[]]></state>
    </partialResponse>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
          <title>Main</title>
    ...
    ... [the rest of the XHTML document]

  • #2
    SWF and Primefaces will be integrated officially in their 2.2 version.

    http://cagataycivici.wordpress.com/2...pring-webflow/

    Comment

    Working...
    X