SlideShare a Scribd company logo
Java Servle Faces
ThS Văn Thiên Hoàng
N i dungộ
JSF là gì?
Thu n l i c a JSF.ậ ợ ủ
Ki n trúc JSF.ế
Mô hình ho t đ ng JSF.ạ ộ
Java Server Faces là gì ?
 JSF là m t n n t ng công ngh cho phépộ ề ả ệ
thi t l p mô hình MVC.ế ậ
 Cung c p m t t p h p các thành ph n dùngấ ộ ậ ợ ầ
l i cho phép trình bày GUI d a vào Web.ạ ự
 Cung c p m t t p các th JSP cho phép truyấ ộ ậ ẻ
c p các thành ph n.ậ ầ
Thu n l i c a JFSậ ợ ủ
Các cách ki m soát GUIể
Cung c p th vi n API k t h p v i các customấ ư ệ ế ợ ớ
tags đ t o giao di n HTML ph c t p.ể ạ ệ ứ ạ
Ki m soát s ki nể ự ệ
H tr vi t code java đ ki m soát s ki n khiỗ ợ ế ể ể ự ệ
form đ c submit.ượ
Qu n lý Beanả
H tr đ y đ vi c s d ng Bean và truy nỗ ợ ầ ủ ệ ử ụ ề
tham s .ố
Ngôn ng : h tr đ y đ cách th c đ truyữ ỗ ợ ầ ủ ứ ể
c p thu c tính bean và các thành ph nậ ộ ầ
khác.
Ki n trúc JSFế
 JSF tuân th mô hìnhủ MVC
 Model: đ i t ng và thu c tính c a ng d ng.ố ượ ộ ủ ứ ụ
 View: Cách bi u di n ng i s d ng.ể ễ ườ ử ụ
 Controller: Đ nh nghĩa cách x lý nghi p v c a ngị ử ệ ụ ủ ứ
