Link to home
Start Free TrialLog in
Avatar of chaitu chaitu
chaitu chaituFlag for India

asked on

how to execute spring webflow 1.0 version flows from jsp

When i click proceed link it will check the id(letterPrinting) mentioned in flow-config.xml and executed the flows(execute the first flow i.e.enterPersonalDetails) in printLetter.xml.

its working fine in spring web flow 2.0;

In spring web flow 1.0 id attribute was not there in printLetter.xml then how to execute the flows in 1.0 version when i click proceed link in jsp?



index.jsp
*********
 
 <body>
    <a href="app/letterPrinting">Proceed.</a> <br>
  </body>

  flow-config.xml
  ****************

  <webflow:flow-registry id="flowRegistry" base-path="/WEB-INF">
		<webflow:flow-location path="/flows/letterPrinting/printLetter.xml" id="letterPrinting" />
	</webflow:flow-registry>


printLetter.xml
***************

	<?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">



	<view-state id="enterPersonalDetails">
		<transition on="next" to="enterCustomMessage"/>
	</view-state>

	</flow>

Open in new window

Avatar of Mick Barry
Mick Barry
Flag of Australia image

> In spring web flow 1.0 id attribute was not there in printLetter.xml

sorry, don't understand what you mean. Can you explain?

http://static.springsource.org/spring-webflow/docs/1.0.x/reference/flow-definition.html
Avatar of chaitu chaitu

ASKER

