SlideShare a Scribd company logo
1 of 25
Download to read offline
Java Server Faces 2.2	

PrimeFaces 4.0	

Servlet 3.0	

Maven
java web
Mario Jorge Pereira
14

20

13

20

12

20

11

20

10

20

09

20

08

20

07

20

06

20

05

20

04

20

03

20

02

20
Agenda
• Maven	

• Servlet 3.0	

• Java Server Faces - JSF 2.2	

• PrimeFaces - Prime 4.0
File > New > Other…
Skip archetype selection
br.com.mariojp.labjsf
Project > Properties > Project Facets
Runtime

são
Ver
et e
Fac
<project 	
xmlns="http://maven.apache.org/POM/4.0.0" 	
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"	
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">	
	 <modelVersion>4.0.0</modelVersion>	
	 <groupId>br.com.mariojp</groupId>	
	 <artifactId>labjsf</artifactId>	
	 <version>0.0.1-SNAPSHOT</version>	
	 <name>labjsf</name>	
	 <packaging>war</packaging>	
</project>

pom.xml
adicionando jsf 2.2 e servlet 3.0

<project ... >	
...	
	 <dependencies>	
	 	 <dependency>	
	 	 	 <groupId>com.sun.faces</groupId>	
	 	 	 <artifactId>jsf-api</artifactId>	
	 	 	 <version>2.2.2</version>	
	 	 </dependency>	
	 	 <dependency>	
	 	 	 <groupId>com.sun.faces</groupId>	
	 	 	 <artifactId>jsf-impl</artifactId>	
	 	 	 <version>2.2.2</version>	
	 	 </dependency>	
	 	 <dependency>	
	 	 	 <groupId>javax.servlet</groupId>	
	 	 	 <artifactId>javax.servlet-api</artifactId>	
	 	 	 <version>3.0.1</version>	
	 	 </dependency>	
	 </dependencies>	
</project>

pom.xml
adicionando commons-fileupload

<project ... >	
...	
	 <dependencies>	
...	
	 	 <dependency>	
	 	 	 <groupId>commons-fileupload</groupId>	
	 	 	 <artifactId>commons-fileupload</artifactId>	
	 	 	 <version>1.3</version>	
	 	 </dependency>	
	 </dependencies>	
</project>

pom.xml
adicionando primefaces

<project ... >	
...	
	 <dependencies>	
...	
	 	 <dependency>	
	 	 	 <groupId>org.primefaces.themes</groupId>	
	 	 	 <artifactId>all-themes</artifactId>	
	 	 	 <version>1.0.10</version>	
	 	 </dependency>	
	 	 <dependency>	
	 	 	 <groupId>org.primefaces</groupId>	
	 	 	 <artifactId>primefaces</artifactId>	
	 	 	 <version>4.0</version>	
	 	 </dependency>	
	 <repositories>	
	 	 <repository>	
	 	 	 <id>prime-repo</id>	
	 	 	 <name>PrimeFaces Maven Repository</name>	
	 	 	 <url>http://repository.primefaces.org</url>	
	 	 	 <layout>default</layout>	
	 	 </repository>	
	 </repositories>	
</project>

pom.xml
Mapeando o Servlet do JSF
<?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">	
<display-name>labjsf</display-name>	
<servlet>	
<servlet-name>Faces Servlet</servlet-name>	
<servlet-class>javax.faces.webapp.FacesServlet</servletclass>	
<load-on-startup>1</load-on-startup>	
</servlet>	
<servlet-mapping>	
<servlet-name>Faces Servlet</servlet-name>	
<url-pattern>*.jsf</url-pattern>	
</servlet-mapping>	
... 	
</web-app>

web.xml
Outras configurações
<?xml version="1.0" encoding="UTF-8"?>	
<web-app ...>	
...	
	<context-param>	
	 	 <param-name>primefaces.THEME</param-name>	
	 	 <param-value>bootstrap</param-value>	
	 </context-param>	
	 	
	 <welcome-file-list>	
	 	 <welcome-file>index.jsf</welcome-file>	
	 </welcome-file-list>	
!

	 <session-config>	
	 	 <session-timeout>30</session-timeout>	
	 </session-config>	
</web-app>

