11. What is immediate attribute in JSF ?

Suppose you want to add a Cancel button in addition to Register button to the registration page so that clicking on the Cancel button would immediately route users back to a main page regardless of what was entered in the form. If you click on Register button without entering any input to the required fields. Then you will get validation errors. Now if you click on Cancel button then you would not be able to go back to the main page because there are validation errors in the page. So you to correct all validation errors then only you can go back to the main page. Hence you require the immediate attribute that will rescue you from this situation and you can easily go back to the main page irrespective of the validation errors in the registration page.

12. What is Phase Listener in JSF ?

Phase Listeners provide a simple way to execute custom Java code at distinct points within the different phases of the lifecycle. For example, you may want to customize an error message based on a value supplied dynamically at runtime, or you may want to verify that a database connection has been established for this session ahead of processing the postback lifecycle. To add the phase listener to the JSF application, it must be registered in faces-config.xml or programmatically registered on the lifecycle instance.

13. Why facelets in JSF ?

Facelets was created to replace the use of JSP as a View Declaration Language for JSF, with the following goals in mind:

Provide a server-side templating facility that allows composing the actual view from several separate physical pages in a way that maximizes markup code reuse and eliminates redundancy among views.

Designed entirely with JSF in mind.

Provide a way to declare a JSF View using standard XHTML syntax.

Provide an extensible “tag library” feature.

Enforce clean Model-View-Controller separation by disallowing the inclusion of Java code in markup pages.

14. What are similarities and differences between facelets and jsp ?

View description concepts        facelets              jsp
Pages authored in XMLYes, XHTMLYes, the JSP XML syntax
Leverages a page compiler concept.XML is parsed into a TagHandler object tree, which is executed.XML is translated into Java, then compiled into a .class file. There is no bytecode generation
Uses the unified EL Yes Yes
Supports the concept
of tag libraries (taglibs)
 Yes Yes
Supports the concept
of tag files
 Yes Yes
Dynamic tag attributes Required Optional
Authors pages using raw HTML Yes, with jsfc attribute or TagDecorators No
Supports Faces-aware parameter passing to templated content Yes No
Expressions that reference other expressions work appropriately Yes, built in to the FaceletContext Yes, but only in JSP 2.1 and must be specified explicitly or set twice
Tag lifecycle All tag instances are stateless, only one instance of each tag per application Stateful tags are pooled
Built-in templating engine Yes No
Tags perform rendering and other display related tasksNo, tags just help to build the UIComponent tree Yes, and there is a wide variety of third-party taglibs available to help in rendering the view

15. What is template in JSF ?

There are two main perspectives in templating with Facelets: the template file and the template client file. The template client is the file whose name actually corresponds to a viewId, such as login.xhtml. The template client employs one or more template files to achieve reuse of page content.

16. What is <ui:composition/> tag in JSF ?

<ui:composition template=”optionalTemplate”>

The ui:composition tag is used in files acting as a template client, and is the fundamental enabler for templating in Facelets. The <ui:composition/> tag is used in template client file and states that the content of this element will be included from template file. In a template client page using <ui:composition/>, anything outside of the bounds of a <ui:define> tag is ignored and is not included in the rendered output.

17. What is <ui:ui:decorate/> tag in JSF ?
<ui:decorate template=”requiredTemplate”>

The <ui:decorate> tag provides the same feature as <ui:composition>, but it causes any content surrounding the <ui:decorate> tag to be included in the page, rather than be trimmed, as in the case of <ui:composition>. This enables taking any element in the page, and applying it to a template. Also, observe that the template attribute is required in this tag. This tag is useful when you have a series of items in one page that require the same appearance. If you were to use ui:composition, the output around the tags would be trimmed, which is not desirable in this case.

18. What is <ui:define/> tag in JSF ?
<ui:define name=”requiredName”>

The <ui:define> tag is used in files acting as a template client, inside a <ui:composition> tag, to define a region that will be inserted into the composition at the location given by the <ui:insert> tag with the corresponding name for the <ui:define> tag.

19. What is <ui:insert/> tag in JSF ?
<ui:insert name=”optionalName”>

The <ui:insert> tag is used in files acting as a template to indicate where the corresponding <ui:define> in the template client is to be inserted. If no name is specified, the body content of the <ui:insert> tag is added to the view.

20. What is <ui:include/> tag in JSF ?
<ui:include src=”requiredFilename”>

The eminently useful tag <ui:include> is combined with the <ui:param> tag to enable the parameterized inclusion of pages. This tag may be present in templates or template clients.

21. What is <ui:param/> tag in JSF ?
<ui:param name=”requiredName” value=”requiredValue”>

The <ui:param> tag is used exclusively inside <ui:include> tags to define name/ value pairs that are available via the EL in the included page. Both the name and value attributes may be literal strings or EL expressions.

22. What is <ui:component/> tag in JSF ?
<ui:component id=”optionalComponentId” binding=”optionalValueExpression”>

The <ui:component> tag has an optional id attribute that will be set into the id property of the component. If not specified, a page-unique ID is generated. The optional binding attribute is a ValueExpression that refers to a JavaBeans property whose type is a UIComponent. This is exactly the same as the binding attribute on JSP JSF component tags. If the ValueExpression has no initial value, an appropriate UIComponent instance is created automatically and set into the ValueExpression. Any markup occurring outside of the <ui:component> tag is not included in the view.

23. What is <ui:fragment/> tag in JSF ?
<ui:fragment id=”optionalComponentId” binding=”optionalValueExpression”>

The <ui:fragment> tag is the same as <ui:component> except that it wraps a series of components inside a single parent component before the parent is added to the tree.

24. What is <ui:remove/> tag in JSF ?

The <ui:remove> tag is mainly used during development to “comment out” a portion of the markup in order to prevent it from actually ending up in the view. <ui:remove> has no attributes and may appear anywhere in the page where it is valid to have a component or something that represents a component.

25. What is <ui:debug/> tag in JSF ?
<ui:debug hotkey=”optionalHotKey” />

This useful tag will enable a hot key that pops up a new window displaying the component tree, any scoped variables currently active, and other useful debugging information. You have to set the javax.faces.FACELETS_DEVELOPMENT context-param in your web.xml to enable this to work. If optionalHotKey is not specified, pressing CTRL-SHIFT-D will pop up the debug window.