d ng.ụ
Xây d ng các ng d ng c b nự ứ ụ ơ ả
Ví d ng d ng là m t ph n m m máy tính b túiụ ứ ụ ộ ầ ề ỏ
(Calculator), đ minh h aể ọ :
Làm th nào đ b trí m t ng d ng JSF đ tri n khaiế ể ố ộ ứ ụ ể ể
Làm th nào đ c u hình m t t p tin web.xml cho JSFế ể ấ ộ ệ
Làm th nào đ c u hình m t t p tin faces-config.xml choế ể ấ ộ ệ
m t ng d ngộ ứ ụ
Vi t bean qu n lý (còn g i là các đ i t ng mô hình và cácế ả ọ ố ượ
trình đi u khi n)ề ể
Xây d ng khung nhìn b ng cách s d ng công ngh JSPự ằ ử ụ ệ
S d ng các th vi n th tùy bi n đ xây d ng cây thànhử ụ ư ệ ẻ ế ể ự
ph n trong g c khung nhìnầ ố
M c đ nh duy t tính h p l c a các tr ng bi u m uặ ị ệ ợ ệ ủ ườ ể ẫ
Xây d ng các ng d ng c b n (1)ự ứ ụ ơ ả
Các b c th c hi nướ ự ệ
Khai báo Faces Servlet và thêm ánh x Facesạ
Servlet trong t p tin web.xml c a b mô t tri nệ ủ ộ ả ể
khai ng d ng Webứ ụ
Ch rõ t p tin faces-config.xml trong t p tinỉ ệ ệ
web.xml
T o l p Calculatorạ ớ
Khai báo bean Calculator trong t p tin faces-ệ
config.xml file
T o trang index.jspạ
T o trang calculator.jspạ
Khai báo servlet Faces và ánh xạ
servlet
Đ s d ng Servlet Faces, c n ph i cài đ tể ử ụ ầ ả ặ
nó trong t p tin web.xmlệ
<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>*.jsf</url-pattern> </servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
Ch rõ t p tin faces-config.xml fileỉ ệ
T o t p tin c u hìnhfaces-config.xml và đ tạ ậ ấ ặ
nó vào trong th m c WEB-INF.ư ụ
<?xml version='1.0' encoding='UTF-8'?>
<!-- =========== FULL CONFIGURATION FILE
================================== -->
<faces-config version="1.2"
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_1_2.xsd">
</faces-config>
T o l p Calculatorạ ớ
Package my;
public class Calculator {
private int firstNumber = 0;
private int result = 0;
private int secondNumber = 0;
public void add() { result = firstNumber + secondNumber; }
public void multiply() { result = firstNumber * secondNumber; }
public void clear() { result = 0; }
public int getFirstNumber() { return firstNumber; }
public void setFirstNumber(int firstNumber)
{this.firstNumber = firstNumber; }
public int getResult() { return result; }
public void setResult(int result) { this.result = result; }
public int getSecondNumber() { return secondNumber; }
public void setSecondNumber(int secondNumber)
{ this.secondNumber = secondNumber; } }
Khai báo bean Calculator trong t p tinệ
faces-config.xml file
<?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_1_2.xsd"
version="1.2">
<managed-bean>
<managed-bean-name>calculator</managed-bean-name>
<managed-bean-class> my.Calculator </managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
T o trang index.jspạ
M c đích c a trang index.jsp trong ngụ ủ ứ
d ng Calculator là đ đ m b o r ng trangụ ể ả ả ằ
calculator.jsp n p vào trong b i c nh JSFạ ố ả
sao cho có th tìm th y g c khung nhìnể ấ ố
t ng ng.ươ ứ
<jsp:forward page="/faces/calculator.jsp" />
T o trang calculator.jspạ
//T p tin. /src/main/webapp/calculator.jspậ
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <title>Calculator Application</title> </head>
<body>
<f:view>
<h:form id="calcForm"> <h4>Calculator</h4>
<table> <tr>
<td><h:outputLabel value="First Number" for="firstNumber" /></td>
<td><h:inputText id="firstNumber"
value="#{calculator.firstNumber}" required="true" /></td>
<td><h:message for="firstNumber" /></td>
</tr>
T o trang calculator.jspạ
<tr>
<td><h:outputLabel value="Second Number" for="secondNumber" /> </td
<td><h:inputText id="secondNumber"
value="#{calculator.secondNumber}" required="true" /></td>
<td><h:message for="secondNumber" /></td>
</tr> </table>
<div>
<h:commandButton action="#{calculator.add}" value="Add" />
<h:commandButton action="#{calculator.multiply}" value="Multiply" />
<h:commandButton action="#{calculator.clear}" value="Clear"
immediate="true"/>
</div>
</h:form>
T o trang calculator.jspạ
<h:panelGroup rendered="#{calculator.result != 0}">
<h4>Results</h4>
<table>
<tr>
<td> First Number ${calculator.firstNumber} </td></tr>
<tr>
<td> Second Number ${calculator.secondNumber} </td>
</tr>
<tr><td> Result ${calculator.result} </td></tr>
</table>
</h:panelGroup>
</f:view>
</body>
</html>
T o trang calculator.jspạ
<h:panelGroup rendered="#{calculator.result != 0}">
<h4>Results</h4>
<table>
<tr>
<td> First Number ${calculator.firstNumber} </td></tr>
<tr>
<td> Second Number ${calculator.secondNumber} </td>
</tr>
<tr><td> Result ${calculator.result} </td></tr>
</table>
</h:panelGroup>
</f:view>
</body>
</html>
Các th JSFẻ
<f:view> </f:view>
<h:form id=""> </h:form>
<h:outputLabel value="" for="" />
<h:inputText id="" value="" required="true" />
<h:message for="" />
<h:commandButton action="" value="" />
<h:panelGroup></h:panelGroup>
<h:panelGrid
S d ng <h:panelGrid> đ hi n th d li u d ngử ụ ể ể ị ữ ệ ạ
b ng.ả
Không th thêm HTML vào m t <h:panelGrid>.ể ộ
T o trang calculator.jspạ -ph nầ
nh pậ
//T p tin. /src/main/webapp/calculator.jspậ
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Calculator Application</title>
</head>
<body>
<h:form id="calcForm">
<h4>Calculator</h4>
T o trang calculator.jsp-phạ nầ
nh pậ
<h:panelGrid columns="3">
<%-- First Number--%>
<h:outputLabel value="First Number" for="firstNumber" />
<h:inputText id="firstNumber" value="#{calculator.firstNumber}" required="true" />
<h:message for="firstNumber" />
<%-- Second Number--%>
<h:outputLabel value="Second Number" for="secondNumber" />
<h:inputText id="secondNumber" value="#{calculator.secondNumber}" required="true"/>
<h:message for="secondNumber" />
</h:panelGrid>
<div>
<h:commandButton action="#{calculator.add}" value="Add" />
<h:commandButton action="#{calculator.multiply}" value="Multiply" />
<h:commandButton action="#{calculator.clear}" value="Clear" immediate="true"/>
</div>
</h:form>
T o trang calculator.jsp-phạ n k t quầ ế ả
<h:panelGroup rendered="#{calculator.result != 0}">
<h4>Results</h4>
<h:panelGrid columns="1">
<h:outputText value="First Number #{calculator.firstNumber}"/>
<h:outputText value="Second Number #{calculator.secondNumber}"/>
<h:outputText value="Result #{calculator.result}"/>
</h:panelGrid>
</h:panelGroup>
</f:view>
</body>
</html>
Đ nh ki u cho PanelGridị ể
//T p tin. /src/main/webapp/calculator.jspậ
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Calculator Application</title>
<link rel="stylesheet" type="text/css“
href="<%=request.getContextPath()%>/css/main.css" />
</head>
<body>
<h:form id="calcForm">
<h4>Calculator</h4>
CSS cho PanelGrid
oddRow {
background-color: white;
}
evenRow {
background-color: silver;
}
formGrid {
border: solid #000 3px; width: 400px;
}
resultGrid {
border: solid #000 1px; width: 200px;
}
/css/main.css
S d ng CSS, thông báoử ụ
<h:panelGrid columns="3“ rowClasses="oddRow, evenRow" styleClass="formGrid">
<%-- First Number--%>
<h:outputLabel value="First Number" for="firstNumber" />
<h:inputText id="firstNumber" value="#{calculator.firstNumber}" required="true“
label="First Number"/>
<h:message for="firstNumber" />
<%-- Second Number--%>
<h:outputLabel value="Second Number" for="secondNumber" />
<h:inputText id="secondNumber" value="#{calculator.secondNumber}" required="true“
label=“Second Number"/>
<h:message for="secondNumber" />
</h:panelGrid>
<div>
<h:commandButton action="#{calculator.add}" value="Add" />
<h:commandButton action="#{calculator.multiply}" value="Multiply" />
<h:commandButton action="#{calculator.clear}" value="Clear" immediate="true"/>
</div>
</h:form>
S d ng CSSử ụ
<h:panelGroup rendered="#{calculator.result != 0}">
<h4>Results</h4>
<h:panelGrid columns="1“ rowClasses="oddRow, evenRow" styleClass="resultGrid">
<h:outputText value="First Number #{calculator.firstNumber}"/>
<h:outputText value="Second Number #{calculator.secondNumber}"/>
<h:outputText value="Result #{calculator.result}"/>
</h:panelGrid>
</h:panelGroup>
</f:view>
</body>
</html>
Hi n th thông báo tóm t tể ị ắ
<h:panelGrid columns="3“ rowClasses="oddRow, evenRow" styleClass="formGrid">
<%-- First Number--%>
<h:outputLabel value="First Number" for="firstNumber" />
<h:inputText id="firstNumber" value="#{calculator.firstNumber}" required="true”>
<h:message for="firstNumber" showSummary="true" showDetail="false"/>
<%-- Second Number--%>
<h:outputLabel value="Second Number" for="secondNumber" />
<h:inputText id="secondNumber" value="#{calculator.secondNumber}" required="true“
label=“Second Number"/>
<h:message for="secondNumber" />
</h:panelGrid>
<div>
<h:commandButton action="#{calculator.add}" value="Add" />
<h:commandButton action="#{calculator.multiply}" value="Multiply" />
<h:commandButton action="#{calculator.clear}" value="Clear" immediate="true"/>
</div>
</h:form>
Vi t đè lên n i dung thông báoế ộ
<h:panelGrid columns="3“ rowClasses="oddRow, evenRow" styleClass="formGrid">
<%-- First Number--%>
<h:outputLabel value="First Number" for="firstNumber" />
<h:inputText id="firstNumber" value="#{calculator.firstNumber}" required="true“
label="First Number“ requiredMessage="required" converterMessage="not a valid" />
<h:message for="firstNumber" />
<%-- Second Number--%>
<h:outputLabel value="Second Number" for="secondNumber" />
<h:inputText id="secondNumber" value="#{calculator.secondNumber}" required="true“
label=“Second Number"/>
<h:message for="secondNumber" />
</h:panelGrid>
<div>
<h:commandButton action="#{calculator.add}" value="Add" />
<h:commandButton action="#{calculator.multiply}" value="Multiply" />
<h:commandButton action="#{calculator.clear}" value="Clear" immediate="true"/>
</div>
</h:form>
Thay đ i thông báo toàn c cổ ụ
<?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_1_2.xsd" version="1.2">
<application>
<message-bundle>messages</message-bundle>
</application> ...
T o t p messages.propertiesạ ệ
javax.faces.component.UIInput.REQUIRED_detail=required
javax.faces.converter.IntegerConverter.INTEGER_detail=not a valid number
Câu h iỏ