web.xml
<?xml version='1.0' encoding='UTF-8' ?>	
<!DOCTYPE html >	
<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" >	
<f:view locale="en">	
	 <h:head>	
	 	 <title>JSF</title>	
	 	 <h:outputScript library="javax.faces" name="jsf.js" target="head" />	
	 </h:head>	
	 <h:body>	
	 	 <h4>JSF</h4>	
	 	 <h:form id="jsfForm">	
	 	 	 <h:inputText id="nome" value="#{mainController.nome}" />	
	 	 	 <h:commandButton value="Exibir">	
	 	 	 	 <f:ajax execute="nome" render=":jsfForm:nameGroup" />	
	 	 	 </h:commandButton>	
	 	 	 <br />	
	 	 	 <h:panelGroup id="nameGroup">	
	 	 	 	 <h:outputText value="Oi! #{mainController.nome}!!"	
	 	 	 	 	 rendered="#{not empty mainController.nome}" />	
	 	 	 </h:panelGroup>	
	 	 </h:form>	

!
	 </h:body>	
</f:view>	
</html>

index.xhtml
@ManagedBean	
@ViewScoped	
public class MainController implements Serializable {	
!

	 private String nome;	
!
!

	 public String getNome() {	
	 	 return nome;	
	 }	
!

	 public void setNome(String nome) {	
	 	 this.nome = nome;	
	 }	
!

}

br.com.mariojp.view.MainController.java
<?xml version='1.0' encoding='UTF-8' ?>	
<!DOCTYPE html >	
<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">	
<f:view locale="en">	
	 <h:head>	
	 	 <title>PrimeFaces</title>	
	 	 <h:outputScript library="javax.faces" name="jsf.js" target="head" />	
	 </h:head>	
	 <h:body>	
	 	 <h4>PrimeFaces</h4>	
	 	 <h:form id="jsfForm">	
	 	 	 <p:inputText id="nome" value="#{mainController.nome}" >	
	 	 	 	 <p:ajax event="keyup" process="@this" update=":jsfForm:nameGroup" />	
	 	 	 </p:inputText>	
	 	 	 <br />	
	 	 	 <h:panelGroup id="nameGroup">	
	 	 	 	 <h:outputText value="OI! #{mainController.nome}!!"	
	 	 	 	 	 rendered="#{not empty mainController.nome}" />	
	 	 	 </h:panelGroup>	
	 	 </h:form>	
	 </h:body>	
</f:view>	
</html>	

index2.xhtml
@ManagedBean	
@SessionScoped	
public class LoginController implements Serializable

{	

!
	
	
	

private static final long serialVersionUID = 1L;	
private String usuario;	
private String senha;	

!
	
	
	

public String getUsuario() {	
	 return usuario;	
}	

!
	
	
	

public void setUsuario(String usuario) {	
	 this.usuario = usuario;	
}	

!
	
	
	

public String getSenha() {	
	 return senha;	
}	

!
	
	
	

public void setSenha(String senha) {	
	 this.senha = senha;	
}	

!
	
	
	

!
}	

public String autenticar() {
	 return "home"; 	
} 	

	

LoginController.java
<?xml version='1.0' encoding='UTF-8' ?>	
<!DOCTYPE html >	
<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">	
<f:view locale="en">	
	
<h:head>	
	
	
<title>Login</title>	
	
	
<h:outputScript library="javax.faces" name="jsf.js" target="head" />	
	
</h:head>	
	
<h:body>	
	
	
<h4>PrimeFaces</h4>	 	
	
	
	
<h:form id="jsfForm">	
	
	
	
<p:panel id="panel" header="Login">	
	
	
	
	
<h:panelGrid columns="3">	
	
	
	
	
	
<h:outputLabel for="usuario" value="Usuario: *" />	
	
	
	
	
	
<p:inputText id="usuario" value=“#{loginController.usuario}" required="true"
label="Usuario">	
	
	
	
	
	
	
<f:validateLength minimum="2" />	
	
	
	
	
	
</p:inputText>	
	
	
	
	
	
<p:message for="usuario" />	
	
	
	
	
	
<h:outputLabel for="senha" value="Senha: *" />	
	
	
	
	
	
