Results 1 to 7 of 7

Thread: Fragments & Ajax

  1. #1

    Default Fragments & Ajax

    Hi everyone,

    I have a Web Flow project that I've integrated with Spring MVC. What I'm trying to do now is set up flow.xml to return fragments from my tilesdefs.xml.

    Here is my set up:

    When I'm in one view state which I'll call "A", that has a view of "AView", I want to run any AJAX request that returns some data. To get this data, I set up a transition in "A" called "A1" which doesn't transition to any other state, but has a render child node that has a fragment called "A1View". From what I understand from the (lackluster) document "A1View" should be and is a "put-attribute" in the "AView" definition in tilesdefs.


    The problem I'm having is this:

    The AJAX call of the following pseudo URL: path?A&_eventId=A1[/url]

    This ends up returning me the full page of "AView" instead of the fragment of "A1View" I requested.


    Questions:

    Is there something wrong with my set up? Am I missing something?

    Any help would be greatly appreciated. Please don't direct me to the booking-mvc example or any 500 page documentation. They barely touch on this subject.

    Thanks in advance,
    Brandon
    Last edited by bmgreeley; Nov 24th, 2008 at 05:05 PM.

  2. #2

    Default

    To simplify the questions, how does an AJAX request actually trigger a transition? I would assume it would be the "_eventId=" argument. But I may be wrong.

  3. #3
    Join Date
    Nov 2008
    Posts
    5

    Default

    Quote Originally Posted by bmgreeley View Post
    To simplify the questions, how does an AJAX request actually trigger a transition? I would assume it would be the "_eventId=" argument. But I may be wrong.
    Atleast FlowAjaxTilesView uses SpringJavascriptAjaxHandler, which requires that there is either a parameter with name "ajaxSource" (value doesn't matter) or the content type of the request must be "text/html;type=ajax".

    Code:
    /**
    	 * The accept header value that signifies an Ajax request.
    	 */
    	public static final String AJAX_ACCEPT_CONTENT_TYPE = "text/html;type=ajax";
    
    	/**
    	 * Alternate request parameter to indicate an Ajax request for cases when control of the header is not available.
    	 */
    	public static final String AJAX_SOURCE_PARAM = "ajaxSource";
    
    	public boolean isAjaxRequest(HttpServletRequest request, HttpServletResponse response) {
    		String acceptHeader = request.getHeader("Accept");
    		String ajaxParam = request.getParameter(AJAX_SOURCE_PARAM);
    		if (AJAX_ACCEPT_CONTENT_TYPE.equals(acceptHeader) || StringUtils.hasText(ajaxParam)) {
    			return true;
    		} else {
    			return false;
    		}
    	}

  4. #4

    Default

    Wow. That worked. Thanks!

  5. #5
    Join Date
    Dec 2008
    Location
    Ulaanbaatar, Mongolia
    Posts
    123

    Default

    Quote Originally Posted by palto View Post
    Atleast FlowAjaxTilesView uses SpringJavascriptAjaxHandler, which requires that there is either a parameter with name "ajaxSource" (value doesn't matter) or the content type of the request must be "text/html;type=ajax".

    Code:
    /**
    	 * The accept header value that signifies an Ajax request.
    	 */
    	public static final String AJAX_ACCEPT_CONTENT_TYPE = "text/html;type=ajax";
    
    	/**
    	 * Alternate request parameter to indicate an Ajax request for cases when control of the header is not available.
    	 */
    	public static final String AJAX_SOURCE_PARAM = "ajaxSource";
    
    	public boolean isAjaxRequest(HttpServletRequest request, HttpServletResponse response) {
    		String acceptHeader = request.getHeader("Accept");
    		String ajaxParam = request.getParameter(AJAX_SOURCE_PARAM);
    		if (AJAX_ACCEPT_CONTENT_TYPE.equals(acceptHeader) || StringUtils.hasText(ajaxParam)) {
    			return true;
    		} else {
    			return false;
    		}
    	}
    How can I set the content type to "text/html;type=ajax"?
    Let's care our nature!

  6. #6
    Join Date
    Nov 2008
    Posts
    5

    Default

    Quote Originally Posted by digz6666 View Post
    How can I set the content type to "text/html;type=ajax"?
    You should check the documentation of you ajax library on how to do that.

  7. #7
    Join Date
    Dec 2008
    Location
    Ulaanbaatar, Mongolia
    Posts
    123

    Default

    Quote Originally Posted by palto View Post
    You should check the documentation of you ajax library on how to do that.
    I'm using web flow 2.0.7, tiles 2.0.6 and spring 2.5.6.

    How to do in this situation?
    Also could you please take a look at following problem?
    Maybe you can help:

    http://forum.springsource.org/showpo...51&postcount=6
    Let's care our nature!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •