Home Jsf Facelet insert Tag
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Facelet insert Tag

Advertisement
Facelet insert Tag is used to replace the content defined in another facelet to the template.

Facelet insert Tag

        

This tag is used to replace the content defined in another facelet to the template. This tag takes one attribute that is not a required attribute and is used in conjunction with define tag. If you set this attribute same as defined in define tag then that content within define tag will be included. If it doesn't match then the content specified within opening and closing tag of this insert tag will be displayed. For example, in the code below in "insert.xhtml" there is not any define tag whose name attribute value is "face5" and this value is used in the second file "inserttemplate.xhtml". So the content ("This is the default text rendered") specified within opening and closing tag of insert tag is displayed. While there is one insert tag whose value of name attribute ("face1") matches with that of define tag, so the content "RoseIndia Facelet Tags Tutorial" and "Welcome to the Facelet world.........." will be replaced to the insert tag.

insert.xhtml : 
 

<!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">
<body>
  Content above composition tag will not be rendered.
   <ui:composition template="/pages/insert/inserttemplate.xhtml">
   <ui:define name="face1">
   <center><h2>RoseIndia Facelet Tags Tutorial</h2></center>
   <h3>Welcome to the Facelet world..........</h3>
  </ui:define>
  <ui:define name="face2">Enter UserID :<br/>
   <h:inputText id="it" /><br/><br/>
   </ui:define>
   <ui:define name="face3">Enter Password :<br/>
   <h:inputSecret id="is" /><br/><br/>
   </ui:define>
  <ui:define name="face4">
   <h:commandButton id="cb" value="Submit" />
  </ui:define>
   </ui:composition>
   Content below composition tag will not be rendered.
</body>
</html>

 inserttemplate.xhtml :

<!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">
<head>
   <title>facelet example </title>
  <link href="../../style/CSS.css" rel="stylesheet" type="text/css"/>
</head>
<body> 
  <ui:insert name="face1"> </ui:insert>
  <ui:insert name="face2"> </ui:insert>
  <ui:insert name="face3"> </ui:insert>
  <ui:insert name="face4"> </ui:insert>
  <ui:insert name="face5"><h3>This is the default text rendered</h3> </ui:insert>
</body>
</html>

 Rendered Output :

Html Source Code :

<!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">
<head>
   <title>facelet example </title>
   <link href="../../style/CSS.css" rel="stylesheet" type="text/css" />
</head>
<body>
   <center><h2>RoseIndia Facelet Tags Tutorial</h2></center>
  <h3>Welcome to the Facelet world..........</h3>
   Enter UserID :<br /><input id="it" type="text" name="it" /><br /><br />
   Enter Password :<br /><input id="is" type="password" name="is" 
   value="" /><br /><br />
   <input id="cb" type="submit" name="cb" value="Submit" />
   <h3>This is the default text rendered</h3>
</body>
</html>

 This tag contains only one attribute :

name : This attribute is used to give the name of  the content to be included in template. This value of name attribute must be same as name attribute in define tag. If name value specified here doesn't match with any name attribute specified in define tag then the content specified within opening and closing tag of this insert tag will be displayed. This has been explained in the above example.  

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 22, 2007

Ask Questions?    Discuss: Facelet insert Tag  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Jhonathan
September 27, 2011
Page Empty

First, sorry for my english. I'm with JBoss Tools on Eclipse Indigo and a Richfaces 4 project. But when I tried to make it tha same thing, the page in browser is empty and nothing in the server log.
DMCA.com