Showing posts with label jsf. Show all posts
Showing posts with label jsf. Show all posts

explain key features of the JavaServer Faces (JSF) framework?

JavaServer Faces is a new framework for building Web applications using java. JSF provides you with the
following main features:
ƒ Basic user interface components like buttons, input fields, links etc. and custom components like tree/table
viewer, query builder etc. JSF was built with a component model in mind to allow tool developers to support
Rapid Application Development (RAD). User interfaces can be created from these reusable server-side
components.
ƒ
Provides a set of JSP tags to access interface components. Also provides a framework for implementing
custom components.
Supports mark up languages other than HTML like WML (Wireless Markup Language) etc by encapsulating
event handling and component rendering. There is a single controller servlet every request goes through
where the job of the controller servlet is to receive a faces page with components and then fire off events
for each component render the components using a render tool kit.
Uses a declarative navigation model by defining the navigation rules inside the XML configuration file
faces-config.xml. This configuration file also defines bean resources used by JSF.
JSF can hook into your model, which means the model is loosely coupled from JSF.
Let’s look at some code snippets. Texts are stored in a properties file called message.properties so that this
properties file can be quickly modified without having to modify the JSPs and also more maintainable because
multiple JSP pages can use the same property.
account_nuber = Account number
account_button = Get account details
account_message=Processing account number :
input_accountNumber.jsp
<%@ taglib uri="http://java.sun.com.jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com.jsf/core" prefix="f" %>
<f:loadBundle basename="messages" var="msg"/>
<html>
...
<body>
<f:view>
<h:form id="accountForm">
<h:outputText value="#{msg.account_number}" />
<h:inputText value="#{accountBean.accountNumber}" />
<h:commandButton action="getAccount" value="#{msg.account_button}" />
</h:form>
</f:view>
</body>
</html>
AccountBean.Java
public class AccountBean {
String accountNumber;
public String getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}
}
faces-config.xml
...
<faces-config>
<navigation-rule>
<form-view-id>/jsps/input_accountNumber.jsp</form-view-id>
<navigation-case>
<from-outcome>getAccount</from-outcome>
<to-view-id>/jsps/output_accountNumber.jsp</to-view-id>
</navigation-case>
</navigation-rule>
...
<managed-bean>
<managed-bean-name>accountBean</managed-bean-name>
<managed-bean-class>AccountBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
output_accountNumber.jsp
<html>
...
<body>
<f:view>
<h3>
<h:outputText value="#{msg.account_message}" />
<h:outputText value="#{accountBean.accountNumber}" />
</h3>
</f:view>
</body>
</html>

explain JSF framework compare with the Struts framework

Struts framework  versus JavaServer Faces

  • Matured since Struts has been around for a few years.
It has got several successful implementations.
JSF is in its early access release and as a result somewhat
immature.

  • The heart of Struts framework is the Controller, which
uses the Front Controller design pattern and the
Command design pattern. Struts framework has got
only single event handler for the HTTP request.
The heart of JSF framework is the Page Controller Pattern where
there is a front controller servlet where all the faces request go
through with the UI components and then fire off events for each
component and render the components using a render toolkit. So
JSF can have several event handlers on a page. Also JSF
loosely couples your model, where it can hook into your model (i.e
unlike Struts your model does not have to extend JSF classes).

  • Struts does not have the vision of Rapid Application
Development (RAD).
JSF was built with a component model in mind to allow RAD. JSF
can be thought of as a combination of Struts framework for thin
clients and the Java Swing user interface framework for thick
clients.
Has got flexible page navigation using navigation rules
inside the struts-config.xml file and Action classes
using maoping.findForward(…) .
JSF allows for more flexible navigation and a better design
because the navigation rule (specified in faces-config.xml ) is
decoupled from the Action whereas Struts forces you to hook
navigation into your Action classes.
  • Struts is a sturdy frame work which is extensible and
flexible. The existing Struts applications can be
migrated to use JSF component tags instead of the
original Struts HTML tags because Struts tags are
superseded and also not undergoing any active
development. You can also use the Struts-Faces
Integration library to migrate your pages one page at
a time to using JSF component tags.
JSF is more flexible than Struts because it was able to learn from
Struts and also extensible and can integrate with RAD tools etc.
So JSF will be a good choice for new applications.?