web flow 1.0 version i am using.we cannot use id attribute in version 1.0 so how to execute flows from index.jsp..

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
Throwable occurred: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 26 in XML document from ServletContext resource [/flows/letterPrinting/printLetter.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute 'id' is not allowed to appear in element 'flow:location'.
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute 'id' is not allowed to appear in element 'flow:location'.

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:flow="http://www.springframework.org/schema/webflow-config"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/webflow-config
           http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.0.xsd">

<bean name="/*" class="org.springframework.webflow.executor.mvc.FlowController">
        <property name="flowExecutor" ref="flowExecutor" />
        <property name="defaultFlowId" value="/flows/letterPrinting/printLetter.xml" />
    </bean>

    <!-- Launches new flow executions and resumes existing executions. -->
    <flow:executor id="flowExecutor" registry-ref="flowRegistry">
        <flow:execution-attributes>
            <flow:alwaysRedirectOnPause value="false" />
        </flow:execution-attributes>
    </flow:executor>

    <!-- Creates the registry of flow definitions for this application -->
    <flow:registry id="flowRegistry">
        <flow:location path="/flows/letterPrinting/printLetter.xml"  id="main"/>
    </flow:registry>
	</beans>

Open in new window

I think it uses the filename as the id, in your case it would use 'printLetter'
now i changed hyper link action
index.jsp
*******

<a href="app/printLetter">Proceed</a>  

when i hit this

HTTP Status 404 - /app/printLetter
1.0 looks for the id as a parameter by default

Try adding a RequestPathFlowExecutorArgumentHandler to your controller


    <bean name="/*" class="org.springframework.webflow.executor.mvc.FlowController">
        <property name="flowExecutor" ref="flowExecutor"/>
        <property name="argumentHandler">
            <bean class="org.springframework.webflow.executor.support.RequestPathFlowExecutorArgumentHandler"/>
        </property>        
    </bean>

still same error.

index.jsp
********
<a href="/app/printLetter">Proceed</a>

flow-config.xml
*****************
  <bean name="/*" class="org.springframework.webflow.executor.mvc.FlowController">
        <property name="flowExecutor" ref="flowExecutor" />
           <property name="argumentHandler">
            <bean class="org.springframework.webflow.executor.support.RequestPathFlowExecutorArgumentHandler"/>
        </property> 
    </bean>

    <!-- Launches new flow executions and resumes existing executions. -->
    <flow:executor id="flowExecutor" registry-ref="flowRegistry">
        <flow:execution-attributes>
            <flow:alwaysRedirectOnPause value="false" />
        </flow:execution-attributes>
    </flow:executor>

    <!-- Creates the registry of flow definitions for this application -->
    <flow:registry id="flowRegistry">
        <flow:location path="/flows/letterPrinting/printLetter.xml" />
    </flow:registry>

Open in new window

Can you check your path ....

path="/WEB-INF//flows/letterPrinting/printLetter.xml"   try this ...
>   <bean name="/*" class="org.springframework.webflow.executor.mvc.FlowController">

try mapping it to a specific path instead of the wildcard
in which jar this class wil be located?i need spring webflow 1.0 version combatability jars..

am getting following error now.

java.lang.ClassNotFoundException: org.springframework.context.event.SourceFilteringListener
what did you change?
>            http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

think you need to use spring 1.x
changed to specific path  after that i am getting this exception.

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:flow="http://www.springframework.org/schema/webflow-config"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/webflow-config
           http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.0.xsd">


    <bean name="/app/" class="org.springframework.webflow.executor.mvc.FlowController">
        <property name="flowExecutor" ref="flowExecutor" />
        <property name="defaultFlowId" value="/flows/letterPrinting/printLetter.xml" />
       
    </bean>
</beans>
> changed to specific path  after that i am getting this exception.

great, that would suggest you're getting closer.

Did you see my previous comment? You need to make sure all your jar are comparible as well.
Migrating from 2.x to 1.x isn't trivial btw, there are quite a few changes between versions.
now i am getting this error.

SEVERE: Servlet.service() for servlet spring threw exception
org.springframework.webflow.definition.registry.NoSuchFlowDefinitionException: No such flow definition with id '/WEB-INF/flows/letterPrinting/printLetter.xml' found; the flows available are: array<String>['printLetter']

index.jsp
**********
<a href="app/printLetter">Proceed</a>  

web.xml
*********
   <servlet>
		         <servlet-name>spring</servlet-name> 
		         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
		   </servlet>
		    <servlet-mapping> 
		    <servlet-name>spring</servlet-name>
			<url-pattern>/app/*</url-pattern>
		    </servlet-mapping> 

Open in new window

where is printLetter.xml?
in this path(/WEB-INF/flows/letterPrinting/printLetter.xml.
) only.same code has worked in spring 2.0 version because we have id attribute in 2.0 so spring is able to identify if i hit with app/letterPrinting.but in 1.0 version how to execute these flows i am not able to understand.



<webflow:flow-registry id="flowRegistry" base-path="/WEB-INF">
            <webflow:flow-location path="/flows/letterPrinting/printLetter.xml" id="letterPrinting" />
      </webflow:flow-registry>


see my earlier comment regards id's
i am facing another problem now.

am executing flow like this.when i click proceed link its going to sample.jsp.but in this jsp ${flowExecutionUrl} is not coming.where am i missing??


http://localhost:8080/&event_Id=proceed.

its framing like this..


below jars hav placed in classpath.
commons-logging-1.0.4.jar
jdom-1.0.jar
ognl-2.6.11.jar
spring-2.0.2.jar
spring-mock-1.1.3.jar
spring-webflow-1.0.5.jar


index.jsp
***********

<a href="app?_flowId=sample-flow">Proceed</a>  

sample.jsp
*************


<%@ page isELIgnored="false" %>

<html>
<head>
<title>Insert title here</title>
</head>
<body>
<form id="frm">
<a href='${flowExecutionUrl}&_eventId=proceed'>Proceed-sample</a>
</form>
</body>
</html>

web.xml
********
   <servlet>
		         <servlet-name>spring</servlet-name> 
		         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
		   </servlet>
		    <servlet-mapping> 
		    <servlet-name>spring</servlet-name>
			<url-pattern>/app/*</url-pattern>
		    </servlet-mapping> 

webflow-confi.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:flow="http://www.springframework.org/schema/webflow-config"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/webflow-config
           http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.0.xsd">


    <bean name="/*" class="org.springframework.webflow.executor.mvc.FlowController">
        <property name="flowExecutor" ref="flowExecutor" />
     </bean>

    <!-- Launches new flow executions and resumes existing executions. -->
    <flow:executor id="flowExecutor" registry-ref="flowRegistry">
        <flow:execution-attributes>
            <flow:alwaysRedirectOnPause value="false" />
        </flow:execution-attributes>
    </flow:executor>

    <!-- Creates the registry of flow definitions for this application -->
    <flow:registry id="flowRegistry">
        <flow:location path="/WEB-INF/**-flow.xml" />
    </flow:registry>

	<bean id="saveAction" class="com.actions.SaveAction">
    </bean>

</beans>

sample-flow.XML
*******************
<?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-1.0.xsd">


    <start-state idref="example" />
    
    <view-state id="example" view="sample">
		<transition on="proceed" to="save"/>
	</view-state>
	
	 <action-state id="save"> 
        <action bean="saveAction" method="generateCode" />
        <transition on="success" to="thanku" /> 
        </action-state>
        
        
        <view-state id="thanku" view='thanku'/> 

</flow>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
so in 1.0 instead of flowExecutionUrl what should i use??
don't know you may have to construct the url manually
i found out the solution.

you should use _flowExecutionKey=${flowExecutionKey} in spring 1.x