使用JSF 2的Spring Web Flow - h:commandButton无效

时间:2012-04-01 19:32:23

标签: java spring spring-webflow

我目前正在使用Java Server Faces(Mojarra 2.1.7)和Spring(3.1.0.RELEASE)/ Spring-Webflow(2.3.1.RELEASE)。我的网络应用程序受到Spring-Primefaces-Showcase的启发。 除了事实之外,一切都工作正常,我无法从h:commandButton元素调用方法。一些示例代码(流程和视图定义):

view.xhtml:

<h:form>
  <h:inputText id="hello" value="${someBean.hello}"/>
  <h:commandButton value="Submit" action="execTest" />
</h:form>

flow.xml:

<var name="someBean" class="some.packagename.SomeBean"/>

<view-state id="view">
  <on-render>
    <evaluate expression="someBean.test()" />
  </on-render>
  <transition on="execTest">
    <evaluate expression="someBean.test()" />
  </transition>
</view-state>

这会产生一个InputField,填充正确的someBean.hello对应值(这只是一个字符串“hello”)和someBean.test()的单次执行(只是打印“test”到系统。出)。该按钮也被创建, 显示正确的文本“提交”,但是当用户点击它时没有执行someBean.test()被执行 显然这个问题与Bean无关,因为在渲染页面时表达式会被正确执行 什么会导致这种错误?
任何帮助将不胜感激!

的问候,
jeyp

我的一些完整性配置:
(Spring-Security没有访问限制)

弹簧webflow.xml:

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

  <!-- Executes flows: the central entry point into the Spring Web Flow system -->
  <flow-executor id="flowExecutor">
    <flow-execution-listeners>
      <listener ref="facesContextListener"/>
      <listener ref="securityListener"/>
    </flow-execution-listeners>
  </flow-executor>

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

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

  <!-- A listener to create and release a FacesContext -->
  <beans:bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>

  <!-- A listener to apply Spring Security authorities -->
  <beans:bean id="securityListener" class="org.springframework.webflow.security.SecurityFlowExecutionListener" />

</beans:beans>

servlet的context.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:webflow="http://www.springframework.org/schema/webflow-config"
  xmlns:faces="http://www.springframework.org/schema/faces"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/webflow-config
    http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd
    http://www.springframework.org/schema/faces
    http://www.springframework.org/schema/faces/spring-faces-2.2.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Imports user-defined @Controller beans that process client requests -->
    <beans:import resource="spring-webflow.xml" />

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Scan for Spring beans declared via annotations. -->
    <context:component-scan base-package="some.basepackage" />

    <tx:annotation-driven transaction-manager="transactionManager"/>

    <!-- Handles HTTP GET requests for /resources/** and /css/** by efficiently 
    serving up static resources in the ${webappRoot}/... directory -->
    <resources mapping="/resources/**" location="/resources/" />
    <resources mapping="/images/**" location="/images/" />
    <resources mapping="/css/**" location="/css/" />

    <!-- 
    Enable processing of JSF 2 resource requests. For example:
    /webflow-primefaces-showcase/app/javax.faces.resource/jsf.js?ln=javax.faces
  -->
  <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"
  -->
  <beans:bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    <beans:property name="flowRegistry" ref="flowRegistry" />
  </beans:bean>

    <!-- 
     Resolves views selected for rendering by @Controllers to .xhtml resources 
     in the /WEB-INF/views directory 
     -->
    <beans:bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
      <beans:property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".xhtml" />
    </beans:bean>

  <!--
    Dispatches requests mapped to flows to FlowHandler implementations
  -->
  <beans:bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">
    <beans:property name="flowExecutor" ref="flowExecutor" />
  </beans:bean>

</beans:beans>

的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

  <!-- 
    SPRING ROOT WEB APPLICATION CONTEXT
  -->

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
  </context-param>

  <!-- 
    SPRING SECURITY
  -->

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
      <filter-name>springSecurityFilterChain</filter-name>
      <servlet-name>Spring MVC Servlet</servlet-name>
    </filter-mapping>

   <filter>
     <filter-name>CharacterEncodingFilter</filter-name>
     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
     <init-param>
         <param-name>encoding</param-name>
         <param-value>UTF-8</param-value>
     </init-param>
     <init-param>
         <param-name>forceEncoding</param-name>
         <param-value>true</param-value>
     </init-param>
   </filter>

   <filter-mapping>
     <filter-name>CharacterEncodingFilter</filter-name>
     <url-pattern>/*</url-pattern>
   </filter-mapping>


  <!-- 
    JSF 2 IMPLEMENTATION
  -->

  <!-- Use JSF view templates saved as *.xhtml, for use with Facelets -->
  <context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
  </context-param>

  <!-- Enables special Facelets debug output during development -->
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
      <param-value>Development</param-value>
    </context-param>

    <!-- Causes Facelets to refresh templates during development -->
    <context-param>
      <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
      <param-value>1</param-value>
    </context-param>

  <!-- Just here so the JSF implementation can initialize, *not* used at runtime -->
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <!-- Just here so the JSF implementation can initialize -->
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
  </servlet-mapping>

  <!-- 
    SPRING MVC
  -->

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <servlet>
    <servlet-name>Spring MVC Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>Spring MVC Servlet</servlet-name>
    <url-pattern>/spring/*</url-pattern>
  </servlet-mapping>

    <!-- 
      Spring Security Facelets tag library declaration 
    -->
    <context-param>
      <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
      <param-value>/WEB-INF/spring_security.taglib.xml</param-value>
    </context-param>

  <!-- 
    DEFAULT PAGE
  -->

  <welcome-file-list>
    <welcome-file>/</welcome-file>
  </welcome-file-list>  

</web-app>

root-context.xml和spring-security.xml不包含重要的定义 对于这种情况。

0 个答案:

没有答案
相关问题