More Related Content

What's hot

Jsf
JsfJsf
Idoc script beginner guide
Idoc script beginner guide Idoc script beginner guide
Idoc script beginner guide
Vinay Kumar
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용
KyeongMook "Kay" Cha
 
Session 3 Java Script
Session 3 Java ScriptSession 3 Java Script
Session 3 Java Script
Muhammad Hesham
 
Django Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksDjango Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, Tricks
Shawn Rider
 
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
성일 한
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Development
ipsitamishra
 
Unified Expression Language
Unified Expression LanguageUnified Expression Language
Unified Expression Language
BG Java EE Course
 
Java script
Java scriptJava script
Java script
Fajar Baskoro
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
Jeado Ko
 
Slimme Joomla! Templating Tips en Truuks
Slimme Joomla! Templating Tips en TruuksSlimme Joomla! Templating Tips en Truuks
Slimme Joomla! Templating Tips en Truuks
ThemePartner
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
Aaronius
 
Chap4 4 2
Chap4 4 2Chap4 4 2
Chap4 4 2
Hemo Chella
 
Web internship Yii Framework
Web internship  Yii FrameworkWeb internship  Yii Framework
Web internship Yii Framework
Noveo
 
AnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFaces
Ankara JUG
 
Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2
Sumy PHP User Grpoup
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
Michał Orman
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
Dirk Haun
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
Magecom Ukraine
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
Claude Tech
 

What's hot (20)

Jsf
JsfJsf
Jsf
 
Idoc script beginner guide
Idoc script beginner guide Idoc script beginner guide
Idoc script beginner guide
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용
 
Session 3 Java Script
Session 3 Java ScriptSession 3 Java Script
Session 3 Java Script
 
