Spring mvc + JSF on GAE - spring

I have a problem with implementing spring mvc + primeFaces on GAE, i think that all works fine except when i try to modify values of my bean by sending post, values remain the same as before. Here is code:
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/main-servlet.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.enableThreading</param-name>
<param-value>false</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>
<listener>
<listener-class>
com.remote.control.web.ApiKeyInitializer
</listener-class>
</listener>
<servlet>
<servlet-name>main</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>main</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<url-pattern>/home</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value/>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
</web-app>
main-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<context:component-scan base-package="com.remote.control.controller" />
<context:component-scan base-package="com.remote.control.service" />
<mvc:annotation-driven />
<mvc:resources mapping="/res/**" location="/WEB-INF/res/" />
<bean
id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property
name="prefix"
value="/WEB-INF/jsp/" />
<property
name="suffix"
value=".xhtml" />
</bean>
</beans>
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config >
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
HomeController.java
#Controller
public class HomeController {
private Logger logger = Logger.getLogger(getClass().getName());
#Autowired
Bean bean;
#RequestMapping(value="/home", method=RequestMethod.GET)
public ModelAndView homeGet() {
ModelAndView mv=new ModelAndView("index");
bean.setParam1("111111111");
bean.setParam2("22222222222");
bean.setParam3("3333333333");
mv.addObject("task",bean);
return mv;
}
#RequestMapping(value="/home", method=RequestMethod.POST)
public ModelAndView homePost() {
ModelAndView mv=new ModelAndView("index");
logger.warning("param1"+ bean.getParam1());
logger.warning("param2" + bean.getParam2());
logger.warning("param3" + bean.getParam3());
mv.addObject("task",bean);
}
}
Bean.java
#Component
#Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)
public class Bean implements Serializable {
private String param1;
private String param2;
private String param3;
public String getParam1() {
return param1;
}
public void setParam1(String param1) {
this.param1 = param1;
}
public String getParam2() {
return param2;
}
public void setParam2(String param2) {
this.param2 = param2;
}
public String getParam3() {
return param3;
}
public void setParam3(String param3) {
this.param3 = param3;
}
}
index.xhtml
<html>
<ui:composition template="baseLayout.xhtml">
<ui:define name="content">
<form action="home" method="post">
<h:panelGrid style="margin-top:20px;" columns="2" cellpadding="10">
<p:outputPanel autoUpdate="true">
<p:inputText value="#{task.param1}" />
<p:inputText value="#{task.param2}" />
<p:inputTextarea value="#{task.param3}" id="text" rows="10" cols="50" />
</p:outputPanel>
</h:panelGrid>
<button value="submit" />
</form>
</ui:define>
</ui:composition>
</html>

Just turn
<form action="home" method="post">
<h:panelGrid style="margin-top:20px;" columns="2" cellpadding="10">
<p:outputPanel autoUpdate="true">
<p:inputText value="#{task.param1}" />
<p:inputText value="#{task.param2}" />
<p:inputTextarea value="#{task.param3}" id="text" rows="10" cols="50" />
</p:outputPanel>
</h:panelGrid>
<button value="submit" />
</form>
Into
<h:form>
<h:panelGrid style="margin-top:20px;" columns="2" cellpadding="10">
<p:outputPanel autoUpdate="true">
<p:inputText value="#{task.param1}" />
<p:inputText value="#{task.param2}" />
<p:inputTextarea value="#{task.param3}" id="text" rows="10" cols="50" />
</p:outputPanel>
</h:panelGrid>
<p:commandButton value="submit" action="#{task.myMethod}"/>
</h:form>
with the following method
public void myMethod(){
System.out.println(param1);
System.out.println(param2);
System.out.println(param3);
}

Related

jsf commandButton managedBean action redirect to 404 page

