Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Ajax form submit using Spring Javascript

  1. #11
    Join Date
    May 2007
    Location
    Belgium
    Posts
    7

    Default

    Hi,

    As far as I understand it, the fragments parameter in the JavaScript Spring.AjaxEventDecoration call ARE the tiles which will be rendered (org.apache.tiles.Attribute). Check out AjaxTilesView.java from the springframework-js jar. If you use the FlowAjaxTilesView.java then the fragments in the flow configuration override that parameter.

    The response will contain the rendered tiles. That response will be handled by handleResponse in Spring-Dojo.js , both in the GET and POST scenario.

    In that response handling the new DOM nodes from the response are extracted and the old nodes are replaced by the new ones. (If you didn't use a modal dialog) These DOM nodes are for example div's.

    I don't know if this helps clarify the difference on the tiles and divs thing during fragments rendering.

    Regards,
    Bram Bruneel

  2. #12
    Join Date
    Aug 2008
    Posts
    17

    Default

    Quote Originally Posted by Brambo View Post
    Hi,

    As far as I understand it, the fragments parameter in the JavaScript Spring.AjaxEventDecoration call ARE the tiles which will be rendered (org.apache.tiles.Attribute). Check out AjaxTilesView.java from the springframework-js jar. If you use the FlowAjaxTilesView.java then the fragments in the flow configuration override that parameter.

    The response will contain the rendered tiles. That response will be handled by handleResponse in Spring-Dojo.js , both in the GET and POST scenario.

    In that response handling the new DOM nodes from the response are extracted and the old nodes are replaced by the new ones. (If you didn't use a modal dialog) These DOM nodes are for example div's.

    I don't know if this helps clarify the difference on the tiles and divs thing during fragments rendering.

    Regards,
    Bram Bruneel
    Yeah from what I have read it is supposed to work that way. I did a quick test with and without the div and changing the id and stuff and have figured out how to cause the refresh and how to make it stop.

    This only happens with form submit not standard get links.

    The tile that I am using is called clientList. I originally thought I had to include a div with and id attribute of clientList, but it seems I only have to include a div with an Id of any value around the content. If I include a div with a name property only, it doesn't work.

    The first submit doesn't get an update the second throws an error from the spring-dojo.js file. I am assuming if this is not a common problem that there is something about the layout that is causing the handleResponse throw an error. Possibly pgibbons is having the same issue?

    I will try and debug it using the uncompressed spring-dojo and see if i can find what is causing the issue.

  3. #13
    Join Date
    May 2007
    Location
    Belgium
    Posts
    7

    Default

    Quote Originally Posted by walterdeane View Post
    The tile that I am using is called clientList. I originally thought I had to include a div with and id attribute of clientList, but it seems I only have to include a div with an Id of any value around the content. If I include a div with a name property only, it doesn't work.
    Yes the replacement of the DOM elements will probably be based on the id's.

    Quote Originally Posted by walterdeane View Post
    The first submit doesn't get an update the second throws an error from the spring-dojo.js file. I am assuming if this is not a common problem that there is something about the layout that is causing the handleResponse throw an error. Possibly pgibbons is having the same issue?
    hmm, first submit works and second doesn't ... does the first submit event trigger a state transition perhaps?

    Quote Originally Posted by walterdeane View Post
    I will try and debug it using the uncompressed spring-dojo and see if i can find what is causing the issue.
    Debugging is the next thing to do and also check out the HTTP requests and responses with firebug while you are at it. The second POST might return data with DOM elements which can't be replaced, this will give a js error. I encountered that because some of my responses returned a standard error page.

  4. #14
    Join Date
    Jul 2007
    Location
    Italy
    Posts
    61

    Default

    Hi. Did u find any solution?
    I have this environment:

    • Spring 2.5.6
    • Spring webflow 2.0.7
    • JVM 1.5 and 1.6
    • Tomcat 5.5 and 6.0


    I have a classic Spring MVC application done by Controller, SimpleFormController and AbstractWizardFormController. I need to add some Aajax behaviours above all to my AbstractWizardFormController. I downloaded spring webflow 2.0.7 and i'ld love to use only Spring-Js framework.
    Now i'ld like to realize this scenario (if possible but i think it's possible) in my AbstractWizardFomController:

    • The user comples the required fields in first page of my page (the _target0 page)
    • He/She clicks on a link or button or submit that goes on the _target1 page
    • I wanna open a popup where the user can do some work (i.e checks some checkboxes)
    • when on the _target1 page the user clicks on confirm button i wanna do a submit to the _target0 page and refresh only a partial part od my page showing to the user the choices


    Now...in my myapp-servlet.xml file i added the TilesViewResolver that is:

    Code:
    	<bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
    		<property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView"/>
    	</bean>
    Now i have a first problem: how can i do a submit with Spring Js framework?
    In my jsp page i did this thing:


    Code:
    <a href="createCeItem.controller?_popu1&amp;folderId=<%=request.getParameter("folderId") %>" id="scegliCategorie" name="scegliCategorie" title="<fmt:message key="chooseCateogries"/>" class="button"><fmt:message key="chooseCateogries"/></a>
    <script type="text/javascript">
    /*<![CDATA[*/
    Spring.addDecoration(new Spring.AjaxEventDecoration({
    				elementId: "scegliCategorie",
    			        event: "onclick",
    				popup: true,
    				params: {fragments: "scegliCategorie"}		
    			}));
    /*]]>*/
    </script>
    The fragments params is a tiles so defined:
    Code:
    <definition name="cePopUpHome" template="/WEB-INF/ceTilesLayout/cePopupLayout.jsp">
     <put-attribute name="head" value="/WEB-INF/jsp/ce/generic/head.jsp" />
     <put-attribute name="corpo" value="" />
    </definition>	
    
    <definition name="elencoCategorie" extends="cePopUpHome">
      <put-attribute name="corpo" value="/WEB-INF/jsp/ce/item/elencoCategorie.jsp" />
    </definition>
    I "deceived" my abstracwizardform controller by overriding the isSubmissionForm method and the getTargetPage method in order to do a "submit" when the user clicks on the href. I did this thing:

    Code:
    @SuppressWarnings("unchecked")
    protected final int getButtonFromRequest(HttpServletRequest request, String value) {
    
        Enumeration<String> paramNames = request.getParameterNames();
        while (paramNames.hasMoreElements()) {
    	String paramName = (String) paramNames.nextElement();
    	if (paramName.startsWith(value)) {
    	String val = paramName.substring(value.length(), paramName.length());
    	return Integer.parseInt(val);
            }
         }
        return -1;
    	}
    
    @Override
    protected boolean isFormSubmission(HttpServletRequest request) {
    
      if (getButtonFromRequest(request, "_popup") != -1) {
    			
    	return true;
      }
       return super.isFormSubmission(request);
    }
    
    @Override
    protected int getTargetPage(HttpServletRequest request, Object command, Errors errors, int currentPage)  {
    
      int popupButton = getButtonFromRequest(request, "_popup");
      if (popupButton > -1) {
    			
        String requestUri = request.getServletPath();
        String queryString = request.getQueryString();
        requestUri = requestUri.endsWith("?") ? requestUri : requestUri+"?";
        String completeUri = requestUri+queryString;
        String msg = "E stata richiamata questa uri: "+completeUri+" sopprimo le validazioni ed apro la popup";
        LoggerUtil.traceInfo(logger, msg);
        setAllowDirtyForward(true);
        return popupButton;
       } else {
    	if( isAllowDirtyForward() ){
    				
    	  setAllowDirtyForward(false);
            }
    	return super.getTargetPage(request, currentPage);
       }
    }
    But, altough the abstractwizardformcontroller thinks it's a submit, this is not a real HTML submit so, correctly, spring will not bind the elements in command; anyway i'm able to open a popup (it seems strange but this popup doesn't have any stylesheet and i don't know why..it simply appears trasparent with the checkboxes i want); this problem is destroying me.
    Do u have any suggestion about how i could implement this scenario?

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
  •