Difference Between Jsf 1.2 and 2.0

Annotations to replace many faces-config.xml entries :

In JSF, managed bean means this java class or bean can be accessed from a JSF page.

In JSF 2.0, you can use the @ManagedBeanannotation to indicate this is a managed bean.

@ManagedBean(name=””)

@sessionScoped

Write this at the start of the class to indicate that this is managed Bean And can be accessible according to its Scope.

take the bean class name, change the first letter to lower case, and use that as the managed bean name.

Jsf 2.0 Pages :

In jsf 1.2 We use JSP or HTML pages while In JSF 2.0, it’s recommended to create JSF page in XHTML file format, a file with a .xhtml extension.

To use the JSF 2.0 components or features, just declared the JSF namespace at the top of the page.

<htmlxmlns=”http://www.w3.org/1999/xhtml”

xmlns:f=”http://java.sun.com/jsf/core”

xmlns:h=”http://java.sun.com/jsf/html”>

Navigation Rules :

In JSF 1.x, you had to declare the “navigation rule” in “faces-config.xml“, to tell which page to display when the button is clicked.

In JSF 2.0, you can put the page name directly in the button’s “action” attribute.

For simple navigation, it’s more than enough, but, for complex navigation, you are still advise to use the “navigation rule” in “faces-config.xml“.

Ajax Support :

Even JSF 1.2 has support of ajax but we have to add the libraries but JSF 2.0 has built in support of Ajax. JSF 2.0 provides the f:ajax client behavior tag. coding Ajax is just like coding a normal HTML tag, it’s extremely easy.

<?xml version=”1.0″ encoding=”UTF-8″?>

<!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:f=”http://java.sun.com/jsf/core” xmlns:h=”http://java.sun.com/jsf/html”>

<h:body> <h3>JSF 2.0 + Ajax Hello World Example</h3>

<h:form>

<h:inputText id=”name” value=”#{helloBean.name}”>

</h:inputText>

<h:commandButton value=”Welcome Me”>

<f:ajax execute=”name” render=”output” />

</h:commandButton>

<h2><h:outputText id=”output” value=”#{helloBean.sayWelcome}” /></h2>

</h:form>

</h:body>

</html>

In this example, it make the button Ajaxable. When the button is clicked, it will make an Ajax request to the server instead of submitting the whole form.

For multiple components, just split it with a space in between, e.g execute=“name anotherId anotherxxId”. In this case, it will submit the text box value.

render=”output” – After the Ajax request, it will refresh the component with an id of “output“. In this case, after the Ajax request is finished, it will refresh the <h:outputText> component .

Support For Groovy :

JSF 2.0 has the support of Groovy, a new scripting language, which was missing in JSF 1.2.

Page Book Marking :

JSF has ability to bookmark the result pages.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.