Django Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksDjango Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, Tricks
 
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Development
 
Unified Expression Language
Unified Expression LanguageUnified Expression Language
Unified Expression Language
 
Java script
Java scriptJava script
Java script
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
Slimme Joomla! Templating Tips en Truuks
Slimme Joomla! Templating Tips en TruuksSlimme Joomla! Templating Tips en Truuks
Slimme Joomla! Templating Tips en Truuks
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
 
Chap4 4 2
Chap4 4 2Chap4 4 2
Chap4 4 2
 
Web internship Yii Framework
Web internship  Yii FrameworkWeb internship  Yii Framework
Web internship Yii Framework
 
AnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFaces
 
Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2Service approach for development REST API in Symfony2
Service approach for development REST API in Symfony2
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
 

Viewers also liked

Bài 11: JSF-1 - Lập Trình Mạng Nâng Cao
Bài 11:  JSF-1 - Lập Trình Mạng Nâng CaoBài 11:  JSF-1 - Lập Trình Mạng Nâng Cao
Bài 11: JSF-1 - Lập Trình Mạng Nâng Cao
Tuan Nguyen
 
Bài 10: Custom Tag - Lập Trình Mạng Nâng Cao
Bài 10: Custom Tag - Lập Trình Mạng Nâng CaoBài 10: Custom Tag - Lập Trình Mạng Nâng Cao
Bài 10: Custom Tag - Lập Trình Mạng Nâng Cao
Tuan Nguyen
 
Bài 1: Web Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 1: Web Cơ Bản - Lập Trình Mạng Nâng CaoBài 1: Web Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 1: Web Cơ Bản - Lập Trình Mạng Nâng Cao
Tuan Nguyen
 
Security Bootcamp 2013 - Lap trinh web an toan
Security Bootcamp 2013 - Lap trinh web an toanSecurity Bootcamp 2013 - Lap trinh web an toan
Security Bootcamp 2013 - Lap trinh web an toan
Security Bootcamp
 
Sức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajax
Sức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajaxSức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajax
Sức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajax
Tuyet Tam
 
[Cntt] bài giảng java khtn hcm
[Cntt] bài giảng java   khtn hcm[Cntt] bài giảng java   khtn hcm
[Cntt] bài giảng java khtn hcm
Hong Phuoc Nguyen
 
Bài 3: Servlet - Lập Trình Mạng Nâng Cao
Bài 3: Servlet - Lập Trình Mạng Nâng CaoBài 3: Servlet - Lập Trình Mạng Nâng Cao
Bài 3: Servlet - Lập Trình Mạng Nâng Cao
Tuan Nguyen
 
Bài 2: J2EE - Lập Trình Mạng Nâng Cao
Bài 2: J2EE - Lập Trình Mạng Nâng CaoBài 2: J2EE - Lập Trình Mạng Nâng Cao
Bài 2: J2EE - Lập Trình Mạng Nâng Cao
Tuan Nguyen
 
Vận dụng kiến thức lập trình web vào môi trường thực tế
Vận dụng kiến thức lập trình web vào môi trường thực tếVận dụng kiến thức lập trình web vào môi trường thực tế
Vận dụng kiến thức lập trình web vào môi trường thực tế
VKhang Yang
 
Bài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng Cao
Bài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng CaoBài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng Cao
Bài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng Cao
Tuan Nguyen
 
Bài 4: JSP Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 4: JSP Cơ Bản - Lập Trình Mạng Nâng CaoBài 4: JSP Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 4: JSP Cơ Bản - Lập Trình Mạng Nâng Cao
Tuan Nguyen
 
VCP 21- VMWare VPC 6
VCP 21- VMWare VPC 6VCP 21- VMWare VPC 6
VCP 21- VMWare VPC 6
Tuan Nguyen
 
Linux LPI Bacis
Linux LPI BacisLinux LPI Bacis
Linux LPI Bacis
Tuan Nguyen
 
Java beans
Java beansJava beans
Java beans
sptatslide
 
tài liệu Mã nguồn mở Lap trình shells
tài liệu Mã nguồn mở  Lap trình shellstài liệu Mã nguồn mở  Lap trình shells
tài liệu Mã nguồn mở Lap trình shells
Thuyet Nguyen
 
Presentation on leadership
Presentation on leadershipPresentation on leadership
Presentation on leadership
sd college
 
Leadership concepts and theories
Leadership concepts and theoriesLeadership concepts and theories
Leadership concepts and theories
alaguraja76
 

Viewers also liked (17)

Bài 11: JSF-1 - Lập Trình Mạng Nâng Cao
Bài 11:  JSF-1 - Lập Trình Mạng Nâng CaoBài 11:  JSF-1 - Lập Trình Mạng Nâng Cao
Bài 11: JSF-1 - Lập Trình Mạng Nâng Cao
 
Bài 10: Custom Tag - Lập Trình Mạng Nâng Cao
Bài 10: Custom Tag - Lập Trình Mạng Nâng CaoBài 10: Custom Tag - Lập Trình Mạng Nâng Cao
Bài 10: Custom Tag - Lập Trình Mạng Nâng Cao
 