I have my ManagedBean
TodoService.java
package com.medkhelifi.tutorials.todolist.services;
import com.medkhelifi.tutorials.todolist.models.dao.ITodoDao;
import com.medkhelifi.tutorials.todolist.models.entities.Todo;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
#ManagedBean
#RequestScoped
public class TodoService implements ITodoService {
#ManagedProperty(value = "ITodoDao")
private ITodoDao ITodoDao;
#Override
public void addTodo(Todo todo) {
ITodoDao.addTodo(todo);
}
public void setITodoDao(ITodoDao ITodoDao) {
this.ITodoDao = ITodoDao;
}
}
And I have my form to add new data
index.xhtml
<!-- extra code coes here -->
<b:column colMd="6">
<div class="todolist not-done">
<h1>Todos</h1>
<h:form>
<b:inputText type="text" class="form-control add-todo" placeholder="Todo Title"/>
<b:inputTextarea type="text" placeholder="Description" />
<b:dateTimePicker placeholder="todo Date" format="YYYY-MM-DD HH:mm:ss"/>
<h:commandButton action="#{todoService.addTodo(null)}" class="btn btn-success" value="Add"/>
</h:form>
<hr/>
<ul class="list-unstyled" >
<ui:repeat value="#{TodoDao.getCurrentUserTodos()}" var="todo" >
<h:panelGroup rendered="#{!todo.done}">
<li class="ui-state-default">
<div class="checkbox">
<label><input type="checkbox" value="" />#{todo.title}</label>
</div>
</li>
</h:panelGroup>
</ui:repeat>
</ul>
<div class="todo-footer">
<strong><span class="count-todos"/></strong> Items Left
</div>
</div>
</b:column>
<!-- extra code coes here -->
When I perform my add button I'm redirected to the same page with 404 status.
There is my web.xml
<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- DEFINE APPLICATION ENVIRONMENT -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- DEFINE JSF SERVLET MAPPING -->
<servlet>
<servlet-name>FACES SERVLET</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FACES SERVLET</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<!-- DEFINE WELCOME PAGE -->
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<!-- SPRING SERVLETS -->
<servlet>
<servlet-name>dispatcher-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/conf/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher-servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- SPRING CONTEXT -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:conf/applicationContext.xml</param-value>
</context-param>
<!-- SPRING SECURITY FILTER -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<!-- Add this dispatcher to handle /j_spring_security_check url -->
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
</web-app>
I use also Spring security:
applicationContext-security.xml
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="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-4.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.0.xsd">
<http auto-config="true">
<intercept-url pattern="/login*" access="permitAll()"/>
<intercept-url pattern="/javax.faces.resource/**" access="permitAll()"/>
<intercept-url pattern="/**" access="isAuthenticated()" />
<!-- access denied page -->
<access-denied-handler error-page="/403" />
<form-login
login-page="/login.xhtml"
default-target-url="/index.xhtml"
authentication-failure-url="/login.xhtml?error"
login-processing-url="/j_spring_security_check"
username-parameter="input_username"
password-parameter="input_password" />
<logout
logout-success-url="/login.xhtml"
/>
<!-- enable csrf protection -->
<csrf />
</http>
<authentication-manager>
<authentication-provider user-service-ref="myUserDetailsService">
<password-encoder hash="bcrypt"/>
</authentication-provider>
</authentication-manager>
</beans:beans>
And when I debug, the method TodoService.addTodo is never called, I hope I explained my problem well.
There is my stack:
Spring 4.2.2-Final
JSF 2.2.17
After few hours of searching I found the issue:
I missed to add csrf security hidden input to my form since I use csrf protection in my Spring security.
index.xhtml
<!-- extra code coes here -->
<b:column colMd="6">
<div class="todolist not-done">
<h1>Todos</h1>
<h:form>
<b:inputText type="text" class="form-control add-todo" placeholder="Todo Title"/>
<b:inputTextarea type="text" placeholder="Description" />
<b:dateTimePicker placeholder="todo Date" format="YYYY-MM-DD HH:mm:ss"/>
<!-- I missed to add this line -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<h:commandButton action="#{todoService.addTodo(null)}" class="btn btn-success" value="Add"/>
</h:form>
<hr/>
<ul class="list-unstyled" >
<ui:repeat value="#{TodoDao.getCurrentUserTodos()}" var="todo" >
<h:panelGroup rendered="#{!todo.done}">
<li class="ui-state-default">
<div class="checkbox">
<label><input type="checkbox" value="" />#{todo.title}</label>
</div>
</li>
</h:panelGroup>
</ui:repeat>
</ul>
<div class="todo-footer">
<strong><span class="count-todos"/></strong> Items Left
</div>
</div>
</b:column>
<!-- extra code coes here -->

primefaces treetable expand not working if jsf page location is changed

