JSF Relocatable Resources

JSF Facelets Relocatable Resources example for beginners and professionals with examples on life cycle, managed beans, ui components, ui tags, validation, bean validation, datatable, converters, facelets etc.

JSF Relocatable Resources

JSF Relocatable Resources

JSF provides a facility to place your resources at any section of your web page and render it to another section. . You can relocate your resource by specifying target attribute.

You can pass following attributes to relocate in the target attribute.

head: It is used to render the resource in head section.

body: It is used to render the resource in the body section,

form: It is used to render the resource in the form section.


JSF Relocatable Resources Example

In the following example, we have placed JavaScript file inside the form tag and specified target to head section.

// index.xhtml

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml"  
  3. xmlns:h="http://xmlns.jcp.org/jsf/html">  
  4. <h:head>  
  5. <title>Web Resources Example</title>  
  6. </h:head>  
  7. <h:body>  
  8. <h:form>  
  9. <h:outputScript  library="js" name="test.js" target="head"/>  
  10. </h:form>  
  11. </h:body>  
  12. </html>