<p:password id="senha" value="#{loginController.senha}"	
	
	
required="true" label="Senha">	
	
	
	
	
	
</p:password>	
	
	
	
	
	
<p:message for="senha" />	
	
	
	
	
</h:panelGrid>	
	
	
	
</p:panel>	
	
	
	
<p:commandButton value="Enviar" id="ajax" update="panel"	
	
	
	
	
action="#{loginController.autenticar}" />	
	
	
</h:form>	
	
</h:body>	
</f:view>	
</html>

t
h

l
m

lo

.x
in
g
<?xml version='1.0' encoding='UTF-8' ?>	
<!DOCTYPE html >	
<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">	
<f:view locale="en">	
	 <h:head>	
	 	 <title>Login</title>	
	 	 <h:outputScript library="javax.faces" name="jsf.js" target="head"
/>	
	 </h:head>	
	 <h:body>	
	 	 <h4>PrimeFaces</h4>	
	 	 <h:form id="jsfForm">	
	 	 	 <h:outputLabel value="#{loginController.usuario}" />	
	 	 </h:form>	
	 </h:body>	
</f:view>	
</html>

m
o
h

.x
e

l
tm
h
Esta obra está licenciada sob a licença Creative Commons
Atribuição-CompartilhaIgual 3.0 Não Adaptada. Para ver uma cópia
desta licença, visite http://creativecommons.org/licenses/by-sa/3.0/.
Java web
Mario Jorge Pereira
Como me encontrar?
http://www.mariojp.com.br
twitter.com/@mariojp
mariojp@gmail.com

More Related Content

What's hot

JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
Talha Ocakçı
 
Html servlet example
Html   servlet exampleHtml   servlet example
Html servlet example
rvpprash
 

What's hot (20)

Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component Behaviors
 
Resthub framework presentation
Resthub framework presentationResthub framework presentation
Resthub framework presentation
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
 
Jsp element
Jsp elementJsp element
Jsp element
 
JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011
 
Resthub lyonjug
Resthub lyonjugResthub lyonjug
Resthub lyonjug
 
JavaFX – 10 things I love about you
JavaFX – 10 things I love about youJavaFX – 10 things I love about you
JavaFX – 10 things I love about you
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
Html servlet example
Html   servlet exampleHtml   servlet example
Html servlet example
 
Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
 
Spring Framework - Web Flow
Spring Framework - Web FlowSpring Framework - Web Flow
Spring Framework - Web Flow
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
 
Cis 274 intro
Cis 274   introCis 274   intro
Cis 274 intro
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
 
Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course Introduction to the Servlet / JSP course
Introduction to the Servlet / JSP course
 

Similar to Java Server Faces

JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
haruki ueno
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 

Similar to Java Server Faces (20)

JavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオンJavaDo#09 Spring boot入門ハンズオン
JavaDo#09 Spring boot入門ハンズオン
 
Ajax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorialsAjax, JSF, Facelets, Eclipse & Maven tutorials
Ajax, JSF, Facelets, Eclipse & Maven tutorials
 
Jsf
JsfJsf
Jsf
 
Pom
PomPom
Pom
 
Pom configuration java xml
Pom configuration java xmlPom configuration java xml
Pom configuration java xml
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
 
Taking your Web App for a walk
Taking your Web App for a walkTaking your Web App for a walk
Taking your Web App for a walk
 
Automation Frame works Instruction Sheet
Automation Frame works Instruction SheetAutomation Frame works Instruction Sheet
Automation Frame works Instruction Sheet
 
Spring Boot and JHipster
Spring Boot and JHipsterSpring Boot and JHipster
Spring Boot and JHipster
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
vJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX Ecosystem
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Spring into rails
Spring into railsSpring into rails
Spring into rails
 
JAX-WS Basics
JAX-WS BasicsJAX-WS Basics
JAX-WS Basics
 
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
 
How to connect redis and mule esb using spring data redis module
How to connect redis and mule esb using spring data redis moduleHow to connect redis and mule esb using spring data redis module
How to connect redis and mule esb using spring data redis module
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Maven in Mule
Maven in MuleMaven in Mule
Maven in Mule
 
Training in Android with Maven
Training in Android with MavenTraining in Android with Maven
Training in Android with Maven
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 