Bài 1: Web Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 1: Web Cơ Bản - Lập Trình Mạng Nâng CaoBài 1: Web Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 1: Web Cơ Bản - Lập Trình Mạng Nâng Cao
 
Security Bootcamp 2013 - Lap trinh web an toan
Security Bootcamp 2013 - Lap trinh web an toanSecurity Bootcamp 2013 - Lap trinh web an toan
Security Bootcamp 2013 - Lap trinh web an toan
 
Sức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajax
Sức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajaxSức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajax
Sức mạnh của jsf 2, phần 3 xử lý sự kiện, java script và ajax
 
[Cntt] bài giảng java khtn hcm
[Cntt] bài giảng java   khtn hcm[Cntt] bài giảng java   khtn hcm
[Cntt] bài giảng java khtn hcm
 
Bài 3: Servlet - Lập Trình Mạng Nâng Cao
Bài 3: Servlet - Lập Trình Mạng Nâng CaoBài 3: Servlet - Lập Trình Mạng Nâng Cao
Bài 3: Servlet - Lập Trình Mạng Nâng Cao
 
Bài 2: J2EE - Lập Trình Mạng Nâng Cao
Bài 2: J2EE - Lập Trình Mạng Nâng CaoBài 2: J2EE - Lập Trình Mạng Nâng Cao
Bài 2: J2EE - Lập Trình Mạng Nâng Cao
 
Vận dụng kiến thức lập trình web vào môi trường thực tế
Vận dụng kiến thức lập trình web vào môi trường thực tếVận dụng kiến thức lập trình web vào môi trường thực tế
Vận dụng kiến thức lập trình web vào môi trường thực tế
 
Bài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng Cao
Bài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng CaoBài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng Cao
Bài 3: Servlet&Cookie&Session - Lập Trình Mạng Nâng Cao
 
Bài 4: JSP Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 4: JSP Cơ Bản - Lập Trình Mạng Nâng CaoBài 4: JSP Cơ Bản - Lập Trình Mạng Nâng Cao
Bài 4: JSP Cơ Bản - Lập Trình Mạng Nâng Cao
 
VCP 21- VMWare VPC 6
VCP 21- VMWare VPC 6VCP 21- VMWare VPC 6
VCP 21- VMWare VPC 6
 
Linux LPI Bacis
Linux LPI BacisLinux LPI Bacis
Linux LPI Bacis
 
Java beans
Java beansJava beans
Java beans
 
tài liệu Mã nguồn mở Lap trình shells
tài liệu Mã nguồn mở  Lap trình shellstài liệu Mã nguồn mở  Lap trình shells
tài liệu Mã nguồn mở Lap trình shells
 
Presentation on leadership
Presentation on leadershipPresentation on leadership
Presentation on leadership
 
Leadership concepts and theories
Leadership concepts and theoriesLeadership concepts and theories
Leadership concepts and theories
 

Similar to Bài 12: JSF-2 - Lập Trình Mạng Nâng Cao

Jsf intro
Jsf introJsf intro
Jsf intro
vantinhkhuc
 
MVC
MVCMVC
MVC
akshin
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
BG Java EE Course
 
Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSF
SoftServe
 
Lec5 ecom fall16_modified7_november16
Lec5 ecom fall16_modified7_november16Lec5 ecom fall16_modified7_november16
Lec5 ecom fall16_modified7_november16
Zainab Khallouf
 
JSF Presentation"2"
JSF Presentation"2"JSF Presentation"2"
JSF Presentation"2"
SiliconExpert Technologies
 
F# And Silverlight
F# And SilverlightF# And Silverlight
F# And Silverlight
Talbott Crowell
 
Jsf2.0 -4
Jsf2.0 -4Jsf2.0 -4
Jsf2.0 -4
Vinay Kumar
 
Web Application Introduction
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
shaojung
 
Web Application Introduction
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
shaojung
 
Web Application Introduction
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
shaojung
 
Introduction to JavaFX
Introduction to JavaFXIntroduction to JavaFX
Introduction to JavaFX
Mindfire Solutions
 
JSF 2.0 Preview
JSF 2.0 PreviewJSF 2.0 Preview
JSF 2.0 Preview
Skills Matter
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
ivpol
 
Rits Brown Bag - Salesforce Lightning
Rits Brown Bag - Salesforce LightningRits Brown Bag - Salesforce Lightning
Rits Brown Bag - Salesforce Lightning
Right IT Services
 
Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course
JavaEE Trainers
 
Programming with JavaFX
Programming with JavaFXProgramming with JavaFX
Programming with JavaFX
Fulvio Corno
 
Walther Aspnet4
Walther Aspnet4Walther Aspnet4
Walther Aspnet4
rsnarayanan
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
Wildan Maulana
 
My Saminar On Php
My Saminar On PhpMy Saminar On Php
My Saminar On Php
Arjun Kumawat
 

Similar to Bài 12: JSF-2 - Lập Trình Mạng Nâng Cao (20)

Jsf intro
Jsf introJsf intro
Jsf intro
 
MVC
MVCMVC
MVC
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
 
Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSF
 
