Está en la página 1de 5

Ing.

Ricardo Inquilla Quispe Cel: 952639757


Universidad Peruana
SIMON BOLIVAR


1

Taller de Desarrollo I
INTRODUCCI0N A JAVA SERVER FACES
Objetivos
Utilizar el JSF
PRIMER PROYECTO
1. La estructura de nuestro proyecto tendr la siguiente apariencia
2. Seleccionamos la opcin File > Dynamic Web Project luego
ingresamos el nombre del proyecto: jsf001 y seleccionamos la siguiente
configuracin


3. Hacemos click en el botn observamos la siguiente ventana y hacemos click
en


4. Seleccionamos la siguiente opcin para crear el archivo web.xml y hacemos click en


5. Obtenemos la siguiente configuracin y hacemos click en el botn Finish
Ing. Ricardo Inquilla Quispe Cel: 952639757
Universidad Peruana
SIMON BOLIVAR


2

Taller de Desarrollo I


6. Agregamos las libreras bsicas del JSF


7. Configurar el Faces Servlet en el archivo web.xml dentro de la carpeta WEB-INF del
webContent

<?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" id="WebApp_ID" version="3.0">
<display-name>jsf001</display-name>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
Ing. Ricardo Inquilla Quispe Cel: 952639757
Universidad Peruana
SIMON BOLIVAR


3

Taller de Desarrollo I
<servlet-class>javax.faces.weba pp.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>
</web-app>

8. Implementamos ManagedBean FormularioBean en el paquete pe.edu.cibertec.managed
package pe.edu.cibertec.managed;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
@ManagedBean(name = "formulario")
public class FormularioBean {
private String nombre;
private String apellido;
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getApellido() {
return apellido;
}
public void setApellido(String apellido) {
this.apellido = apellido;
}
public String procesar() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Su nombre
completo es: ".concat(getNombre()).concat(" ").concat(getApellido())));
return "resultado"; // Resultado => formulario xhtml
}
}

9. Creamos las paginas XHTML
a. Inicio.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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
Ing. Ricardo Inquilla Quispe Cel: 952639757
Universidad Peruana
SIMON BOLIVAR


4

Taller de Desarrollo I
<h:head>
</h:head>
<h:body>
<h:form>
<h:commandLink value="Iniciar" action="formulario" />
</h:form>
</h:body>
</html>
b. Formulario.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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Nombre" />
<h:inputText value="#{formulario.nombre}" />

<h:outputLabel value="Apellido" />
<h:inputText value="#{formulario.apellido}" />

<h:commandButton value="Procesar" action="#{formulario.procesar}" />

<h:commandButton value="Continuar" action="final" />
</h:panelGrid>
</h:form>
</h:body>
</html>
c. Resultado.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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
</h:head>
<h:body>

<h:messages />
Ing. Ricardo Inquilla Quispe Cel: 952639757
Universidad Peruana
SIMON BOLIVAR


5

Taller de Desarrollo I

</h:body>
</html>
d. Final.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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
</h:head>
<h:body>

<h:outputText value="Gracias por su visita #{formulario.nombre}" />

</h:body>
</html>

10. Ejecutamos la Aplicacin

También podría gustarte