使用SpringWebFlow找不到URI为JSF资源的HTTP请求的映射



我正在尝试使用JSF(Primefaces 3.1.1)和Spring WebFow 2.3来设置一个web项目。我可以部署和启动我的索引页面,但我注意到p:commandButton似乎没有Primeface的外观。

当我启动应用程序时,我在IDE控制台上看到以下警告:

WARNING: No mapping found for HTTP request with URI [/client-ui/contact/javax.faces.resource/primefaces.css] in DispatcherServlet with name 'DispatcherMVC'
WARNING: No mapping found for HTTP request with URI [/client-ui/contact/javax.faces.resource/theme.css] in DispatcherServlet with name 'DispatcherMVC'
WARNING: No mapping found for HTTP request with URI [/client-ui/contact/javax.faces.resource/primefaces.js] in DispatcherServlet with name 'DispatcherMVC'
WARNING: No mapping found for HTTP request with URI [/client-ui/contact/javax.faces.resource/jquery/jquery.js] in DispatcherServlet with name 'DispatcherMVC'

WEB-INF/WEB.xml

<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                         "http://java.sun.com/dtd/web-app_3_0.xsd">
<web-app>
    <display-name>Buttery Bees web client ui</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/*-context.xml</param-value>
    </context-param>   
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet> 
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>DispatcherMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/config/webmvc-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>Resources Servlet</servlet-name>
        <servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>  
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>  
    <servlet-mapping>
        <servlet-name>DispatcherMVC</servlet-name>
        <url-pattern>/contact/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Resources Servlet</servlet-name>
        <url-pattern>/resources/*</url-pattern>
    </servlet-mapping>    
    <welcome-file-list>
        <welcome-file>/index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

WEB-INF/config/webmvc-config.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
    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-3.0.xsd     
                        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd     
                        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <mvc:annotation-driven/>
    <context:component-scan base-package="com.bb.ui.controller" />
    <mvc:resources location="/WEB-INF/web-content/" mapping="/WEB-INF/web-content/**"/>
    <bean id="facesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
        <property name="prefix" value="/WEB-INF/web-content/pages/" />
        <property name="suffix" value=".xhtml" />
    </bean> 
    <import resource="webflow-config.xml" />    
</beans>

WEB-INF/config/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:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/webflow-config 
                        http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">
    <!--Maps request paths to flows in the flowRegistry--> 
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"> 
        <property name="order" value="0" /> 
        <property name="flowRegistry" ref="flowRegistry" /> 
    </bean>
    <!-- Dispatches requests mapped to flows to FlowHandler implementations -->
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
        <property name="flowExecutor" ref="flowExecutor" />
    </bean>
    <!-- Executes flows: the 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="flowBuilderServices" base-path="/WEB-INF/flows">
        <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.MvcViewFactoryCreator">
        <property name="viewResolvers" ref="facesViewResolver" />
    </bean>
</beans>

WEB-INF/WEB content/pages/index.xhtml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:p="http://primefaces.org/ui">
<h:head>

</h:head>
<h:body>
    <h:form>
        <p:panel>
            <p:commandButton value="Primeface Button"/>
            something
        </p:panel>
    </h:form>
</h:body>
</html>

HomeController.java

package com.bb.ui.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping ("/contact")
public class HomeController {
    @RequestMapping ("/contact")
    public String home() {
        return "index";
    }
}

webapp/index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=contact">
</head>
</html>

正如春季展示案例示例中所述:

启用JSF 2资源请求的处理。例如:

/webflow primefaces showcase/app/javax.faces.resource/jsf.js?ln=javax.faces

尝试将其添加到MVC配置中:

    <faces:resources/>

在声明了多个资源的某些情况下,也有必要使用显式顺序属性。例如:

    <mvc:resources mapping="/resources/**" location="/"/>
    <faces:resources order="-1"/>

BalusC的评论是正确的,但即使你听从他的建议,你仍然可能遇到Primefaces组件渲染不正确的问题。您尚未在web.xml中映射Primefaces资源Servlet。

<servlet>
  <servlet-name>Resource Servlet</servlet-name>
  <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>Resource Servlet</servlet-name>
  <url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping>

不过,这个servlet名称与WebFlow资源servlet的servlet名称冲突,因此您也需要解决这个名称差异。

我为我的应用程序解决了这个问题

WEB-INF/config/webmvc config.xml中将顺序0设置为mvc:resources

<mvc:resources order="0" location="/WEB-INF/web-content/" mapping="/WEB-INF/web-content/**"/>

然后在WEB-INF/config/webflow config.xml中将FlowHandlerMapin的顺序值更改为更大的值:

<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"> 
    <property name="order" value="2" /> 
    <property name="flowRegistry" ref="flowRegistry" /> 
</bean>

这就足够了,但我建议您也从web.xml中删除ResourceServlet,mvc不再需要它:resources

最新更新