Por admin | Para la categoría de jsf (java server faces) | noticia del 15-07-2010
Para la versión jsf 1.2 de este framework
Sitio oficial para descarga de los jars https://facelets.dev.java.net/
Sitio oficial con documentación para desarrolladores https://facelets.dev.java.net/nonav/docs/dev/docbook.html
modificación del archivo faces-config.xml para la visualización
1 2 3 | <application> <view-handler>com.sun.facelets.FaceletViewHandler</view-handler> </application> |
modificación del fichero web.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <context-param> <param-name>facelets.DEVELOPMENT</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param> <welcome-file-list> <welcome-file>index.xhtml</welcome-file> </welcome-file-list> |
modificamos el sufijo por defecto de las páginas de jsf a .xhtml
los facelets nos permiten crear plantillas en jsf de una forma rápida y comoda al cambiar el manejador de las vistas todas nuestras jsp tienen que ser renombradas a xhtml pero no es obligatorio
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 | <!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:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"> <head> <link rel="stylesheet" href="../../css/estilo.css" type="text/css"/> <ui:insert name="titulo"/> </head> <body> <div id="contenedor"> <div id="cabecera"> <h2><ui:insert name="cabecera"/></h2> </div> <div id="contenido"> <ui:insert name="contenido"/> </div> <div id="pie"> <ui:insert name="pie"/> </div> </div> </body> </html> |
Código de un cliente para la plantilla clienteplantilla.xhtml
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 | <!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:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"> <ui:composition template="plantillasimple.xhtml"> <ui:define name="cabecera"> <h:outputText value="Ejemplo simple con facelets"/> </ui:define> <ui:define name="contenido"> <h:outputText value="cuerpo de la aplicación"/> </ui:define> <ui:define name="pie"> <p><h:outputText value="www.railsymas.com"/></p> </ui:define> </ui:composition> </html> |
Resultado

