Facelet param Tag

Facelet param Tag is used to pass objects as variables between facelets. This tag has two required attributes name and value.

Facelet param Tag

Facelet param Tag

        

This tag is used to pass objects as variables between facelets. This tag has two required attributes name and value. name attribute is the name of the variable and the value attribute is to set the value of this variable. You can use this tag where a define tag is used within composition or decorate tag. We can also use this tag within include tag.  In this example, we have taken two variables user and pwd within include tag in debug.xhtml and values are set through bean's properties userid and password. These variable are passed to the "includeparampage.xhtml"  where we can use these variables in this line of code "Your #{user} and #{pwd} will not be disclosed".

Code Description : 

debug.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/param/paramtemplate.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:define name="face5">
  <ui:include src="includeparampage.xhtml">
   <ui:param name="user" value="#{MessageBean.userid}"/>
   <ui:param name="pwd" value="#{MessageBean.password}"/>

  </ui:include>
  </ui:define>
   </ui:composition>
   Content below composition tag will not be rendered.
</body>
</html>

 debugtemplate.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"></ui:insert>
</body>
</html>

 includeparampage.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">

<ui:composition>
<br/><br/><h3>Your #{user} and #{pwd} will not be disclosed.</h3>
</ui:composition>

</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" />
  <br /><br /><h3>Your ID and Password will not be disclosed.</h3>
</body>
</html>

 This tag contains two attributes :

name : This is required attribute and is used to specify the name of the variable to be passed to other facelet.
value :
This is required attribute to set the value of the variable specified by the name attribute.