Announcement Announcement Module
Collapse
No announcement yet.
Ajax problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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>

    Comment


    • #3
      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?

      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>

      Comment


      • #4
        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.

        Comment


        • #5
          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.

          Comment


          • #6
            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


            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.

            Comment


            • #7
              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

              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.

              Comment


              • #8
                The 'body' fragment..how is it included in the JSP? Can you post the code? Make sure that the fragment is inside a html container (div or something) with a proper id assigned to it. The Ajax tiles resolver uses the html ids to figure out what needs to be replaced.

                Comment


                • #9
                  Thanks again.

                  The body is referrend to the tiles attribute "body". However I've tried to change the fragment name of the script to the id of the div container of all, just to trie some, but that also not work.

                  Someone have little working sample with the the configuration webflow/tiles/ajax with more then 1 viewstate?



                  Originally posted by maheshguruswamy View Post
                  The 'body' fragment..how is it included in the JSP? Can you post the code? Make sure that the fragment is inside a html container (div or something) with a proper id assigned to it. The Ajax tiles resolver uses the html ids to figure out what needs to be replaced.

                  Comment


                  • #10
                    Please post the versions you are using for Spring Web Flow, Spring MVC and Tiles. If you are using Spring Web Flow 2.0.9 which in turn depends on Spring 2.5.6 how did you get around the TileConfigurer exception "Class org.apache.tiles.web.util.ServletContextAdapter not recognized a TilesApplicationContext"?

                    Comment


                    • #11
                      Hi,

                      I'm using
                      spring 2.5.6
                      flow 2.0.3
                      tiles 2.0.6
                      mvc 2.5.6

                      There isen't that kind of exception. My tiles configurer is like this:

                      Code:
                      <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
                      		<property name="definitions">
                      			<list>
                      				<value>/WEB-INF/config/tiles/tiles-layout.xml</value>
                      				<value>/WEB-INF/config/tiles/views-fornitore.xml</value>
                      [...]
                      			</list>
                      		</property>
                      	</bean>
                      Any ideas?

                      Thanks.

                      Originally posted by ranjan_george View Post
                      Please post the versions you are using for Spring Web Flow, Spring MVC and Tiles. If you are using Spring Web Flow 2.0.9 which in turn depends on Spring 2.5.6 how did you get around the TileConfigurer exception "Class org.apache.tiles.web.util.ServletContextAdapter not recognized a TilesApplicationContext"?

                      Comment


                      • #12
                        Hi

                        I'm getting really frustrated over this. I've spent two days trying to get this to work.

                        Is there really no working sample in the Spring community that makes use of the <render fragments="xxx"/> tag?

                        None of the samples; booking-faces, booking-mvc, booking-portlet-faces, booking-portlet-mvc or jsf-booking uses this functionallity.

                        I'm trying to get a partial reload of a page using Spring Webflow, Tiles and Spring javascript. I've tried using both buttons and links but I can't get it to work.

                        Help would be greatly apprechiated.

                        Regards,
                        Mattias

                        Comment

                        Working...
                        X