AR3Y35
AR3Y35

Reputation: 596

No mapping found for HTTP request with URI - JSF resource using Spring WebFlow

I'm trying to setup a web project using JSF (Primefaces 3.1.1) and Spring WebFow 2.3. I'm able to deploy and launch my index page but I noticed the p:commandButton doesn't seem to have the Primeface look and feel.

When I lauch the app I see these warnings on my IDE console:

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>

Upvotes: 1

Views: 6250

Answers (3)

rootkit
rootkit

Reputation: 2165

As it is stated in spring show case sample:

Enable processing of JSF 2 resource requests. For example:

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

Try adding this to your MVC config:

    <faces:resources/>

In some cases which multiple resources are declared it is necessary to use explicit order property as well. For example:

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

Upvotes: 2

Massimo
Massimo

Reputation: 1219

I solved this for my application

in WEB-INF/config/webmvc-config.xml set order 0 to mvc:resources

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

then in WEB-INF/config/webflow-config.xml change the order value of FlowHandlerMappin to something bigger:

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

this will suffice, but i suggest you also to remove ResourceServlet from web.xml, it's not needed anymore with mvc:resources

Upvotes: 0

maple_shaft
maple_shaft

Reputation: 10463

BalusC's comments are correct, however even if you follow his advice you will likely still run into a problem with Primefaces components not rendering properly. You have not mapped the Primefaces Resource Servlet in your web.xml.

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

This servlet name conflicts with the Servlet Name for your WebFlow resource servlet though so you need to resolve this name difference as well.

Upvotes: 0

Related Questions