Announcement Announcement Module
Collapse
No announcement yet.
How to use "<render fragments=" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use "<render fragments="

    Hi all,

    I'm new in SWF and i have some problem to use the render fragments .

    Some info: I'm using SWF with tiles and hibernate

    Can i use the render tag in a simple jsp page of must i use ajax or jsf to use it?

    I'm trying to use the render tag but he render the full page and i lost the first information that i have selected.

    her is my code

    my webFlow
    Code:
    	<view-state id="createAcount" view="createAcount">
    		<on-entry>
    			<evaluate expression="userService.getAllCountries()" result="flowScope.countries" />
    		</on-entry>
    		<transition on="languagesForCountry">
    			<set name="requestScope.countryId" value="requestParameters.countryId" />
    			<evaluate expression="userService.getAllLanguagesByCountry(countryId)" result="flowScope.languages" />
    			<render fragments="languageRender"/>
    		</transition>
    	</view-state>
    my jsp
    Code:
    <tags:coreTag>
    <script type="text/javascript">
    <!--
    function getValue(value){
    	var url = document.getElementById('execution').value;
    	var event = document.getElementById('eventId').value + '&countryId=' + value;
    
    	window.location.href = url+event;
    }
    -->
    </script>
    	<input type="hidden" id="execution" value="${flowExecutionUrl}" />
    	<input type="hidden" id="eventId" value="&_eventId_languagesForCountry" />
    
    	<table>
    		<tr>
    			<td><fmt:message key="person.country" /></td>
    			<td><form:select id="country" path="countries" onchange="getValue(this.value)">
    				<form:option value="null" label="empty" />
    				<form:options items="${countries}" itemValue="id" itemLabel="name" />
    			</form:select></td>
    		</tr>
    	</table>
    
    
    	<div id="languageRender"><c:if test="${languages != null}">
    		<td><fmt:message key="person.language" /></td>
    		<td><form:select id="language" path="languages">
    			<form:option value="null" label="empty" />
    			<form:options items="${languages}" itemValue="id" itemLabel="name" />
    		</form:select></td>
    	</c:if></div>
    </tags:coreTag>
    Thanks for information and sorry for my bad English

  • #2
    Hi all,

    Nobody know how to use <render fragments=, must it used with jsf, ajax or can we used in a simple jsp ?

    Thanks for reply or for some example

    Comment


    • #3
      I would look at the booking-mvc sample in the web flow distribution that shows how to do partial rendering using the render action with jsp + and tiles.

      Comment


      • #4
        booking example dont use &lt;render fragments=

        Thanks for reply

        Code:
        <?xml version="1.0" encoding="UTF-8"?>
        <flow xmlns="http://www.springframework.org/schema/webflow"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
        
        	<secured attributes="ROLE_USER" />
        
        	<persistence-context/>
        
        	<input name="hotelId" required="true" />
        	
        	<on-start>
        		<evaluate expression="bookingService.createBooking(hotelId, currentUser.name)" result="flowScope.booking" />
        	</on-start>
        	
        	<view-state id="enterBookingDetails" model="booking">
        		<binder>
        			<binding property="checkinDate" converter="shortDate" required="true" />
        			<binding property="checkoutDate" converter="shortDate" required="true" />
        			<binding property="beds" required="true" />
        			<binding property="smoking" required="true" />
        			<binding property="creditCard" required="true" />
        			<binding property="creditCardName" required="true" />
        			<binding property="creditCardExpiryMonth" required="true" />
        			<binding property="creditCardExpiryYear" required="true" />
        		</binder>
        		<transition on="proceed" to="reviewBooking" />
        		<transition on="cancel" to="cancel" bind="false" />
        	</view-state>
        	
        	<view-state id="reviewBooking" model="booking">
        		<transition on="confirm" to="bookingConfirmed" />
        		<transition on="revise" to="enterBookingDetails" />
        		<transition on="cancel" to="cancel" />
        	</view-state>
        	
        	<end-state id="bookingConfirmed" commit="true" />
        
        	<end-state id="cancel" />
        			
        </flow>
        In the booking example the "<render fragments=" is not used so i can understand how to use it.

        What is the best practice to use "<render fragments="?

        implement the Facelets as describe into the doc 12.5 Configuring faces-config.xml or 11.5.2. Handling Ajax Requests with Spring MVC + Spring Web Flow

        The goal is for re render a table <tr> tag when choosing a country

        For the moment with my code he render the full body of my tiles, and i loose the selected country but the languages are displayed.

        I hope that I'm clear in my explication

        Comment


        • #5
          Oops, right, the booking-mvc example doesn't implement the search functionality as a web flow, so no render actions are needed. The booking-faces sample does, and it uses render actions to re-render sections of the search results page when paging through a results list. This same functionality is demonstrated in booking mvc, but using stateless Spring MVC @Controllers with the render fragments specified client side. If you were to do this with web flow, you would not specify the fragments client side, but rather you would specify them when handling a web-flow event by executing a transition from a resuming view-state. The important thing to remember is the view-state should not exit the current state (no 'to' target on the transition), and in the case of JSP + TILES, the fragment needs to be the id of a tiles definition or attribute to render.

          Keith

          Comment


          • #6
            I'm having the same problem redering fragments


            I have a web-flow which needs to render a form that is over a flash app. I have a view template which holds the form and the validation message:

            <div id="busArrivesForm">
            <tiles:insertAttribute name="messages"/>
            <tiles:insertAttribute name="regBusForm"/>
            </div>


            view.xml

            <definition name="busArrives" template="/WEB-INF/registration/busArrives/busArrivesView.jsp">
            <put-attribute name="messages" value="/WEB-INF/registration/busArrives/messages.jsp" />
            <put-attribute name="regBusForm" value="/WEB-INF/registration/busArrives/reg1Form.jsp" />
            </definition>


            When i try to render only the message or form the whole page refreshes

            <transition on="submitForm">
            <render fragments="messages" />
            </transition>

            This is a very cool, interesting part of swf, I hope that it works. Am I doing something obviously wrong? Thanks in advance!

            Comment


            • #7
              Can you post your Spring MVC View Resolver configuration and your Web Flow configuration (not the web flow itself, but the webflow-config schema code)?

              Keith

              Comment


              • #8
                config files

                Thank you for the quick response Keith. Here are the webflow-config and the the springmvc-config. I hope this helps

                -------webflow-config.xml -------------------------------------------------------

                <?xml version="1.0" encoding="UTF-8"?>
                <beans xmlns="http://www.springframework.org/schema/beans"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:webflow="http://www.springframework.org/schema/webflow-config"
                xsi:schemaLocation="
                http://www.springframework.org/schema/beans
                http://www.springframework.org/schem...-beans-2.5.xsd
                http://www.springframework.org/schema/webflow-config
                http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">

                <webflow:flow-executor id="flowExecutor" />
                <!-- The registry of executable flow definitions -->
                <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF">
                <webflow:flow-location-pattern value="/**/*-flow.xml" />
                </webflow:flow-registry>

                <!-- Plugs in a custom creator for Web Flow views -->
                <webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" development="true"/>
                <bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.Mvc ViewFactoryCreator">
                <property name="viewResolvers" ref="tilesViewResolver"/>
                </bean>
                </beans>
                -------------------------------------------------------------------------------------

                ----webmvc-config.xml------------------------------------------------------------

                <?xml version="1.0" encoding="UTF-8"?>
                <beans xmlns="http://www.springframework.org/schema/beans"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="
                http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">



                <!-- Maps request paths to flows in the flowRegistry-->
                <bean class="org.springframework.webflow.mvc.servlet.Flo wHandlerMapping">
                <property name="flowRegistry" ref="flowRegistry"/>
                <property name="order" value="0"/>
                </bean>



                <!-- Maps request paths to @Controller classes; e.g. a path of /game looks for a controller named gameController -->
                <bean class="org.springframework.web.servlet.mvc.support .ControllerClassNameHandlerMapping">
                <property name="order" value="1" />
                <property name="defaultHandler">
                <!-- If no @Controller match, map path to a view to render; e.g. the "/intro" path would map to the view named "intro" -->
                <bean class="org.springframework.web.servlet.mvc.UrlFile nameViewController" />
                </property>
                </bean>

                <!-- Resolves logical view names returned by Controllers to Tiles; a view name to resolve is treated as the name of a tiles definition -->
                <bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedVie wResolver">
                <property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAj axTilesView"/>
                </bean>

                <!-- Configures the Tiles layout system -->
                <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2 .TilesConfigurer">
                <property name="definitions">
                <list>
                <value>/WEB-INF/layouts/layouts.xml</value>
                <value>/WEB-INF/registration/views.xml</value>
                <value>/WEB-INF/game/views.xml</value>
                <value>/WEB-INF/game/launch/views.xml</value>
                <value>/WEB-INF/game/postgame/views.xml</value>
                <value>/WEB-INF/invite/views.xml</value>
                <value>/WEB-INF/examplezzzz/views.xml</value>
                <value>/WEB-INF/registration/busArrives/views.xml</value>
                <value>/WEB-INF/registration/onBus/views.xml</value>
                <value>/WEB-INF/registration/arrived/views.xml</value>
                </list>
                </property>
                </bean>
                <!-- Dispatches requests mapped to flows to FlowHandler implementations -->
                <bean class="org.springframework.webflow.mvc.servlet.Flo wHandlerAdapter">
                <property name="flowExecutor" ref="flowExecutor"/>
                </bean>
                <!-- Dispatches requests mapped to POJO @Controllers implementations -->
                <bean class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter" />

                <!-- Dispatches requests mapped to org.springframework.web.servlet.mvc.Controller implementations -->
                <bean class="org.springframework.web.servlet.mvc.SimpleC ontrollerHandlerAdapter" />

                <bean class="org.springframework.context.annotation.Comm onAnnotationBeanPostProcessor"/>
                <!-- Custom FlowHandler for the game launch flow -->
                <bean name="game/launch" class="com.rebelmonkey.campfu.spring.LaunchFlowHan dler" />
                <!-- Custom FlowHandler for the game pregame flow -->
                <bean name="game" class="com.rebelmonkey.campfu.spring.PregameFlowHa ndler" />

                <!-- Custom FlowHandler for the game pregame flow -->
                <bean name="game/postgame" class="com.rebelmonkey.campfu.spring.PostgameFlowH andler" />
                <!-- Custom FlowHandler for the game registration flow -->
                <bean name="spring/registration" class="com.rebelmonkey.campfu.spring.RegistrationF lowHandler" />

                <bean name="registration/busArrives" class="com.rebelmonkey.campfu.spring.BusArrivesFlo wHandler" />
                <bean name="registration/onBus" class="com.rebelmonkey.campfu.spring.OnBusFlowHand ler" />
                <bean name="registration/arrived" class="com.rebelmonkey.campfu.spring.OnBusFlowHand ler" />

                <bean id="simpleRegistrationService" class="com.rebelmonkey.campfu.spring.SimpleRegistr ationService"/>
                <bean id="registration" class="com.rebelmonkey.campfu.spring.Registration"/>
                <bean id="gameModel" class="com.rebelmonkey.campfu.spring.Game"/>
                <bean id="gameService" class="com.rebelmonkey.campfu.spring.GameServiceIm pl"/>
                <bean id="emailInvite" class="com.rebelmonkey.campfu.spring.EmailInvite"/>

                </beans>
                -------------------------------------------------------------------------------------

                Comment


                • #9
                  Hi, Keith,

                  I had the same issue when use Spring MVC + SWF + tiles + jsp. Could you please let me know if this is still an issue for using Ajax + fragments? Or how to use a bypass way (I followed ths SWF instruction for using tiles + jsp, but now work).

                  Thanks.

                  Peter

                  Comment


                  • #10
                    Originally posted by Keith Donald View Post
                    ...The important thing to remember is the view-state should not exit the current state (no 'to' target on the transition)...
                    Hi Keith,

                    I'm using SWF 2.0.3, MyFaces, and Facelets, and after tinkering around I've been able to use SWF's ajax outside of the target view-state.

                    For example, I can render the fragments on-entry of the view-state, and have a sf:commandButton drive a transition to an action-state, which transitions back to the view-state, performing an ajax rendering of the fragments.

                    Or even better, I can take tell SWF to render the fragments in the transition of the action-state back to the view-state.

                    So it seems the actions to perform in an ajax call can be separated from the view-state to render.

                    But from the SWF documentation and your own quotes, it doesn't seem as if this approach was intended by the SWF team. If so, any particular reasons why? Is there something I'm overlooking? Some design decision which guided your team away from this kind of usage?

                    Comment


                    • #11
                      Its fine to set the render fragments attribute using a render action at any time during a flow execution. We figured its most common to set it when executing a transition from a view that does not change the current view.

                      Keith

                      Comment


                      • #12
                        Can I get SWF framgemtns example?

                        I have same issue.
                        Under SWF 2.0.8, Spring.add Decoration is work.
                        But <render fragments="body" /> does not work.
                        And <render fragments="transferList" /> does not work too.
                        "body" is tiles attribute name and "transferList" is div id, both does not work.

                        I reviewed booking-mvc example, but I can not found <render fragments=""/> case.
                        Can I get another executable SWF fragments (and popup) example?
                        Or are these configuration wrong? (attach files)

                        Comment

                        Working...
                        X