Results 1 to 8 of 8

Thread: Spring Web Flow with JSF navigation

  1. #1

    Default Spring Web Flow with JSF navigation

    Hi,

    I'm writing a sample spring web flow (2.2.1) app with jsf2 as view technology. I guess I've got everything right in terms of configuration. However when I click on the "login" commandbutton of the jsf page, the flow does not go the next view (Welcome). Am I missing something ?

    main-flow.xml

    <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="Login">
    <transition on="login" to="Welcome" />
    <transition on="cancel" to="Cancel"/>
    </view-state>

    <end-state id="Welcome" />
    <end-state id="Cancel" />

    </flow>

    Login.xhtml

    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">

    <h:head><title>Spring Web flow with JSF</title></h:head>

    <h:body>
    <h5>Please login to continue</h5>
    <h:form>
    <hanelGrid columns="2">
    <h:outputText value="Username"/>
    <h:inputText value="#{loginBean.username}"/>

    <h:commandButton id="loginButton" action="login" value="Login" />
    <h:commandButton id="cancelButton" action="cancel" value="Cancel" />
    </hanelGrid>
    </h:form>
    </h:body>
    </html>

    Welcome.xhtml

    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">

    <h:body>
    Welcome to Spring Web flow with JSF, <h:outputText value="#{loginBean.username}"/>
    </h:body>

    </html>

    @Component("loginBean")
    public class LoginControllerBean implements Serializable {

    private String username;
    private String password;

    public String getUsername() {
    return username;
    }

    public void setUsername(String username) {
    this.username = username;
    System.out.println("Setting username to " + this.username);
    }

    public String getPassword() {
    return password;
    }

    public void setPassword(String password) {
    this.password = password;
    System.out.println("Setting password");
    }

    }

  2. #2
    Join Date
    Feb 2007
    Posts
    143

    Default

    Where did you define your "login" in <transition on="login" to="Welcome" />
    "login" is not defined in the loginbean which is your container for login.xhtml

    Vinaya

  3. #3

    Default

    login is the name of the action attribute of CommandButton in Login.xhtml. I got it working just now. I had to replace end-state with view-state and write a different end-state. With the previous flow, the end state was bringing up the Login state again.

    This is the new main-flow.xml:

    <view-state id="Login">
    <transition on="login" to="Welcome" />
    <transition on="cancel" to="Cancel"/>
    </view-state>

    <view-state id="Welcome">
    <transition on="thankYou" to="end"/>
    </view-state>

    <view-state id="Cancel">
    <transition on="noProblem" to="end"/>
    </view-state>

    <end-state id="end"/>

  4. #4
    Join Date
    Feb 2007
    Posts
    143

    Default

    I am trying to do something similar.
    I am not able to show the login page it self
    When I had login.xhtml out of webflow, everything worked fine. But I am not bale to start login page with webflow.
    Would you mind sharing your config files??

    Thanks
    Vinaya

  5. #5

    Default

    Hope you find these useful.

    web-application-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:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="

    http://www.springframework.org/schema/beans

    http://www.springframework.org/schem...-beans-2.5.xsd

    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">


    <!-- Activates annotation-based bean configuration -->
    <!-- context:annotation-config / -->

    <!-- Scans for application @Components to deploy -->
    <context:component-scan base-package="swf.workspace" />

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

    </beans>

    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"
    xmlns:faces="http://www.springframework.org/schema/faces"
    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/schem...config-2.0.xsd
    http://www.springframework.org/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">
    <webflow:flow-execution-listeners>
    <webflow:listener ref="facesContextListener" />
    </webflow:flow-execution-listeners>
    </webflow:flow-executor>

    <!-- The registry of executable flow definitions -->
    <webflow:flow-registry id="flowRegistry"
    flow-builder-services="flowBuilderServices" 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="flowBuilderServices" />

    <!-- A listener maintain one FacesContext instance per Web Flow request. -->
    <bean id="facesContextListener"
    class="org.springframework.faces.webflow.FlowFaces ContextLifecycleListener" />


    </beans>

    webmvc-config
    -----------------

    <?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:faces="http://www.springframework.org/schema/faces"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-2.5.xsd
    http://www.springframework.org/schema/faces
    http://www.springframework.org/schema/faces/spring-faces-2.0.xsd">

    <faces:resources />

    <!-- Maps request paths to flows in the flowRegistry;
    e.g. a path of /hotels/booking looks for a flow with id "hotels/booking" -->
    <bean class="org.springframework.webflow.mvc.servlet.Flo wHandlerMapping">
    <property name="order" value="1"/>
    <property name="flowRegistry" ref="flowRegistry" />
    <property name="defaultHandler">
    <!-- If no flow 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>

    <!-- Maps logical view names to Facelet templates in /WEB-INF
    (e.g. 'search' to '/WEB-INF/search.xhtml' -->
    <bean id="faceletsViewResolver" class="org.springframework.web.servlet.view.UrlBas edViewResolver">
    <property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
    <property name="prefix" value="/WEB-INF/" />
    <property name="suffix" value=".xhtml" />
    </bean>

    <bean class="org.springframework.faces.webflow.JsfFlowHa ndlerAdapter">
    <property name="flowExecutor" ref="flowExecutor" />
    </bean>

    </beans>

  6. #6
    Join Date
    Feb 2007
    Posts
    143

    Default

    Hi,

    I have the same configurations.
    I have the loginbean as

    Code:
    public class LoginBean implements AuthenticationManager, Serializable{
     private String username;
     private String password;
    public String getUsername() {
    	return username;
    }
    
    
    
    public void setUsername(String username) {
    	this.username = username;
    }
    
    public String getPassword() {
    	return password;
    }
    
    public void setPassword(String password) {
    	this.password = password;
    }
    
    public LoginBean() {
    	super();
    }	
    
    public void reset(){
    	this.username = null;
    	this.password = null;
    	
    }
    
    @Override
    public Authentication authenticate(Authentication authentication)
    		throws AuthenticationException {
    	
    	
    	
    	
    	System.out.println("In auhenticate :" + username + ":" + password);
    
    	return authentication;
    
    }
    My login.xhtml is

    Code:
      <table border="0" width="100%">
      	<tr>
        <td align="center" colspan="2"><img src="images/master_ui/logo.gif" /></td>
      </tr>
      <tr>
     		<td colspan="2" align="center">
     		 <h:messages style="font-size: 10px;	font-weight: bold;color: #E90649" id="messages"
    								layout="table" globalOnly="true" 
    								showDetail="true" />
    		</td>
    	</tr>
    	<tr>
    		<td align="center">
    								<font color="#0000CC" face="Arial, Helvetica, sans-serif" size="1.5">User Name:</font>
    							</td>
    							<td>
    							<h:inputText id="j_username" value="#{loginBean.username}" size="20" maxlength="80"></h:inputText>
    								
    							</td>
    	
    	</tr>
    	<tr>
    							<td align="center">
    							<font color="#0000CC" face="Arial, Helvetica, sans-serif" size="1.5">Password: </font>
    							</td>
    							<td>
    							<h:inputSecret id="j_password" 
    								value="#{loginBean.password}" size="20" maxlength="80"
    								redisplay="true" tabindex="0"></h:inputSecret>
    							</td>
    							</tr>
    							<tr>
    							<td colspan="2" align="center">
    							<h:commandButton action="j_spring_security_check"
    									value="Login" tabindex="0"/>
    							<h:commandButton value="Reset" action="reset" tabindex="0"/>
    							
    							</td>
    							</tr>
      </table>
    my login.xml is
    Code:
    	
    
    	<view-state id="login">
    		<transition on="authenticate" to="main" />
    		<transition on="reset" to=""/>
    		
    	</view-state>
    The authenticate action is not being called and the flow goes to main even though the authentication failed.

    Any ideas??

    Thanks
    Vinaya

  7. #7
    Join Date
    Feb 2007
    Posts
    143

    Default

    Hi Deepak,

    Would you mind posting your LoginController??

    Thanks
    Vinaya

  8. #8

    Default

    Good shot deepak,

    actually this is a bug spring webflow. in the end-state the view is not getting rendered. But the same would work when you use JSPs. That is obvious that we need to have a view in end-state.

    See in your workaround user have u invoke 'thankyou' action then only it reaches to end-state.

    see here: http://forum.springsource.org/showthread.php?t=56194

Tags for this Thread

Posting Permissions

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