Primefaces treetable expands if my xhtml webpage is in WebContent Folder but it doesn't expand if I move the same webpage to WEB-INF/views/jsf folder. I'm very new to JSF and I don't know where and what to change.
If my webpage is in WEB-INF/views/jsf folder only the root node is visible. It's not expanding if I click it.
HTML Code
<?xml version="1.0" encoding="UTF-8" ?>
<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>
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="IE=9" />
</f:facet>
</h:head>
<h:body class="page">
<h:outputStylesheet name="philos.css" />
<h:outputStylesheet name="primefaces.css" />
<h:form>
<p:treeTable value="#{treeView.newRoot}" var="document" id="treeTable" >
<p:column headerText="Name">
<h:outputText value="#{document.name}" />
</p:column>
<p:column headerText="Size">
<h:outputText value="#{document.size}" />
</p:column>
<p:column headerText="Type">
<h:outputText value="#{document.type}" />
</p:column>
</p:treeTable>
</h:form>
</h:body>
</html>
Managed Bean
package com.maintechnicalframework.sa.controller;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.servlet.http.HttpServletRequest;
import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import com.maintechnicalframework.common.constants.MainConstants;
import com.maintechnicalframework.common.controller.MainController;
import com.maintechnicalframework.common.model.LoginUserDetails;
import com.maintechnicalframework.sa.contants.SystemAttributeConstants;
import com.maintechnicalframework.sa.model.Document;
import com.maintechnicalframework.sa.service.SystemAttributeService;
import com.maintechnicalframework.sa.validator.SystemAttributeValidator;
#Controller
#RequestMapping("/faces")
#ManagedBean(name="treeView")
#ViewScoped
#SessionAttributes({ MainConstants.CURRENT_INSTANCE, MainConstants.LOGIN_USER_DETAILS, MainConstants.REQUEST_PARAM} )
public class SystemAttributeManagedBean extends MainController implements Serializable{
#Autowired
private SystemAttributeService systemAttributeService;
#Autowired
private SystemAttributeValidator systemAttributeValidator;
private List<String> sampleList = new ArrayList<String>();
#RequestMapping("/showTree")
public String showTree( HttpServletRequest httpRequest, ModelMap model ){
MainError.clearErrors();
model.put(MainConstants.ERROR_OBJ, mainError);
validateSSO(model, systemAttributeValidator, true );
if( loginUserDetails == null ){
model.addAttribute( MainConstants.INVALID_INFO, MainConstants.INVALID_SSO_INFO );
return MainConstants.INVALID_SSO_PAGE;
}else{
return SystemAttributeConstants.EDIT_TREE;
}
}
private TreeNode root;
TreeNode newRoot;
private Document selectedDocument;
#PostConstruct
public void init() {
createDocuments();
}
public TreeNode createDocuments() {
newRoot = new DefaultTreeNode(new Document("Files", "-", "Folder"), null);
TreeNode documents = new DefaultTreeNode(new Document("Documents", "-", "Folder"), newRoot);
TreeNode pictures = new DefaultTreeNode(new Document("Pictures", "-", "Folder"), newRoot);
TreeNode movies = new DefaultTreeNode(new Document("Movies", "-", "Folder"), newRoot);
TreeNode work = new DefaultTreeNode(new Document("Work", "-", "Folder"), documents);
TreeNode primefaces = new DefaultTreeNode(new Document("PrimeFaces", "-", "Folder"), documents);
//Documents
TreeNode expenses = new DefaultTreeNode("document", new Document("Expenses.doc", "30 KB", "Word Document"), work);
TreeNode resume = new DefaultTreeNode("document", new Document("Resume.doc", "10 KB", "Word Document"), work);
TreeNode refdoc = new DefaultTreeNode("document", new Document("RefDoc.pages", "40 KB", "Pages Document"), primefaces);
//Pictures
TreeNode barca = new DefaultTreeNode("picture", new Document("barcelona.jpg", "30 KB", "JPEG Image"), pictures);
TreeNode primelogo = new DefaultTreeNode("picture", new Document("logo.jpg", "45 KB", "JPEG Image"), pictures);
TreeNode optimus = new DefaultTreeNode("picture", new Document("optimusprime.png", "96 KB", "PNG Image"), pictures);
//Movies
TreeNode pacino = new DefaultTreeNode(new Document("Al Pacino", "-", "Folder"), movies);
TreeNode deniro = new DefaultTreeNode(new Document("Robert De Niro", "-", "Folder"), movies);
TreeNode scarface = new DefaultTreeNode("mp3", new Document("Scarface", "15 GB", "Movie File"), pacino);
TreeNode carlitosWay = new DefaultTreeNode("mp3", new Document("Carlitos' Way", "24 GB", "Movie File"), pacino);
TreeNode goodfellas = new DefaultTreeNode("mp3", new Document("Goodfellas", "23 GB", "Movie File"), deniro);
TreeNode untouchables = new DefaultTreeNode("mp3", new Document("Untouchables", "17 GB", "Movie File"), deniro);
return newRoot;
}
public TreeNode getNewRoot() {
return newRoot;
}
public TreeNode getRoot() {
return root;
}
public List<String> getListOfString(){
LoginUserDetails loginUserDetails = (LoginUserDetails)getSessionObj(MainConstants.LOGIN_USER_DETAILS);
sampleList.add("One");sampleList.add("Two");sampleList.add("Three");sampleList.add("Four");
return sampleList;
}
/* public void actionHandler(ActionEvent event)throws Exception{
System.out.println("Jjjj");
}*/
public Document getSelectedDocument() {
return selectedDocument;
}
public void setSelectedDocument(Document selectedDocument) {
this.selectedDocument = selectedDocument;
}
}
My -servlet.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
">
<!-- Enable annotation driven controllers, validation etc... -->
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"/>
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<!-- Turn off working out content type based on URL file extension, should fall back to looking at the Accept headers -->
<property name="favorPathExtension" value="false" />
</bean>
<context:annotation-config />
<context:component-scan base-package = "com.mycompany.ondemand,com.oracle.ondemand.crm,com.maintechnicalframework"/>
<context:property-placeholder location="/WEB-INF/properties/config.properties"/>
<bean id="applicationContextProvider" class="com.oracle.ondemand.crm.framework.context.ApplicationContextProvider"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
</bean>
<mvc:interceptors>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" depends-on="localeMap">
<property name="paramName" value="language" />
<property name="localeMap" ref="localeMap" />
</bean>
</mvc:interceptors>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<!-- <property name="basename" value="file:/C:/XXXXX/messages" /> -->
<property name="basename" value="classpath:messages" />
<property name="fallbackToSystemLocale" value="false"/>
<property name="defaultEncoding" value="UTF-8"/>
</bean>
</beans>
Web.xml
<web-app 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"
version="3.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/*-Config.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<filter>
<filter-name>SetCharacterEncodingFilter</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>SetCharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- CERT Implementation START -->
<filter>
<filter-name>csrfFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>csrfFilter</filter-name>
<url-pattern>/mycompany/*</url-pattern>
</filter-mapping>
<!-- CERT Implementation END -->
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<display-name>systemAttribute</display-name>
<servlet>
<servlet-name>systemAttribute</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>systemAttribute</servlet-name>
<url-pattern>/mycompany/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<!-- CERT Implementation START -->
<error-page>
<error-code>403</error-code>
<location>/unauthorizedPage.jsp</location>
</error-page>
<!-- CERT Implementation END -->
</web-app>
I also had this issue. I did resolve with steps below:
Step 1: move your XHTML files into webcontent folder.
Step 2: Since all the files in webcontent are allowed for public access, you need to add the below entry in web.xml for security reason.
Please follow the link for security restrictions:
Prevent direct access to composite components by placing them inside /WEB-INF

Spring MVC POST not supportet

i wan't to configure spring mvc via UrlBasedViewResolver in an existing webflow, JSF- Primefaces project cause i need clean URLs. Unfortunately my SearchForm get an
WARN PageNotFound:183 - Request method 'POST' not supported
warn if it fires ajax or action.
In case of form action the associated method in my #ManagedBean dont get called.
Now, I ask you to help...
web.xml
<display-name>My Transport</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:res/conf/applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFSULT_SUFFIX</param-name>
<param-value>.xhtml.xml</param-value>
</context-param>
<context-param>
<param-name>faceslets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_RESOLVER_REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>hot-sneaks</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>Resources Servlet</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter>
<filter-name>NoSessionIdFilter</filter-name>
<filter-class>dev.le.tools.servlet.filter.SessionIdFromUrlRemoveFilter</filter-class>
</filter>
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter>
<filter-name>requestContextFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<!-- Spring security filters -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
<filter-name>charEncodingFilter</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>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>mvc-dispatcher</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>charEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>NoSessionIdFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>requestContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
applicationContext.xml
<context:annotation-config />
<context:component-scan base-package="de************" />
<context:component-scan base-package="de************" />
<import resource="datasource-config.xml" />
<import resource="webflow-config.xml" />
<import resource="security-config.xml" />
<mvc:annotation-driven />
<mvc:resources location="/WEB-INF/views/" mapping="/WEB-INF/views/**"/>
<bean id="defaultServletHttpRequestHandler"
class="org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler" />
<bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" />
<!-- JSF for representation layer. All JSF files under /WEB-INF/views directory -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="cache" value="false" />
<property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".xhtml" />
</bean>
<bean id="userAuthenticationProvider" class="de.wiegand.mytransport.services.impl.UserAuthenticationProvider">
<property name="authenticationManager" ref="authenticationManager" />
</bean>
webflow-config.xml
<bean id="jpaFlowExecutionListener"
class="org.springframework.webflow.persistence.HibernateFlowExecutionListener">
<constructor-arg ref="sessionFactory" />
<constructor-arg ref="transactionManager" />
</bean>
<bean id="facesContextListener"
class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener" />
<webflow:flow-executor id="flowExecutor">
<webflow:flow-execution-repository
max-executions="0" />
<webflow:flow-execution-listeners>
<webflow:listener ref="facesContextListener" />
<webflow:listener ref="securityFlowExecutionListener" />
</webflow:flow-execution-listeners>
</webflow:flow-executor>
<webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices" base-path="/WEB-INF/flows">
<webflow:flow-location-pattern value="/**/*-flow.xml" />
</webflow:flow-registry>
<faces:flow-builder-services id="facesFlowBuilderServices"
development="true" />
<faces:resources />
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="order" value="0" />
<property name="flowRegistry" ref="flowRegistry" />
<property name="flowUrlHandler">
<bean class="de.wiegand.mytransport.ui.util.PrettyFlowUrlHandler" />
</property>
</bean>
<bean id="faceletsViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<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.JsfFlowHandlerAdapter">
<property name="flowUrlHandler">
<bean class="de.wiegand.mytransport.ui.util.PrettyFlowUrlHandler" />
</property>
<property name="flowExecutor" ref="flowExecutor" />
</bean>
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
<property name="flowUrlHandler">
<bean class="de.wiegand.mytransport.ui.util.PrettyFlowUrlHandler" />
</property>
<property name="flowExecutor" ref="flowExecutor" />
</bean>
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<bean id="securityFlowExecutionListener"
class="org.springframework.webflow.security.SecurityFlowExecutionListener" />
search.xhtml
<p:fieldset styleClass="fieldset_search" legend="Fahrt suchen">
<h:form id="searchTripForm">
<p:focus />
<h:panelGrid id="searchPanelGrid"
style="margin: 0 auto; margin-top: 25px; text-align: right"
cellspacing="8" columns="3">
<h:panelGroup>
<h:outputText value="Von:" />
<h:outputText style="color:red" value="* " />
</h:panelGroup>
<p:autoComplete id="origin_autocomplete" minQueryLength="3"
rendered="#{empty searchBean.notUniqueOrigins}"
forceSelection="false" queryDelay="300" maxResults="5"
placeholder="PLZ, Stadt oder Statdtteil" charset="UTF-8"
value="#{searchBean.originDisplayNameAndClearGeoLocation}"
required="true" label="Von" title="Absendeadresse eingeben"
tabindex="false"
completeMethod="#{geoNamesService.getGeoNamesByInput}" />
<h:panelGrid rendered="#{!empty searchBean.notUniqueOrigins}"
columns="1">
<h:selectOneMenu
value="#{searchBean.selectedNotUniqueOriginId}"
style="width:200px;" onchange="submit()"
valueChangeListener="#{searchBean.changeSelectedOrigin}">
<f:selectItems value="#{searchBean.notUniqueOrigins}"
var="origin" itemLabel="#{origin.name}, #{origin.zipcode}"
itemValue="#{origin.id}" />
</h:selectOneMenu>
<p:commandLink id="resetOriginToInput" style="margin-right:20px;"
immediate="true" ajax="false" action="resetOriginToInput">
<h:outputText value="zurücksetzen" />
</p:commandLink>
</h:panelGrid>
<h:panelGroup>
<p:message id="originMsg" for="origin_autocomplete" />
<p:tooltip for="origin_autocomplete" styleClass="tooltip"
showEvent="focus" hideEvent="blur" />
</h:panelGroup>
<h:panelGroup>
<h:outputText value="Nach:" />
<h:outputText style="color:red" value="* " />
</h:panelGroup>
<p:autoComplete id="destination_autocomplete" minQueryLength="3"
queryDelay="300"
rendered="#{empty searchBean.notUniqueDestinations}"
forceSelection="false" charset="UTF-8" maxResults="5"
placeholder="PLZ, Stadt oder Statdtteil"
value="#{searchBean.destinationDisplayNameAndClearGeoLocation}"
effect="fade" required="true" label="Nach"
title="Empfängeradresse eingeben"
completeMethod="#{geoNamesService.getGeoNamesByInput}" />
<h:panelGrid
rendered="#{!empty searchBean.notUniqueDestinations}"
columns="1">
<h:selectOneMenu
value="#{searchBean.selectedNotUniqueDestinationId}"
style="width:200px;" onchange="submit()"
valueChangeListener="#{searchBean.changeSelectedDestination}">
<f:selectItems value="#{searchBean.notUniqueDestinations}"
var="destination"
itemLabel="#{destination.name}, #{destination.zipcode}"
itemValue="#{destination.id}" />
</h:selectOneMenu>
<p:commandLink id="resetDestinationToInput" ajax="false"
immediate="true" style="margin-right:20px;"
action="resetDestinationToInput">
<h:outputText value="zurücksetzen" />
</p:commandLink>
</h:panelGrid>
<h:panelGroup>
<p:message id="destinationMsg" for="destination_autocomplete" />
<p:tooltip for="destination_autocomplete" styleClass="tooltip" showEvent="focus" hideEvent="blur" />
</h:panelGroup>
</h:panelGrid>
Controller:
#RequestMapping(value="/", method=RequestMethod.GET)
public ModelAndView init() {
ModelAndView mav = new ModelAndView("suche*");
return mav;
}
#RequestMapping(value="/suche*", method = RequestMethod.GET)
public ModelAndView search(HttpServletRequest request) {
ModelAndView mav = new ModelAndView("views/suche");
return mav;
}
#RequestMapping(value="/suche*", method = RequestMethod.POST)
public ModelAndView _search(SearchRequestBean searchBean, Model model) {
ModelAndView mav = new ModelAndView("views/suche");
return mav;
}
#RequestMapping(value="/detail*", method=RequestMethod.GET)
public ModelAndView detail() {
ModelAndView mav = new ModelAndView("views/detail");
return mav;
}
T hank you very much.