Lec5 ecom fall16_modified7_november16
Lec5 ecom fall16_modified7_november16Lec5 ecom fall16_modified7_november16
Lec5 ecom fall16_modified7_november16
 
JSF Presentation"2"
JSF Presentation"2"JSF Presentation"2"
JSF Presentation"2"
 
F# And Silverlight
F# And SilverlightF# And Silverlight
F# And Silverlight
 
Jsf2.0 -4
Jsf2.0 -4Jsf2.0 -4
Jsf2.0 -4
 
Web Application Introduction
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
 
Web Application Introduction
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
 
Web Application Introduction
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
 
Introduction to JavaFX
Introduction to JavaFXIntroduction to JavaFX
Introduction to JavaFX
 
JSF 2.0 Preview
JSF 2.0 PreviewJSF 2.0 Preview
JSF 2.0 Preview
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Rits Brown Bag - Salesforce Lightning
Rits Brown Bag - Salesforce LightningRits Brown Bag - Salesforce Lightning
Rits Brown Bag - Salesforce Lightning
 
Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course
 
Programming with JavaFX
Programming with JavaFXProgramming with JavaFX
Programming with JavaFX
 
Walther Aspnet4
Walther Aspnet4Walther Aspnet4
Walther Aspnet4
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
My Saminar On Php
My Saminar On PhpMy Saminar On Php
My Saminar On Php
 

Recently uploaded

“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
CAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on BlockchainCAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on Blockchain
Claudio Di Ciccio
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
Techgropse Pvt.Ltd.
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 

Recently uploaded (20)

“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
CAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on BlockchainCAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on Blockchain
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 