More from Mario Jorge Pereira

More from Mario Jorge Pereira (20)

Educacao e Inteligencia Artificial Generativa
Educacao e Inteligencia Artificial GenerativaEducacao e Inteligencia Artificial Generativa
Educacao e Inteligencia Artificial Generativa
 
Labs Jogos Java
Labs Jogos JavaLabs Jogos Java
Labs Jogos Java
 
Java www
Java wwwJava www
Java www
 
Html
HtmlHtml
Html
 
HTTP
HTTPHTTP
HTTP
 
Lógica de Programação e Algoritmos
Lógica de Programação e AlgoritmosLógica de Programação e Algoritmos
Lógica de Programação e Algoritmos
 
Guia rapido java v2
Guia rapido java v2Guia rapido java v2
Guia rapido java v2
 
Guia Rápido de Referência Java
Guia Rápido de Referência JavaGuia Rápido de Referência Java
Guia Rápido de Referência Java
 
Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015
 
Java Nuvem Appengine
Java Nuvem AppengineJava Nuvem Appengine
Java Nuvem Appengine
 
Mini curso Android
Mini curso AndroidMini curso Android
Mini curso Android
 
Minicurso Android
Minicurso AndroidMinicurso Android
Minicurso Android
 
Android, por onde começar?
Android, por onde começar?Android, por onde começar?
Android, por onde começar?
 
Hands-On Java web passando por Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...
Hands-On Java web passando por  Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...Hands-On Java web passando por  Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...
Hands-On Java web passando por Servlets, JSP, JSTL, JDBC, Hibernate, DAO, MV...
 
Android e Cloud Computing
Android e Cloud ComputingAndroid e Cloud Computing
Android e Cloud Computing
 
Threads
ThreadsThreads
Threads
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation) RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 
Socket
SocketSocket
Socket
 
Java e Cloud Computing
Java e Cloud ComputingJava e Cloud Computing
Java e Cloud Computing
 
GUI - Eventos
GUI - EventosGUI - Eventos
GUI - Eventos
 

Recently uploaded

Recently uploaded (20)

How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptxREPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
Behavioral-sciences-dr-mowadat rana (1).pdf
Behavioral-sciences-dr-mowadat rana (1).pdfBehavioral-sciences-dr-mowadat rana (1).pdf
Behavioral-sciences-dr-mowadat rana (1).pdf
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
 
Essential Safety precautions during monsoon season
Essential Safety precautions during monsoon seasonEssential Safety precautions during monsoon season
Essential Safety precautions during monsoon season
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdfPost Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 