autowiring an external bean does not work

Im tryin to map the bean called "userVO" to the security controller with annotations, it works when I map it by xml configuration, but I keep getting the following error when I use annotations
WARNING: /login.xhtml #22,37 value="#{securityController.userVO.vc_name}": Target unreacheable, 'userVO' returned null
I must say UserVO is in a different project that I also own, and its dependency is handled with maven
The following is my spring-beans config file
<?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-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<import resource="mapper-beans.xml" />
<bean name="userVO" id="userVO" class="rst.core.security.UserVO"
scope="session" />
<context:annotation-config />
<context:component-scan base-package="rst.core.security" />
<context:component-scan base-package="rst.controller" />
</beans>
The following is the controller with the mapping to userVO that its not working:
#ManagedBean
#RequestScoped
#Controller
public class SecurityController {
public static Logger log;
private WebFacade webFacade;
#Autowired
private UserVO userVO;
public SecurityController() {
log = LoggerFactory.getLogger(this.getClass());
log.debug("Creating SecurityController.");
}
public String login() {
UserVO user= webFacade.validateUser(getUserVO()); // method to search the db
if (user!= null) {
return "accessGranted";
} else {
return "accessDenied";
}
}
//getters and setters....
}
Also this is the login screen that triggers the error:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1 /DTD/xhtml1-transitional.dtd">
<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"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form id="form">
<p:panel id="panel" header="New Person">
<h:panelGrid columns="3">
<h:outputLabel for="name" value="Name: *" />
<p:inputText id="name" value="#{securityController.userVO.vc_name}"
label="name" required="true"/>
<h:outputLabel for="password" value="Password: *" />
<p:inputText id="password" value="#{securityController.userVO.vc_password}"
required="true" label="Password" type="password"/>
</h:panelGrid>
<p:commandButton id="btn" value="Login" update="panel"
action="#{securityController.login}"/>
</p:panel>
</h:form>
</h:body>
</html>
And the following is my 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">
<display-name>rst-web</display-name>
<!---+++++++++++++++++++++++++++++++++++++++++++++++++Spring++++++++++++++++++++++++++++++++++++++++++-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-beans.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- ++++++++++++++++++++++++ JSF +++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/login.xhtml</welcome-file>
</welcome-file-list>
</web-app>
How is securityController resolved? It is marked with #ManagedBean which makes it visible to JSF, on the other hand JSF won't recognize spring's #Autowired when instantiating SecurityManager.
If you want to stick to spring, get rid of #ManagedBean, change #RequestScoped to #Scope("request") and make sure you have set up ELResolver correctly in faces-config:
<faces-config>
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
...
</application>
</faces-config>

