Beruflich Dokumente
Kultur Dokumente
1 of 13
http://www.javabeat.net/integrating-spring-web-flow-with-jsf/
Follow @javabeat
Like
Tweet
also read:
Advertise Here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
<filter>
<filter-name>charEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
08-07-2015 23:06
2 of 13
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
http://www.javabeat.net/integrating-spring-web-flow-with-jsf/
<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>charEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<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>Spring MVC Dispatcher Servlet</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>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/spring/*</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>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
08-07-2015 23:06
3 of 13
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
1
2
3
4
5
6
7
8
9
10
11
</property>
<property name="defaultHandler">
<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
</property>
</bean>
<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
<property name="flowExecutor" ref="flowExecutor"/>
</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>
</beans>
<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
<faces-config>
<application>
<!-- Enables Facelets -->
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
</faces-config>
1
2
3
4
5
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=spring/start">
</head>
</html>
1
2
3
4
5
6
7
8
9
1
2
3
4
5
1
2
3
http://www.javabeat.net/integrating-spring-web-flow-with-jsf/
<view-state id="test">
</view-state>
</flow>
<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>
08-07-2015 23:06
4 of 13
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
http://www.javabeat.net/integrating-spring-web-flow-with-jsf/
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<body>
<ui:composition template="../template.xhtml">
<ui:define name="heading">
</ui:define>
<ui:define name="body">
Sample page which illustrates the integration between JSF and Spring Web Flow
</ui:define>
</ui:composition>
</body>
</html>
08-07-2015 23:06
5 of 13
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
http://www.javabeat.net/integrating-spring-web-flow-with-jsf/
</transition>
</view-state>
<view-state id="showSearchResults">
<on-render>
<evaluate expression="employeeSearchService.findEmployees(employeeSearchCriteria)"
result="viewScope.allEmployees" result-type="dataModel" />
</on-render>
</view-state>
</flow>
08-07-2015 23:06
6 of 13
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
http://www.javabeat.net/integrating-spring-web-flow-with-jsf/
<f:facet name="header">Name</f:facet>
<h:outputText value="#{employee.name}" align="left" />
</h:column>
<h:column>
<f:facet name="header">Date of Birth</f:facet>
<h:outputText value="#{employee.dob}" align="left" />
</h:column>
<h:column>
<f:facet name="header">Designation</f:facet>
<h:outputText value="#{employee.designation}" align="left" />
</h:column>
</h:dataTable>
<p align="left">
<a href="search">Search Again</a>
</p>
</ui:define>
</ui:composition>
</body>
</html>
package net.javabeat.spring.webflow.jsf.search.employee;
import java.io.Serializable;
import java.util.Date;
public class Employee implements Serializable{
private
private
private
private
String id;
String name;
Date dob;
String designation;
08-07-2015 23:06
7 of 13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package net.javabeat.spring.webflow.jsf.search.employee;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package net.javabeat.spring.webflow.jsf.search.employee;
39
40
41
42
43
44
45
46
47
48
49
50
http://www.javabeat.net/integrating-spring-web-flow-with-jsf/
import java.io.Serializable;
public class EmployeeCriteria implements Serializable{
private static final long serialVersionUID = 1L;
private String empName;
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
}
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class EmployeeSearchService {
private static List<Employee> allEmployees;
public List<Employee> findEmployees(EmployeeCriteria criteria){
List<Employee> searchedEmployees = new ArrayList<Employee>();
if (criteria == null){
return allEmployees;
}
String searchEmpName = criteria.getEmpName();
if (searchEmpName != null && searchEmpName.trim().length() > 0){
for (Employee anEmployee : allEmployees){
if (anEmployee.getName().contains(searchEmpName)){
searchedEmployees.add(anEmployee);
}
}
return searchedEmployees;
}else{
return allEmployees;
}
}
static{
allEmployees = new ArrayList<Employee>();
allEmployees.add(employee("10000", "Steve Clark", new Date(1960, 6, 12), "Employee"));
allEmployees.add(employee("10000", "Alfred Ray", new Date(1954, 4, 17), "Manager"));
allEmployees.add(employee("10000", "Robert Woulsh", new Date(1944, 2, 16),
"Director"));
}
static Employee employee(String id, String name, Date dob, String designation){
Employee employee = new Employee();
employee.setId(id);
employee.setName(name);
employee.setDob(dob);
employee.setDesignation(designation);
return employee;
}
}
08-07-2015 23:06
8 of 13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
http://www.javabeat.net/integrating-spring-web-flow-with-jsf/
08-07-2015 23:06
9 of 13
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
http://www.javabeat.net/integrating-spring-web-flow-with-jsf/
</bean>
<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
<property name="flowExecutor" ref="flowExecutor"/>
</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>
<tx:annotation-driven />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:book" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
</beans>
package net.javabeat.spring.webflow.jsf.book;
import
import
import
import
import
java.io.Serializable;
javax.persistence.Entity;
javax.persistence.GeneratedValue;
javax.persistence.GenerationType;
javax.persistence.Id;
@Entity
public class Book implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String category;
private String author;
private double price;
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
08-07-2015 23:06
10 of 13
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
http://www.javabeat.net/integrating-spring-web-flow-with-jsf/
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
if (!(object instanceof Book)) {
return false;
}
Book other = (Book) object;
if ((this.id == null && other.id != null) || (this.id != null &&
!this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "net.javabeat.spring.webflow.jsf.book.Book[id=" + id + "]";
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
package net.javabeat.spring.webflow.jsf.book;
1
2
3
4
5
6
7
8
package net.javabeat.spring.webflow.jsf.book;
import java.util.List;
public interface BookService {
List<Book> findAllBooks();
List<Book> findBooks(BookSearchCriteria criteria);
void createBook(String name, String category, String author, double price);
}
import
import
import
import
import
import
java.util.List;
javax.persistence.EntityManager;
javax.persistence.PersistenceContext;
javax.persistence.Query;
org.springframework.stereotype.Repository;
org.springframework.stereotype.Service;
08-07-2015 23:06
11 of 13
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
1
2
3
4
5
6
7
8
9
10
11
12
http://www.javabeat.net/integrating-spring-web-flow-with-jsf/
import org.springframework.transaction.annotation.Transactional;
@Service("bookService")
@Repository
public class BookServiceImpl implements BookService {
private EntityManager em;
@PersistenceContext
public void setEntityManager(EntityManager em){
this.em = em;
}
@Transactional(readOnly=true)
public List<Book> findAllBooks() {
Query query = em.createQuery("select book from Book book");
List<Book> results = query.getResultList();
if (results == null || results.size() == 0){
createTestBooks();
return query.getResultList();
}else{
return results;
}
}
private void createTestBooks(){
createBook("Java Programming", "Technical", "James", 1110.00);
createBook("Life After Death", "Spiritual", "Unknown", 3140.00);
createBook("All About Numerology", "Numerolgy", "Richard", 6130.00);
}
@Transactional(readOnly=true)
public List<Book> findBooks(BookSearchCriteria criteria) {
if (criteria == null){
return findAllBooks();
}
String name = criteria.getName();
String author = criteria.getAuthor();
String query = "select book from Book";
if (name != null && name.trim().length() > 0){
query = query + " where upper(book.name) = :name ";
}
if (author != null && author.trim().length() > 0){
if (query.contains("where")){
query = query + " and ";
}else{
query = query + "where ";
}
query = query + " upper(book.author) = :author ";
}
Query queryObject = em.createQuery(query);
queryObject.setParameter("name", name);
queryObject.setParameter("author", author);
List<Book> results = queryObject.getResultList();
if (results == null || results.size() == 0){
createTestBooks();
}
return queryObject.getResultList();
}
@Transactional(readOnly=true)
public void createBook(String name, String category, String author, double price) {
Book book = new Book();
book.setName(name);
book.setCategory(category);
book.setAuthor(author);
book.setPrice(price);
em.persist(book);
}
}
08-07-2015 23:06
12 of 13
13
14
15
16
17
18
19
20
21
22
23
http://www.javabeat.net/integrating-spring-web-flow-with-jsf/
</transition>
</view-state>
<view-state id="bookAdd">
<on-render>
<evaluate expression="bookService.createBook(bookSearchCriteria.name,
bookSearchCriteria.category,
bookSearchCriteria.author, bookSearchCriteria.price)"/>
</on-render>
</view-state>
</flow>
1 Comment
Sort by
Add a comment...
08-07-2015 23:06
13 of 13
http://www.javabeat.net/integrating-spring-web-flow-with-jsf/
Lifestyle Journal
Web2Carz.com
TheFix.com
Spring 5 Announced
0 Comments
08-07-2015 23:06