Facelets

13
Facelets Diego Armando Gómez M [email protected]

Transcript of Facelets

Page 1: Facelets

Facelets  Diego  Armando  Gómez  M  [email protected]  

 

Page 2: Facelets

Introducción  

•  JavaServer   Facelets   es   un   framework   para  plan5llas   (templates)   centrado   en   la  tecnología   JSF   (JavaServer   Faces),   por   lo   cual  se  integran  de  manera  muy  fácil.  

Page 3: Facelets

Introducción  

•  Caracterís5cas  :  –  Tiempo  de  desarrollo  cero  de  tags  para  UIComponents.  –  Facilidad  en  la  creación  del  templa5ng  para  los  componentes  y  páginas.  

–  Es  posible  separar  los  UIComponents  en  diferentes  archivos.  

–  Soporte  completo  a  EL  (Expression  Language).  –  No  es  necesaria  configuración  XML.  –  Trabaja  con  cualquier  RenderKit.  

Page 4: Facelets

Porque  usar  Facelets  •  Independiente  del  contenedor  Web  (Tomcat,  JeTy,  GlassFish,  Jboss,  etc)  •  Facelets  provee  un  proceso  de  compilación  más  rápido  que  JSP.  •  Provee  templa5ng,  lo  cual  implica  reu5lización  de  código,  simplificación  

de  desarrollo  y  facilidad  en  el  mantenimiento  de  grandes  aplicaciones.  •  Permite  crear  componentes  ligeros  sin  necesidad  de  crear  los  tags  de  los  

UIComponents  (es  más  fácil  comparado  a  crear  un  componente  JSF  puro).  •  Soporta  Unified  Expression  Language,  incluyendo  soporte  para  funciones  

EL  y  validación  de  EL  en  5empo  de  compilación.  •  Es  posible  conver5r  template  en  HTML5  fácilmente.  •  En  Facelets,  las  páginas  son  XTHML  •  Facelets  permite  incluir  texto,  e5quetas  y  expresiones  en  cualquier  zona  

de  la  página,  y  se  encargará  de  evaluarlo.  

Page 5: Facelets

Configuración  Maven  •  Solo  se  debe  descargar  el  jar  de  primefaces-­‐{version}.jar  y  la  impelemtacion  de  referencia  de  jsf,  en  este  caso  mojarra  2.2.9  Maven  

<!-­‐-­‐  Primefaces  -­‐-­‐>      <dependency>        <groupId>org.primefaces</groupId>        <ar9factId>primefaces</ar9factId>        <version>5.1</version>      </dependency>      <!-­‐-­‐  Primefaces  à          <dependency>        <groupId>org.glassfish</groupId>        <ar9factId>javax.faces</ar9factId>        <version>2.2.9</version>      </dependency>  

Page 6: Facelets

Configuración  web.xml  <?xml  version="1.0"  encoding="UTF-­‐8"?>  <web-­‐app  version="3.0"                    xmlns="hNp://java.sun.com/xml/ns/javaee"                    xmlns:xsi=hNp://www.w3.org/2001/XMLSchema-­‐instance    xsi:schemaLoca9on="hNp://java.sun.com/xml/ns/javaee  hNp://java.sun.com/xml/ns/javaee/web-­‐app_3_0.xsd"  >          <display-­‐name>demoFacelets</display-­‐name>      <welcome-­‐file-­‐list>          <welcome-­‐file>index.xhtml</welcome-­‐file>      </welcome-­‐file-­‐list>      <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-­‐paTern>/faces/*</url-­‐paTern>      </servlet-­‐mapping>          <servlet-­‐mapping>          <servlet-­‐name>Faces  Servlet</servlet-­‐name>          <url-­‐paTern>*.xhtml</url-­‐paTern>      </servlet-­‐mapping>  </web-­‐app>  

Page 7: Facelets

header.xhtml  <jsp:root  jsfc="f:view"  xmlns:jsp="hNp://java.sun.com/JSP/Page"          xmlns:f="hNp://java.sun.com/jsf/core"          xmlns:h="hNp://java.sun.com/jsf/html"          xmlns:ui="hNp://java.sun.com/jsf/facelets"          xmlns:c="hNp://java.sun.com/jstl/core"          xmlns:p="hNp://primefaces.org/ui"          xmlns:fn="hNp://java.sun.com/jsp/jstl/func9ons">              <html>  

   <body>        <f:view>          <ui:composi9on>                                      <h1>El  encabezado  de  mi  si9o  Web</h1>                            <p>Esto  es  un  template  con  facelets</p>          </ui:composi9on>        </f:view>      </body>    </html>  

</jsp:root>  

Page 8: Facelets

footer.xhtml  

<jsp:root  jsfc="f:view"  xmlns:jsp="hNp://java.sun.com/JSP/Page"    xmlns:f="hNp://java.sun.com/jsf/core"    xmlns:h="hNp://java.sun.com/jsf/html"    xmlns:ui="hNp://java.sun.com/jsf/facelets"    xmlns:c="hNp://java.sun.com/jstl/core"    xmlns:fn="hNp://java.sun.com/jsp/jstl/func9ons">    <html>      <body>        <f:view>          <ui:composi9on>                      <h3>Esta  es  la  parte  inferior</h3>                </ui:composi9on>        </f:view>      </body>    </html>  

</jsp:root>  

Page 9: Facelets

template.xhtml  <html  xmlns="hNp://www.w3.org/1999/xhtml"  

 xmlns:h="hNp://java.sun.com/jsf/html"    xmlns:ui="hNp://java.sun.com/jsf/facelets">      <h:head>  

                               <5tle>.::Titulo  de  mi  app  web::.</5tle>                                            </h:head>    

 <h:body>            <ui:insert  name="header">            <ui:include  src="/WEB-­‐INF/facelets/header.xhtml"  />        </ui:insert>                <ui:insert  name="body"/>              <ui:insert  name="footer">            <ui:include  src="/WEB-­‐INF/facelets/footer.xhtml"  />        </ui:insert>        </h:body>  

</html>  

Page 10: Facelets

index.xhtml  <html  xmlns="hNp://www.w3.org/1999/xhtml"  

 xmlns:h="hNp://java.sun.com/jsf/html"    xmlns:p="hNp://primefaces.org/ui"    xmlns:f="hNp://java.sun.com/jsf/core"    xmlns:ui="hNp://java.sun.com/jsf/facelets">        <h:head>      <meta  hTp-­‐equiv="Content-­‐Type"  content="text/html;  charset=UTF-­‐8"/>    </h:head>            <h:body>      <ui:composi5on  template="/WEB-­‐INF/facelets/template.xhtml">          <ui:define  name="body">            <f:view>            <p:keyboard  id="default"  />          </f:view>        </ui:define>          </ui:composi5on>      </h:body>    

</html>    

Page 11: Facelets

Enlaces  

•  hTp://docs.oracle.com/javaee/6/tutorial/doc/gijtu.html  

•  hTp://www.mkyong.com/jsf2/jsf-­‐2-­‐templa5ng-­‐with-­‐facelets-­‐example/  

Page 12: Facelets

Información  de  contacto  

•  Si5o  Web:  www.vortexbird.com  •  Blog:  hTp://blog.vortexbird.com  •  Zathuracode:  www.zathuracode.org  •  Contacto  vía  mail:  [email protected]  •  Teléfonos:  +57    -­‐  (316  482  4629)  

Page 13: Facelets