Java Server Faces

  • 1. Java Server Faces 2.2 PrimeFaces 4.0 Servlet 3.0 Maven
  • 2.
  • 5. Agenda • Maven • Servlet 3.0 • Java Server Faces - JSF 2.2 • PrimeFaces - Prime 4.0
  • 6. File > New > Other…
  • 9. Project > Properties > Project Facets
  • 11. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>br.com.mariojp</groupId> <artifactId>labjsf</artifactId> <version>0.0.1-SNAPSHOT</version> <name>labjsf</name> <packaging>war</packaging> </project> pom.xml
  • 12. adicionando jsf 2.2 e servlet 3.0 <project ... > ... <dependencies> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> </dependency> </dependencies> </project> pom.xml
  • 13. adicionando commons-fileupload <project ... > ... <dependencies> ... <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3</version> </dependency> </dependencies> </project> pom.xml
  • 14. adicionando primefaces <project ... > ... <dependencies> ... <dependency> <groupId>org.primefaces.themes</groupId> <artifactId>all-themes</artifactId> <version>1.0.10</version> </dependency> <dependency> <groupId>org.primefaces</groupId> <artifactId>primefaces</artifactId> <version>4.0</version> </dependency> <repositories> <repository> <id>prime-repo</id> <name>PrimeFaces Maven Repository</name> <url>http://repository.primefaces.org</url> <layout>default</layout> </repository> </repositories> </project> pom.xml
  • 15. Mapeando o Servlet do JSF <?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"> <display-name>labjsf</display-name> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servletclass> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> ... </web-app> web.xml
  • 16. Outras configurações <?xml version="1.0" encoding="UTF-8"?> <web-app ...> ... <context-param> <param-name>primefaces.THEME</param-name> <param-value>bootstrap</param-value> </context-param> <welcome-file-list> <welcome-file>index.jsf</welcome-file> </welcome-file-list> ! <session-config> <session-timeout>30</session-timeout> </session-config> </web-app> web.xml
  • 17. <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html > <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" > <f:view locale="en"> <h:head> <title>JSF</title> <h:outputScript library="javax.faces" name="jsf.js" target="head" /> </h:head> <h:body> <h4>JSF</h4> <h:form id="jsfForm"> <h:inputText id="nome" value="#{mainController.nome}" /> <h:commandButton value="Exibir"> <f:ajax execute="nome" render=":jsfForm:nameGroup" /> </h:commandButton> <br /> <h:panelGroup id="nameGroup"> <h:outputText value="Oi! #{mainController.nome}!!" rendered="#{not empty mainController.nome}" /> </h:panelGroup> </h:form> ! </h:body> </f:view> </html> index.xhtml
  • 18. @ManagedBean @ViewScoped public class MainController implements Serializable { ! private String nome; ! ! public String getNome() { return nome; } ! public void setNome(String nome) { this.nome = nome; } ! } br.com.mariojp.view.MainController.java
  • 19. <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html > <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"> <f:view locale="en"> <h:head> <title>PrimeFaces</title> <h:outputScript library="javax.faces" name="jsf.js" target="head" /> </h:head> <h:body> <h4>PrimeFaces</h4> <h:form id="jsfForm"> <p:inputText id="nome" value="#{mainController.nome}" > <p:ajax event="keyup" process="@this" update=":jsfForm:nameGroup" /> </p:inputText> <br /> <h:panelGroup id="nameGroup"> <h:outputText value="OI! #{mainController.nome}!!" rendered="#{not empty mainController.nome}" /> </h:panelGroup> </h:form> </h:body> </f:view> </html> index2.xhtml
  • 20. @ManagedBean @SessionScoped public class LoginController implements Serializable { ! private static final long serialVersionUID = 1L; private String usuario; private String senha; ! public String getUsuario() { return usuario; } ! public void setUsuario(String usuario) { this.usuario = usuario; } ! public String getSenha() { return senha; } ! public void setSenha(String senha) { this.senha = senha; } ! ! } public String autenticar() { return "home"; } LoginController.java
  • 21. <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html > <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"> <f:view locale="en"> <h:head> <title>Login</title> <h:outputScript library="javax.faces" name="jsf.js" target="head" /> </h:head> <h:body> <h4>PrimeFaces</h4> <h:form id="jsfForm"> <p:panel id="panel" header="Login"> <h:panelGrid columns="3"> <h:outputLabel for="usuario" value="Usuario: *" /> <p:inputText id="usuario" value=“#{loginController.usuario}" required="true" label="Usuario"> <f:validateLength minimum="2" /> </p:inputText> <p:message for="usuario" /> <h:outputLabel for="senha" value="Senha: *" /> <p:password id="senha" value="#{loginController.senha}" required="true" label="Senha"> </p:password> <p:message for="senha" /> </h:panelGrid> </p:panel> <p:commandButton value="Enviar" id="ajax" update="panel" action="#{loginController.autenticar}" /> </h:form> </h:body> </f:view> </html> t h l m lo .x in g
  • 22. <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html > <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"> <f:view locale="en"> <h:head> <title>Login</title> <h:outputScript library="javax.faces" name="jsf.js" target="head" /> </h:head> <h:body> <h4>PrimeFaces</h4> <h:form id="jsfForm"> <h:outputLabel value="#{loginController.usuario}" /> </h:form> </h:body> </f:view> </html> m o h .x e l tm h
  • 23.
  • 24. Esta obra está licenciada sob a licença Creative Commons Atribuição-CompartilhaIgual 3.0 Não Adaptada. Para ver uma cópia desta licença, visite http://creativecommons.org/licenses/by-sa/3.0/.
  • 25. Java web Mario Jorge Pereira Como me encontrar? http://www.mariojp.com.br twitter.com/@mariojp mariojp@gmail.com