Results 1 to 10 of 12

Thread: Ajax problem

Hybrid View

  1. #1
    Join Date
    Jul 2010
    Posts
    6

    Default Ajax problem

    Hi all, this is my first post.

    As I said in the title I've some problems running Ajax with webflow. I've read all documentation:

    I've configure all like said documentation:
    webmvc-config.xml:
    Code:
    <bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
            <property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView" />
    </bean>
    All the configuration are ok and working without ajax. The javascript are imported correctly.

    I have 2 viewstate:
    Code:
         
    <view-state id="enterFornitoreDetails" view="fornitore.dettaglio" >
             <on-entry>
                 <evaluate expression="fornitoreService.getDettaglioFull(codiceFornitore, profilo)" result="flowScope.fornitore" />
             </on-entry>
             <on-render>
                 <render fragments="body" />
             </on-render>
            <transition on="modifica" to="enterFornitoreModify" />
            <transition on="chiudi" to="endFlow" />
    </view-state>
         
     <view-state id="enterFornitoreModify" view="fornitore.modifica"  >
             <on-render>
                 <render fragments="body" />
             </on-render>
            <transition on="saveAndClose" to="fornitoreModified">
                <evaluate expression="fornitoreService.save(codiceFornitore, profilo)" result="flowScope.fornitore" />
            </transition>
            <transition on="cancelAndClose" to="fornitoreUnmodified" />
    </view-state>
    Those are the tiles
    Code:
    <tiles-definitions>
    
        <definition name="layout" template="/WEB-INF/jsp/layout.jsp">
            
            <put-attribute name="menu1lev" value="/WEB-INF/jsp/menu1lev.jsp" />
            <put-attribute name="menu2lev" value="/WEB-INF/jsp/menu2lev.jsp" />
            <put-attribute name="body" value="/WEB-INF/jsp/indexBody.jsp" />
        </definition>
    
    </tiles-definitions>
    and
    Code:
    <tiles-definitions>
    
        <definition name="fornitore.dettaglio" extends="layout">
            <put-attribute name="body" value="/WEB-INF/jsp/fornitore/dettaglio.jsp" />
        </definition>
    
        <definition name="fornitore.modifica" extends="layout">
            <put-attribute name="body" value="/WEB-INF/jsp/fornitore/modifica.jsp" />
        </definition>
    
    </tiles-definitions>
    The JSP to start the "modifica" event is this this:

    Code:
    <form:form  id="form1" action="${webAppPrefix}${flowExecutionUrl}" >
                <input id="enterFornitoreModify" name="_eventId_modifica" value="Modifica" type="submit"  class="submit_b"  />            
                <script type="text/javascript">
                Spring.addDecoration(new Spring.AjaxEventDecoration({elementId:'enterFornitoreModify', event:'onclick',formId:'form1'}));
                </script>
    </form:form>
    The transition is working, i've also tried to evaluate a service inside the "modifica" transition and it work.

    Without the decoration all work perfect. With the decoration nothings happens. The request start but nothing render, the page stay the same of the call.

    Someone can help?

    Thanks

  2. #2
    Join Date
    Mar 2010
    Location
    Boston, MA
    Posts
    316

    Default

    You have to specify which fragment to re render..something like

    Code:
    <form:form  id="form1" action="${webAppPrefix}${flowExecutionUrl}" >
                <input id="enterFornitoreModify" name="_eventId_modifica" value="Modifica" type="submit"  class="submit_b"  />            
                <script type="text/javascript">
                Spring.addDecoration(new Spring.AjaxEventDecoration({elementId:'enterFornitoreModify', event:'onclick',formId:'form1',params: { fragments: "fornitore.dettaglio" }}));
                </script>
    </form:form>

  3. #3
    Join Date
    Jul 2010
    Posts
    6

    Default

    Thanks for the reply.
    But on the Web Flow References on cap. "Handling Ajax Requests" there is:

    Spring Web Flow handles the optional rendering of fragments directly in the flow definition language through use of the render element. The benefit of this approach is that the selection of fragments is completely decoupled from client-side code, such that no special parameters need to be passed with the request the way they currently must be with the pure Spring MVC controller approach.
    However I've tried your suggest, but that doesn't work too.

    Some other ideas?

    Quote Originally Posted by maheshguruswamy View Post
    You have to specify which fragment to re render..something like

    Code:
    <form:form  id="form1" action="${webAppPrefix}${flowExecutionUrl}" >
                <input id="enterFornitoreModify" name="_eventId_modifica" value="Modifica" type="submit"  class="submit_b"  />           
                <script type="text/javascript">
                Spring.addDecoration(new Spring.AjaxEventDecoration({elementId:'enterFornitoreModify', event:'onclick',formId:'form1',params: { fragments: "fornitore.dettaglio" }}));
                </script>
    </form:form>

  4. #4

    Default

    Couple of things:

    * The "modifica" transition takes you to a new view-state, which would mean a new screen and a different JSP right? So really the render fragment is probably irrelevant.

    * You say that the request starts but stays on the same page. So did the request hit the server and the transition occur? The server side debug statements from Web Flow should give you a hint as to whether the transition has fired at all, succeeded or failed. Typically, if the transtion was fired and failed, then the flow would remain in the same view-state.

    * If the transition did not fire at all, I would suspect a spring javascript setup issue. If you are using FireFox, turn on the Add-On and see what that tells you.

  5. #5
    Join Date
    Mar 2010
    Location
    Boston, MA
    Posts
    316

    Default

    Agree with Ranjan..i think at this point best thing is to inspect the request/response using firebug or something else..if the AJAX call was successful you should be able to see the tiles html returning in the response of that POST call.

  6. #6
    Join Date
    Jul 2010
    Posts
    6

    Default

    I've read all thanks.

    Like suggest I've read the call with firebug.

    Those are the parameters of the post call:

    Code:
    http://localhost/scriptAlbo/AlboFornitori/fo/dettaglioFornitore?execution=e5s1&_eventId_modifica=_eventId_modifica&ajaxSource=enterFornitoreModify&fragments=body
    And those are the html response page (an empty jsp with the word "modifica":
    Code:
    MODIFICA
    So the call happen correctly, the response is good too, but there isen't an update of the page.

    Other ideas?

    Thanks

    Quote Originally Posted by maheshguruswamy View Post
    Agree with Ranjan..i think at this point best thing is to inspect the request/response using firebug or something else..if the AJAX call was successful you should be able to see the tiles html returning in the response of that POST call.

  7. #7
    Join Date
    Jul 2010
    Posts
    6

    Default

    Thanks again for reply.

    * Ok, so how I can render only a part of a page between two different state? Web flow doesn't support that?

    * The javascript was fired well, this is the DEBUG log:
    Code:
    28/07/2010 14:28:45,419 DEBUG [15] [org.springframework.webflow.engine.ViewState] - Entering state 'enterFornitoreModify' of flow 'modificaFornitore'
    28/07/2010 14:28:45,419 DEBUG [15] [org.springframework.webflow.engine.impl.FlowExecutionImpl] - Assigned key e2s2
    28/07/2010 14:28:45,419 DEBUG [15] [org.springframework.webflow.engine.ViewState] - Rendering + org.springframework.webflow.mvc.servlet.ServletMvcView@1917ef8
    28/07/2010 14:28:45,419 DEBUG [15] [org.springframework.webflow.engine.ViewState] - Flash scope = map[[empty]]
    28/07/2010 14:28:45,419 DEBUG [15] [org.springframework.webflow.engine.ViewState] - Messages = [DefaultMessageContext@126d5d1 sourceMessages = map[[null] -> list[[empty]]]]
    28/07/2010 14:28:45,419 DEBUG [15] [org.springframework.webflow.execution.ActionExecutor] - Executing [RenderAction@19a9cd0 fragments = array<Expression>[body]]
    28/07/2010 14:28:45,419 DEBUG [15] [org.springframework.webflow.execution.AnnotatedAction] - Putting action execution attributes map[[empty]]
    28/07/2010 14:28:45,419 DEBUG [15] [org.springframework.webflow.execution.AnnotatedAction] - Clearing action execution attributes map[[empty]]
    28/07/2010 14:28:45,419 DEBUG [15] [org.springframework.webflow.execution.ActionExecutor] - Finished executing [RenderAction@19a9cd0 fragments = array<Expression>[body]]; result = success

    The problem still remain, on the server side all ok until the render action, the browser stay on the same page without refresh itself or fragment.


    I'm thinking to integrate with a simple Ajax.Update of prototype


    Quote Originally Posted by ranjan_george View Post
    Couple of things:

    * The "modifica" transition takes you to a new view-state, which would mean a new screen and a different JSP right? So really the render fragment is probably irrelevant.

    * You say that the request starts but stays on the same page. So did the request hit the server and the transition occur? The server side debug statements from Web Flow should give you a hint as to whether the transition has fired at all, succeeded or failed. Typically, if the transtion was fired and failed, then the flow would remain in the same view-state.

    * If the transition did not fire at all, I would suspect a spring javascript setup issue. If you are using FireFox, turn on the Add-On and see what that tells you.

Posting Permissions

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