Spring Web Flow

  • Themenstarter Themenstarter SpringWF
  • Beginndatum Beginndatum
S

SpringWF

Gast
Hallo zusammen,

ich habe in meine bestehende Webanwendung Spring Web Flow integriert, bzw. versuche es zumindest noch. Da die Anwendung bereits existiert, möchte ich diese "Flow" für "Flow" umstellen, d.h. also, ich möchte bspw. Anfragen, die mit .jsp enden, um SWF vorbei leiten und alle anderen Anfragen durch SWF "bearbeiten" lassen. Mein Menü besteht momentan aus mehreren Punkten, die auf eine JSP verlinken, die dann im Main-Frame geöffnet wird (ich weiß, Frames sind MEGA veraltet, wird deshalb auch bald umgestellt). Je nachdem, ist in dieser JSP auf weitere JSPs verlinkt. Nun habe ich vor, einzelne JSP-Folgen in SWF-Flows umzuschreiben und diese dann in die bestehende Anwendung integrieren. Dies kann ich allerdings nicht alles von heut auf morgen machen und möchte deshalb, dass bestehende Links auch weiterhin funktionieren. Bisher bekomme ich von Spring immer nur "Mapping"-Exception oder so ähnlich, weil er nunmal nicht weiß, wohin mit der Anfrage!
Welche Möglichkeiten hierfür wären aus eurer Sicht denkbar? Könntet ihr das Ganze evtl. auch an einem Beispiel erklären? Ich hoffe, ich habe mein Problem verständlich genug formuliert, ansonsten bitte ich um kurze Rückmeldung!
 
Hab bisher folgende Konfiguration:

web.xml:
[XML]
...
<!-- Initializing JavaServer Faces, *NOT* used at runtime due to Spring Web Flow -->
<!-- FacesServlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<!-- The servlet is loaded on startup to be reachable for requests. -->
<load-on-startup>1</load-on-startup>
</servlet>

<!-- Mapping for FacesServlet -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>


<!-- Initializing JBoss RichFaces -->
<!-- Plugging the "Blue Sky" skin into the project -->
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>

<!-- Making the RichFaces skin spread to standard HTML controls -->
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>

<!-- Defining and mapping the RichFaces filter -->
<filter>
<filter-name>RichFaces Filter</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>

<filter-mapping>
<filter-name>RichFaces Filter</filter-name>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>

<!-- Turn off the VDL viewhandler because of the limited JSF 2.0 support of RichFaces -->
<context-param>
<param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name>
<param-value>true</param-value>
</context-param>