Bài 12: JSF-2 - Lập Trình Mạng Nâng Cao

  • 1. Java Servle Faces ThS Văn Thiên Hoàng
  • 2. N i dungộ JSF là gì? Thu n l i c a JSF.ậ ợ ủ Ki n trúc JSF.ế Mô hình ho t đ ng JSF.ạ ộ
  • 3. Java Server Faces là gì ?  JSF là m t n n t ng công ngh cho phépộ ề ả ệ thi t l p mô hình MVC.ế ậ  Cung c p m t t p h p các thành ph n dùngấ ộ ậ ợ ầ l i cho phép trình bày GUI d a vào Web.ạ ự  Cung c p m t t p các th JSP cho phép truyấ ộ ậ ẻ c p các thành ph n.ậ ầ
  • 4. Thu n l i c a JFSậ ợ ủ Các cách ki m soát GUIể Cung c p th vi n API k t h p v i các customấ ư ệ ế ợ ớ tags đ t o giao di n HTML ph c t p.ể ạ ệ ứ ạ Ki m soát s ki nể ự ệ H tr vi t code java đ ki m soát s ki n khiỗ ợ ế ể ể ự ệ form đ c submit.ượ Qu n lý Beanả H tr đ y đ vi c s d ng Bean và truy nỗ ợ ầ ủ ệ ử ụ ề tham s .ố Ngôn ng : h tr đ y đ cách th c đ truyữ ỗ ợ ầ ủ ứ ể c p thu c tính bean và các thành ph nậ ộ ầ khác.
  • 5. Ki n trúc JSFế  JSF tuân th mô hìnhủ MVC  Model: đ i t ng và thu c tính c a ng d ng.ố ượ ộ ủ ứ ụ  View: Cách bi u di n ng i s d ng.ể ễ ườ ử ụ  Controller: Đ nh nghĩa cách x lý nghi p v c a ngị ử ệ ụ ủ ứ d ng.ụ
  • 6. Xây d ng các ng d ng c b nự ứ ụ ơ ả Ví d ng d ng là m t ph n m m máy tính b túiụ ứ ụ ộ ầ ề ỏ (Calculator), đ minh h aể ọ : Làm th nào đ b trí m t ng d ng JSF đ tri n khaiế ể ố ộ ứ ụ ể ể Làm th nào đ c u hình m t t p tin web.xml cho JSFế ể ấ ộ ệ Làm th nào đ c u hình m t t p tin faces-config.xml choế ể ấ ộ ệ m t ng d ngộ ứ ụ Vi t bean qu n lý (còn g i là các đ i t ng mô hình và cácế ả ọ ố ượ trình đi u khi n)ề ể Xây d ng khung nhìn b ng cách s d ng công ngh JSPự ằ ử ụ ệ S d ng các th vi n th tùy bi n đ xây d ng cây thànhử ụ ư ệ ẻ ế ể ự ph n trong g c khung nhìnầ ố M c đ nh duy t tính h p l c a các tr ng bi u m uặ ị ệ ợ ệ ủ ườ ể ẫ
  • 7. Xây d ng các ng d ng c b n (1)ự ứ ụ ơ ả
  • 8. Các b c th c hi nướ ự ệ Khai báo Faces Servlet và thêm ánh x Facesạ Servlet trong t p tin web.xml c a b mô t tri nệ ủ ộ ả ể khai ng d ng Webứ ụ Ch rõ t p tin faces-config.xml trong t p tinỉ ệ ệ web.xml T o l p Calculatorạ ớ Khai báo bean Calculator trong t p tin faces-ệ config.xml file T o trang index.jspạ T o trang calculator.jspạ
  • 9. Khai báo servlet Faces và ánh xạ servlet Đ s d ng Servlet Faces, c n ph i cài đ tể ử ụ ầ ả ặ nó trong t p tin web.xmlệ <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>*.jsf</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping>
  • 10. Ch rõ t p tin faces-config.xml fileỉ ệ T o t p tin c u hìnhfaces-config.xml và đ tạ ậ ấ ặ nó vào trong th m c WEB-INF.ư ụ <?xml version='1.0' encoding='UTF-8'?> <!-- =========== FULL CONFIGURATION FILE ================================== --> <faces-config version="1.2" 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_1_2.xsd"> </faces-config>
  • 11. T o l p Calculatorạ ớ Package my; public class Calculator { private int firstNumber = 0; private int result = 0; private int secondNumber = 0; public void add() { result = firstNumber + secondNumber; } public void multiply() { result = firstNumber * secondNumber; } public void clear() { result = 0; } public int getFirstNumber() { return firstNumber; } public void setFirstNumber(int firstNumber) {this.firstNumber = firstNumber; } public int getResult() { return result; } public void setResult(int result) { this.result = result; } public int getSecondNumber() { return secondNumber; } public void setSecondNumber(int secondNumber) { this.secondNumber = secondNumber; } }
  • 12. Khai báo bean Calculator trong t p tinệ faces-config.xml file <?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_1_2.xsd" version="1.2"> <managed-bean> <managed-bean-name>calculator</managed-bean-name> <managed-bean-class> my.Calculator </managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> </faces-config>
  • 13. T o trang index.jspạ M c đích c a trang index.jsp trong ngụ ủ ứ d ng Calculator là đ đ m b o r ng trangụ ể ả ả ằ calculator.jsp n p vào trong b i c nh JSFạ ố ả sao cho có th tìm th y g c khung nhìnể ấ ố t ng ng.ươ ứ <jsp:forward page="/faces/calculator.jsp" />
  • 14. T o trang calculator.jspạ //T p tin. /src/main/webapp/calculator.jspậ <?xml version="1.0" encoding="ISO-8859-1" ?> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Calculator Application</title> </head> <body> <f:view> <h:form id="calcForm"> <h4>Calculator</h4> <table> <tr> <td><h:outputLabel value="First Number" for="firstNumber" /></td> <td><h:inputText id="firstNumber" value="#{calculator.firstNumber}" required="true" /></td> <td><h:message for="firstNumber" /></td> </tr>
  • 15. T o trang calculator.jspạ <tr> <td><h:outputLabel value="Second Number" for="secondNumber" /> </td <td><h:inputText id="secondNumber" value="#{calculator.secondNumber}" required="true" /></td> <td><h:message for="secondNumber" /></td> </tr> </table> <div> <h:commandButton action="#{calculator.add}" value="Add" /> <h:commandButton action="#{calculator.multiply}" value="Multiply" /> <h:commandButton action="#{calculator.clear}" value="Clear" immediate="true"/> </div> </h:form>
  • 16. T o trang calculator.jspạ <h:panelGroup rendered="#{calculator.result != 0}"> <h4>Results</h4> <table> <tr> <td> First Number ${calculator.firstNumber} </td></tr> <tr> <td> Second Number ${calculator.secondNumber} </td> </tr> <tr><td> Result ${calculator.result} </td></tr> </table> </h:panelGroup> </f:view> </body> </html>
  • 17. T o trang calculator.jspạ <h:panelGroup rendered="#{calculator.result != 0}"> <h4>Results</h4> <table> <tr> <td> First Number ${calculator.firstNumber} </td></tr> <tr> <td> Second Number ${calculator.secondNumber} </td> </tr> <tr><td> Result ${calculator.result} </td></tr> </table> </h:panelGroup> </f:view> </body> </html>
  • 18. Các th JSFẻ <f:view> </f:view> <h:form id=""> </h:form> <h:outputLabel value="" for="" /> <h:inputText id="" value="" required="true" /> <h:message for="" /> <h:commandButton action="" value="" /> <h:panelGroup></h:panelGroup>
  • 19. <h:panelGrid S d ng <h:panelGrid> đ hi n th d li u d ngử ụ ể ể ị ữ ệ ạ b ng.ả Không th thêm HTML vào m t <h:panelGrid>.ể ộ
  • 20. T o trang calculator.jspạ -ph nầ nh pậ //T p tin. /src/main/webapp/calculator.jspậ <?xml version="1.0" encoding="ISO-8859-1" ?> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Calculator Application</title> </head> <body> <h:form id="calcForm"> <h4>Calculator</h4>
  • 21. T o trang calculator.jsp-phạ nầ nh pậ <h:panelGrid columns="3"> <%-- First Number--%> <h:outputLabel value="First Number" for="firstNumber" /> <h:inputText id="firstNumber" value="#{calculator.firstNumber}" required="true" /> <h:message for="firstNumber" /> <%-- Second Number--%> <h:outputLabel value="Second Number" for="secondNumber" /> <h:inputText id="secondNumber" value="#{calculator.secondNumber}" required="true"/> <h:message for="secondNumber" /> </h:panelGrid> <div> <h:commandButton action="#{calculator.add}" value="Add" /> <h:commandButton action="#{calculator.multiply}" value="Multiply" /> <h:commandButton action="#{calculator.clear}" value="Clear" immediate="true"/> </div> </h:form>
  • 22. T o trang calculator.jsp-phạ n k t quầ ế ả <h:panelGroup rendered="#{calculator.result != 0}"> <h4>Results</h4> <h:panelGrid columns="1"> <h:outputText value="First Number #{calculator.firstNumber}"/> <h:outputText value="Second Number #{calculator.secondNumber}"/> <h:outputText value="Result #{calculator.result}"/> </h:panelGrid> </h:panelGroup> </f:view> </body> </html>
  • 23. Đ nh ki u cho PanelGridị ể //T p tin. /src/main/webapp/calculator.jspậ <?xml version="1.0" encoding="ISO-8859-1" ?> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Calculator Application</title> <link rel="stylesheet" type="text/css“ href="<%=request.getContextPath()%>/css/main.css" /> </head> <body> <h:form id="calcForm"> <h4>Calculator</h4>
  • 24. CSS cho PanelGrid oddRow { background-color: white; } evenRow { background-color: silver; } formGrid { border: solid #000 3px; width: 400px; } resultGrid { border: solid #000 1px; width: 200px; } /css/main.css
  • 25. S d ng CSS, thông báoử ụ <h:panelGrid columns="3“ rowClasses="oddRow, evenRow" styleClass="formGrid"> <%-- First Number--%> <h:outputLabel value="First Number" for="firstNumber" /> <h:inputText id="firstNumber" value="#{calculator.firstNumber}" required="true“ label="First Number"/> <h:message for="firstNumber" /> <%-- Second Number--%> <h:outputLabel value="Second Number" for="secondNumber" /> <h:inputText id="secondNumber" value="#{calculator.secondNumber}" required="true“ label=“Second Number"/> <h:message for="secondNumber" /> </h:panelGrid> <div> <h:commandButton action="#{calculator.add}" value="Add" /> <h:commandButton action="#{calculator.multiply}" value="Multiply" /> <h:commandButton action="#{calculator.clear}" value="Clear" immediate="true"/> </div> </h:form>
  • 26. S d ng CSSử ụ <h:panelGroup rendered="#{calculator.result != 0}"> <h4>Results</h4> <h:panelGrid columns="1“ rowClasses="oddRow, evenRow" styleClass="resultGrid"> <h:outputText value="First Number #{calculator.firstNumber}"/> <h:outputText value="Second Number #{calculator.secondNumber}"/> <h:outputText value="Result #{calculator.result}"/> </h:panelGrid> </h:panelGroup> </f:view> </body> </html>
  • 27. Hi n th thông báo tóm t tể ị ắ <h:panelGrid columns="3“ rowClasses="oddRow, evenRow" styleClass="formGrid"> <%-- First Number--%> <h:outputLabel value="First Number" for="firstNumber" /> <h:inputText id="firstNumber" value="#{calculator.firstNumber}" required="true”> <h:message for="firstNumber" showSummary="true" showDetail="false"/> <%-- Second Number--%> <h:outputLabel value="Second Number" for="secondNumber" /> <h:inputText id="secondNumber" value="#{calculator.secondNumber}" required="true“ label=“Second Number"/> <h:message for="secondNumber" /> </h:panelGrid> <div> <h:commandButton action="#{calculator.add}" value="Add" /> <h:commandButton action="#{calculator.multiply}" value="Multiply" /> <h:commandButton action="#{calculator.clear}" value="Clear" immediate="true"/> </div> </h:form>
  • 28. Vi t đè lên n i dung thông báoế ộ <h:panelGrid columns="3“ rowClasses="oddRow, evenRow" styleClass="formGrid"> <%-- First Number--%> <h:outputLabel value="First Number" for="firstNumber" /> <h:inputText id="firstNumber" value="#{calculator.firstNumber}" required="true“ label="First Number“ requiredMessage="required" converterMessage="not a valid" /> <h:message for="firstNumber" /> <%-- Second Number--%> <h:outputLabel value="Second Number" for="secondNumber" /> <h:inputText id="secondNumber" value="#{calculator.secondNumber}" required="true“ label=“Second Number"/> <h:message for="secondNumber" /> </h:panelGrid> <div> <h:commandButton action="#{calculator.add}" value="Add" /> <h:commandButton action="#{calculator.multiply}" value="Multiply" /> <h:commandButton action="#{calculator.clear}" value="Clear" immediate="true"/> </div> </h:form>
  • 29. Thay đ i thông báo toàn c cổ ụ <?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_1_2.xsd" version="1.2"> <application> <message-bundle>messages</message-bundle> </application> ...
  • 30. T o t p messages.propertiesạ ệ javax.faces.component.UIInput.REQUIRED_detail=required javax.faces.converter.IntegerConverter.INTEGER_detail=not a valid number