Integration of JSF 2, Spring 3.1 and Hibernate 4.1 in Eclipse

According to my previous question integration of jsf2.0 and spring 3.1 and hibernate 4.1
I think my code has problem. I am really confused. I did as other advised but still getting error 404:Description The requested resource (/jsfspringhiber/default.xhtml) is not available. I don't use maven.
Customer.java
package main;
public class Customer{
public long customerId;
public String name;
public String address;
public String createdDate;
public long getCustomerId() {
return customerId;
}
public void setCustomerId(long customerId) {
this.customerId = customerId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCreatedDate() {
return createdDate;
}
public void setCreatedDate(String createdDate) {
this.createdDate = createdDate;
}
}
CustomerBean.java
package main;
import java.io.Serializable;
import java.util.List;
import main.CustomerBo;
import main.Customer;
public class CustomerBean implements Serializable{
CustomerBo customerBo;
public String name;
public String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public void setCustomerBo(CustomerBo customerBo) {
this.customerBo = customerBo;
}
public CustomerBo getCustomerBo() {
return customerBo;
}
//get all customer data from database
public List<Customer> getCustomerList(){
return customerBo.findAllCustomer();
}
//add a new customer data into database
public String addCustomer(){
Customer cust = new Customer();
cust.setName(getName());
cust.setAddress(getAddress());
customerBo.addCustomer(cust);
clearForm();
return "";
}
//clear form values
private void clearForm(){
setName("");
setAddress("");
}
}
CustomerBo.java
import java.util.List;
import main.Customer;
public interface CustomerBo{
void addCustomer(Customer customer);
List<Customer> findAllCustomer();
}
CustomerBoImpl.java
public class CustomerBoImpl implements CustomerBo{
CustomerDao customerDao;
public void setCustomerDao(CustomerDao customerDao) {
this.customerDao = customerDao;
}
public void addCustomer(Customer customer){
customerDao.addCustomer(customer);
}
public List<Customer> findAllCustomer(){
return customerDao.findAllCustomer();
}
}
CustomerDao.java
public interface CustomerDao{
void addCustomer(Customer customer);
List<Customer> findAllCustomer();
}
CustomerDaoImpl.java
public class CustomerDaoImpl implements CustomerDao{
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public void addCustomer(Customer customer){
getSessionFactory().getCurrentSession().save
(customer);
}
public List<Customer> findAllCustomer(){
List list = getSessionFactory().getCurrentSession
().createQuery("from Customer").list();
return list;
}
}
Customer.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 27, 2012 1:01:10 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="main.Customer" table="CUSTOMER">
<id name="customerId" type="long">
<column name="CUSTOMER_ID" />
<generator class="assigned" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" />
</property>
<property name="address" type="java.lang.String">
<column name="ADDRESS" />
</property>
<property name="createdDate" type="java.lang.String">
<column name="CREATED_DATE" />
</property>
</class>
</hibernate-mapping>
CustomerBean.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-3.1xsd">
<bean id="customerBo"
class="main.CustomerBoImpl" >
<property name="customerDao" ref="customerDao" />
</bean>
<bean id="customerDao"
class="main.CustomerDaoImpl" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
DataSource.xml
<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-3.1.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#Mohsen-PC:1521:mydb" />
<property name="username" value="system" />
<property name="password" value="123" />
</bean>
</beans>
HibernateSessionFactory.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-3.1.xsd">
<!-- Hibernate session factory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>main/Customer.hbm.xml</value>
</list>
</property>
</bean>
</beans>
applicationContext.xml
<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-3.1.xsd">
<!-- Database Configuration -->
<import resource="main/DataSource.xml"/>
<import resource="main/HibernateSessionFactory.xml"/>
<!-- Beans Declaration -->
<import resource="main/CustomerBean.xml"/>
</beans>
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
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-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
<managed-bean>
<managed-bean-name>customer</managed-bean-name>
<managed-bean-class>main.CustomerBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>customerBo</property-name>
<value>#{customerBo}</value>
</managed-property>
</managed-bean>
</faces-config>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>jsfspringhiber</display-name>
<!-- Add Support for Spring -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>default.xhtml</welcome-file>
</welcome-file-list>
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>
default.xhtml
<<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
>
<h:head>
<h:outputStylesheet library="css" name="table-style.css" />
</h:head>
<h:body>
<h1>JSF 2.0 + Spring + Hibernate Example</h1>
<h:dataTable value="#{customer.getCustomerList()}" var="c"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row"
>
<h:column>
<f:facet name="header">
Customer ID
</f:facet>
#{c.customerId}
</h:column>
<h:column>
<f:facet name="header">
Name
</f:facet>
#{c.name}
</h:column>
<h:column>
<f:facet name="header">
Address
</f:facet>
#{c.address}
</h:column>
<h:column>
<f:facet name="header">
Created Date
</f:facet>
#{c.createdDate}
</h:column>
</h:dataTable>
<h2>Add New Customer</h2>
<h:form>
<h:panelGrid columns="3">
Name :
<h:inputText id="name" value="#{customer.name}"
size="20" required="true"
label="Name" >
</h:inputText>
<h:message for="name" style="color:red" />
Address :
<h:inputTextarea id="address" value="#{customer.address}"
cols="30" rows="10" required="true"
label="Address" >
</h:inputTextarea>
<h:message for="address" style="color:red" />
</h:panelGrid>
<h:commandButton value="Submit" action="#{customer.addCustomer()}" />
</h:form>
</h:body>
</html>
the structure of my project:
Lets do one thing, Here is the code for a basic skeleton for integrating Spring and JSF. If you are able to see the login page with this code then we will build the solution out of this.
Create a new Dynamic Web Project with the following files:
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"
version="3.0">
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
</web-app>
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
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-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
applicationContext.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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.examples" />
</beans>
Test pages: index.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Welcome</title>
</h:head>
<h:body>
<h:form>
<h3>Please enter your name and password.</h3>
<table>
<tr>
<td>Name:</td>
<td><h:inputText value="#{userBean.name}"/></td>
</tr>
<tr>
<td>Password:</td>
<td><h:inputSecret value="#{userBean.password}"/></td>
</tr>
</table>
<p><h:commandButton value="Login" action="welcome"/></p>
</h:form>
</h:body>
</html>
welcome.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Welcome</title>
</h:head>
<h:body>
<h3>Spring integration with JavaServer Faces Successful, #{userBean.name}!</h3>
</h:body>
</html>
And finally the backing bean: UserBean.java
package com.examples;
import java.io.Serializable;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
#Component
#Scope("request")
public class UserBean implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private String password;
public String getName() { return name; }
public void setName(String newValue) { name = newValue; }
public String getPassword() { return password; }
public void setPassword(String newValue) { password = newValue; }
}
That's it, nothing more. Just copy and paste this code into a sample project and lets see what we can do later. One more thing I noticed is that your lib folder under WEB-INF seems empty. You will need the following jars to run this project:
Download Latest GA release of Spring Framework from here and include the jars in the dist folder of the zip file.
Download JSF jars from here, you can grab the latest 2.1.10.
Include commons-logging jar from here
i use maven. the correct answer is here.
the structure is:

Resources