<!-- Initializing Spring Web Flow -->
<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/web-application-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<!-- Map all /spring requests to the Dispatcher Servlet for handling -->
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/spring/*</url-pattern>
</servlet-mapping>
...
[/XML]

web-application-config.xml:
[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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Index of /schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<context:annotation-config />

<!-- Imports the configurations of the different infrastructure systems of the application -->
<import resource="webmvc-config.xml" />
<import resource="webflow-config.xml" />

</beans>
[/XML]

webmvc-config.xml:
[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">

<!-- Handles requests mapped to the Spring Web Flow system -->
<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
<property name="flowExecutor" ref="flowExecutor"/>
<!-- Integrates the ability to use RichFaces Ajax components -->
<property name="ajaxHandler">
<bean class="org.springframework.faces.richfaces.RichFacesAjaxHandler"/>
</property>
</bean>

<!-- Maps logical view names to JSF-Files (e.g. 'search' to '/search.jsp' -->
<!-- <bean id="jsfViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> -->
<bean id="jsfViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>

<!-- Maps request URIs to controllers -->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/*-flow=flowController
</value>
</property>
<property name="defaultHandler">
<!-- Selects view names to render based on the request URI: e.g. /main selects "main" -->
<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
</property>
</bean>

</beans>
[/XML]

webflow-config.xml:
[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"
xmlns:faces="http://www.springframework.org/schema/faces"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Index of /schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
Index of /schema/faces
http://www.springframework.org/schema/faces/spring-faces-2.0.xsd">

<!-- Executes flows: the central entry point into the Spring Web Flow system -->
<webflow:flow-executor id="flowExecutor" />

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

<!-- Configures the Spring Web Flow JSF integration -->
<faces:flow-builder-services id="facesFlowBuilderServices" />

</beans>
[/XML]

beispiel-flow.xml:
[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="Beispiel">
</view-state>

</flow>
[/XML]

Nun sucht er aber im Ordner, wo beispiel-flow.xml liegt nach einer Beispiel.xhtml obwohl ich JSPs mit ein paar JSF-Tags habe. Wo kann ich das anpassen? Hat das nicht was mit den [XML]faces:flow-builder-services[/XML] zu tun? Ist es auch möglich, den Pfad anzupassen, wo die View-States (JSPs) liegen (also nicht nur im Ordner, wo die Flow-Definition liegt)?

Auch würde ich gerne in der web.xml für das "Spring MVC Dispatcher Servlet"-Mapping sowas ähnliches angeben, wie "/*"! Allerdings bekomme ich bei Angabe von "/*" die Fehlermeldung, dass das Faces-Servlet kein "/*"-Mapping haben darf!?!? Hab's auch schon nur über "/" versucht, bekam dann aber eine Null-Pointer-Exception!
 
Durch ewiges rum probieren habe ich nun eine Konfiguration gefunden, die teilweise funktioniert, allerdings habe ich nun das Problem, dass wenn ich einen h:commandButton verwende, die definierte Transition nicht ausgeführt wird, stattdessen die Seite einfach neu aufgerufen wird. Habe ich einen Fehler in der Konfiguration oder auf der JSP-Seite?

Die Konfiguration íst bisher wie oben beschrieben, nur die webflow-config.xml hat sich wie folgt geändert:

[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"
xmlns:faces="http://www.springframework.org/schema/faces"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Index of /schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
Index of /schema/faces
http://www.springframework.org/schema/faces/spring-faces-2.0.xsd">

<!-- Executes flows: the central entry point into the Spring Web Flow system -->
<webflow:flow-executor id="flowExecutor" />

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

<!-- Handles requests mapped to the Spring Web Flow system -->
<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
<property name="flowExecutor" ref="flowExecutor"/>
<!-- Integrates the ability to use RichFaces Ajax components -->
<property name="ajaxHandler">
<bean class="org.springframework.faces.richfaces.RichFacesAjaxHandler"/>
</property>
</bean>

<!-- Configures the Spring Web Flow JSF integration -->
<webflow:flow-builder-services id="facesFlowBuilderServices" view-factory-creator="viewFactoryCreator"/>

<!-- Maps selected view identifiers to JSF-files specified by the defined jsfViewResolver -->
<bean id="viewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<property name="viewResolvers">
<list>
<ref bean="jsfViewResolver"/>
</list>
</property>
</bean>

</beans>
[/XML]

Meine JSP sieht wie folgt aus:
Java:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//DE">
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<!-- RichFaces tag library declaration -->
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
 

<HTML>
<HEAD>
<meta NAME="Author" content="$Author: wurst $  $Date: 2010-02-15 13:24:17 +0100 (Mo, 15 Feb 2010) $ $Revision: 50274 $">
<TITLE>Testseite</TITLE>
</HEAD>
<BODY>
<f:view>
<h:form>
  
  <a href="${flowExecutionUrl}&_eventId=test">Submit</a>
  
  <input type="submit" name="_eventId" value="test" />
  
  <h:commandButton action="_eventId:test" value="test" />

</h:form>
</f:view>
</BODY>
</HTML>

Der Link und der HTML-Button funktionieren einwandfrei, allerdings nicht der JSF-Button! An was könnte das liegen?

Bitte helft mir, ich bin schon fast am verzweifeln!
 

Zurück
Oben