Thursday, February 11, 2010

Use of "immediate" property in JSF

"immediate" attribute is available in almost all user input JSF tags. This attribute is commonly called "Event Handling Attribute". The valid values for this attribute is either "true" or "false". If value of this property is set to "true", then the validation, conversion, and events associated with these components takes place in this phase instead of the Process Validation Phase.

Eg. Suppose you have a cancel button that ignores all form values then we used this attribute.

Phases of JSF Application

Multiple faces-config.xml for JSF Application

We can use multiple faces-config.xml for JSF application, for that you have to specify file names for the JSF application in web configuration file(web.xml).

There is a built-in parameter of JSF named "javax.faces.CONFIG_FILES" we can use this paramete for JSF configuration files. This parameter can take any no. of files.
Add the following entry in web.xml file.

<context-param>
  <param-name>javax.faces.CONFIG_FILES</param-name>
   <param-value>
    /WEB-INF/faces-config1.xml,
    /WEB-INF/faces-config2.xml,
    /WEB-INF/faces-config3.xml
   </param-value>
</context-param>

Difference between JSP-EL and JSF-EL

JSP-EL:
1. JSP-EL value expressions are delimited by ${..}.
2. The ${..} delimiter immediately evaluate the given expression, at the time when the page is processed.

JSF-EL:
1. JSF-EL value expressions are delimited by #{..).
2. The #{..) delimiter is deferred evaluation. With deferred evaluation ,the expression is evaluates whenever a value is needed.

Difference between Managed and Backing Beans in JSF

Managed Beans: Java Bean Objects managed by JSF implementation is called Managed Bean, It is nothing but describe how beans are created and managed(scope). Managed Beans are automatically created by the framework at runtime. Managed Beans can be put in request, session and Application context.

Backing Beans: Java Beans Objects that associated with UI component is called backing bean. It is basically holds data of associated UI component and may contains business logic. The backing beans may also contains other methods for validations and events for that UI component. The Backing Beans are referenced by form(JSF/JSP page). The Backing Beans can be put in request scope only.
Sometime Backing Beans is also called View Objects, View Objects are specifically used in Presentation Layer. It contains data and logic to validate, events and interact with business logic tier.

Wednesday, February 10, 2010

How to Declare Message Bundle in JSF

There are two ways to declare Message Bundle in JSF:
1. Simply configured in faces-config.xml file.
<application>
  <resource-bundle>
    <base-name>wiki.com.messages</base-name>
    <var>message</var>
  </resource-bundle>
</application>

2. Use built-in JSF tag to declare Message Bundle. this should be for each and every jsf page. If same message is used for multiple pages then this should not be a good choice.
<f:loadBundle baseName = "wiki.com.messages" var="message"/>