[go: up one dir, main page]

0% found this document useful (0 votes)
114 views20 pages

Overview of JavaServer Faces (JSF)

Java Server Faces (JSF) is a Java framework for building web applications that offers a clean separation between behavior and presentation. JSF uses a component-based model-view-controller architecture and provides standard HTML tags to build the user interface. Some benefits of JSF include its component-based approach, ease of development, default exception handling, and separation of functionality from display of components. However, JSF can become complex to maintain when mixing Java and XHTML code and forcing this intermingling. JSF programs use standard HTML tags with JSF namespaces to render corresponding HTML output on the server side.

Uploaded by

shanthi.ceg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Topics covered

  • HTML integration,
  • UI components,
  • Client-server applications,
  • HTTP protocol,
  • Service interface,
  • Managed Beans,
  • JavaServer Faces,
  • Data exchange,
  • SOAP,
  • JSF tags
0% found this document useful (0 votes)
114 views20 pages

Overview of JavaServer Faces (JSF)

Java Server Faces (JSF) is a Java framework for building web applications that offers a clean separation between behavior and presentation. JSF uses a component-based model-view-controller architecture and provides standard HTML tags to build the user interface. Some benefits of JSF include its component-based approach, ease of development, default exception handling, and separation of functionality from display of components. However, JSF can become complex to maintain when mixing Java and XHTML code and forcing this intermingling. JSF programs use standard HTML tags with JSF namespaces to render corresponding HTML output on the server side.

Uploaded by

shanthi.ceg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Topics covered

  • HTML integration,
  • UI components,
  • Client-server applications,
  • HTTP protocol,
  • Service interface,
  • Managed Beans,
  • JavaServer Faces,
  • Data exchange,
  • SOAP,
  • JSF tags

Java Programming

Why JSF?
• JavaServer Faces (JSF) is a new standard Java
framework for building Web applications.
• Java specification for building component-
based user interfaces for web applications
• JSF offers a clean separation between
behavior and presentation for web
applications.
What is JSF?
• Java Server Faces (JSF) technology is a front
end framework which makes the creation of user
interface components easier by reusing the UI
components.
• JSF is designed based on the Model View
Controller pattern (MVC) which segregates the
presentation, controller and the business logic.
• UI Components: Text fields, list boxes,
checkboxes, labels, panels, radio buttons, and
other elements
JSF Features

• Component Based Framework.


• JSP is based on the Model-View-Controller
concept
• Ease and Rapid web Development.
• Default Exception Handling.
• JSF separates the functionality of a
component from the display of the
component.
Why not JSF?
• JSF forces you to mix Java and xhtml code for
the same feature.
• JSF project can be easily become too complex
to maintain
JSF program
• JSF provides a standard HTML tag library
which are rendered into corresponding html
output.
• In order to use these these tags we need to
use the following namespaces of URI in html
node.
• <html
xmlns="[Link]
xmlns:h="[Link] >
JSF tags HTML tags
h:inputText <input type="text“>
h:outputText Plain text JSF tags are
similar to
h:form <form> html tags
h:commandButton <input type=value> with minor
value can be "submit", "reset", variations
or "image"
h:inputSecret <input type="password">
h:inputTextarea <textarea>
h:inputHidden <input type="hidden">
h:dataTable <table>
h:outputLabel <label>
h:panelGrid <table> element with <tr> and
<td> elements
h:selectOneRadio <input type="radio">

h:selectBooleanCheckbox <input type="checkbox">


JSF-Example code 1
java class and X-html
@ManagedBean(name="hello")
This is the name for the object of HelloWorld class
Later can use in JSF tag to fetch its variables as #(hello.s1)

<?xml version='1.0' encoding='UTF-8' ?>


<html
@ManagedBean(name="hello") xmlns="[Link]
public class HelloWorld xmlns:h="[Link]
{ <h:head>
private String s1 = "Hello World!!"; <title>Hello World JSF Example</title>
</h:head>
} <h:body>
#{hello.s1}
<br />
<br />
Use <h:head> instead of <head>
</h:body>
Access the java class HelloWorld </html>
varaible s1 via java object helloWorld
declared using @ManagedBean
@ManagedBean(name="temperatureCo <html> Example 2
nvertor") <title>Celsius to Fahrenheit Convertor</title>
public class TemperatureConvertor { <h:body>
private double celsius; <h:form>
private double fahrenheit; <h:outputLabel value="Celsius">
private boolean initial= true; </h:outputLabel>
public double getCelsius() { <h:inputText
return celsius; } value="#{[Link]}">
public void setCelsius(double celsius) { </h:inputText>
[Link] = celsius; } <h:commandButton action=
public double getFahrenheit() { "#{[Link]}"
return fahrenheit; } value="Calculate">
public boolean getInitial(){ </h:commandButton>
return initial; } <h:commandButton action=
public String reset (){ "#{[Link]}" value="Reset">
initial = true; </h:commandButton>
fahrenheit =0; </h:form>
celsius = 0; <h3> Result </h3>
return "reset"; <h:outputLabel value="Fahrenheit ">
} </h:outputLabel>
public String celsiusToFahrenheit(){ initial <h:outputLabel
= false; value="#{[Link]}">
fahrenheit = (celsius *9 / 5) +32; </h:outputLabel> </h:body> </html>
return "calculated"; } }
Example 2: jdbc connectivity
// [Link]
html xmlns="[Link]
xmlns:h="[Link]
<h:head> <title>User Form</title> </h:head>
<h:body>
<h:form>
<h:outputLabel for="username" value="User Name "/>
<h:inputText id="username" value="#{[Link]}"> </h:inputText><br/>
<h:outputLabel for="email" value="Email ID "/>
<h:inputText id="email" value="#{[Link]}">
</h:inputText><br/><br/>
<h:commandButton action="#{[Link]()}" value="submit"/>
</h:form>
</h:body>
</html>
Example 2: jdbc connectivity
// [Link] public boolean save(){
@ManagedBean(name=“user") int result = 0;
public class User { try{
String userName; String url="jdbc:oracle:thin:@localhost:1521:XE";
String email; String user ="SYSTEM";
public String getUserName() { String pwd ="oracle";
return userName; } Connection
public void setUserName(String userName) con=[Link](url,user,pwd);
{ PreparedStatement stmt = [Link](
[Link] = userName; } "insert into user(name,email) values(?,?)");
public String getEmail() { [Link](1, [Link]());
return email; } [Link](2, [Link]());
public void setEmail(String email) { result = [Link]();
[Link] = email; }catch(Exception e){ [Link](e); }
} if(result == 1){ return true; }
else return false;
}
public String submit(){
if([Link]()){ return "[Link]";
}else return "[Link]";
}
}
Example 2: jdbc connectivity

// [Link]
<html xmlns="[Link]
xmlns:h="[Link]
<h:head>
<title>Response Page</title>
</h:head>
<h:body>
<h1><h:outputText value="Hello #{[Link]}"/></h1>
<h:outputText value="Your Record has been Saved Successfully!"/>

</h:body>
</html>
Web services
• A web service makes software application resources
available over networks using standard technologies.
• A web service is a collection of open protocols and
standards used for exchanging data between
applications or systems
• Web services are based on standard interfaces and
hence they can communicate even if they are running
on different operating systems and are written in
different languages.
• Therefore, Web services are an excellent approach for
building distributed applications that must incorporate
diverse systems over a network.
What are Web services?
• Web services are client and server applications that communicate over
the World Wide Web’s (WWW) HyperText Transfer Protocol (HTTP).
• web services provide a standard means of interoperating between
software applications running on a variety of platforms and frameworks.
• Web services are characterized by their great interoperability and
extensibility, as well as their machine-processable descriptions, XML.
• Web services can be combined in a loosely coupled way to achieve
complex operations.
• Software applications written in various programming languages and
running on various platforms can use web services to exchange data over
computer networks like the Internet in a manner similar to inter-process
communication on a single computer.
• A web service:
– Publicly describes its own functionality through a
WSDL file
• WSDL is an XML, and it stands for Web Service Description
Language. WSDL describes all the methods available in the
web service, along with the request and response types. It
describes the contract between service and client.
– Communicates with other applications via XML
messages, often formatted with SOAP
– Employs a standard network protocol such as HTTP
Types of web services
• There are two types of web services:
– SOAP Web Services
– REST Web Services
SOAP
• SOAP is an XML-based protocol.
• SOAP stands for Simple Object Access Protocol.
• SOAP was intended to be a way to do remote
procedure calls to remote objects by sending XML
over HTTP.
REST Web Services

• The REST stands for Representational State Transfer.


• REST is not a set of standards or rules, rather it is a style of
software architecture.
• The applications which follow this architecture are referred
to as RESTful
• REST locates the resources by using URL and it depends on
the type of transport protocol(with HTTP - GET, POST, PUT,
DELETE,...) for the actions to be performed on the
resources.
• while requesting the data from a website, the data should
be in a browser readable format, which is HTML, while in
case of the REST API, response can be anything
like XML/JSON or any other media type.
REST Web Services
Difference between REST and SOAP

REST SOAP
• REST is a style of software • SOAP is a protocol or a set of
architecture. standards.
• REST can use SOAP because it • SOAP cannot use REST
is a concept and can use any because it itself is a protocol.
protocol like HTTP, SOAP etc.
• REST uses URI to expose • SOAP uses the service
business logic. interface to expose business
• REST inherits security logic.
measures from the underlying • SOAP defines its own security
transport protocols. layer.
• REST accepts different data • SOAP only works with XML
formats like, Plain Text, HTML, format.
JSON, XML etc.

Common questions

Powered by AI

While JSF supports scalable web application development with component reuse and separation of concerns, its necessitation of mixing Java and XHTML can lead to complex code structures that are challenging to maintain. Its complexity is further compounded when applications grow large, potentially inflating the framework's overhead, leading to entangled logic that diminishes the benefits of its MVC architecture .

RESTful web services are often preferred over SOAP in scenarios where simplicity, scalability, and performance are prioritized. REST's adherence to HTTP protocols makes it more straightforward and lighter weight, which is especially suitable for stateless operations integral to web-based applications. Its flexible support for multiple formats, such as JSON, increases its efficiency in web development where bandwidth is a consideration .

Managed Beans in JSF are used to encapsulate business logic and data, acting as the model in the MVC framework. They are defined with annotations like @ManagedBean, making them accessible from the JSF page using expression language. Managed Beans facilitate the separation of backend logic from the user interface, enhance reusability, and simplify code management through the framework's dependency injection .

Developers might avoid using JSF due to its tendency to intertwine Java and XHTML code, which can increase complexity and hinder maintainability. Furthermore, the learning curve associated with mastering JSF may deter developers who seek simpler and more straightforward frameworks .

JSF tags like h:inputText and h:form correspond directly to HTML elements such as <input type="text"> and <form>. This abstraction allows developers to work with JSF's component-based model while relying on familiar HTML output. Yet, it requires developers to learn JSF-specific tags and syntax, which can complicate development if they are not well-versed in the framework's conventions .

WSDL plays a crucial role in defining the network services and their functionalities through an XML format. For SOAP-based systems, it specifies the operations the service can perform, the data types used, and the communication protocol bindings, enabling clients and services to interoperate with defined contracts and facilitating automated tool support for creating service interfaces .

The MVC pattern benefits JSF by separating the user interface from the business and control logic. This allows developers to manage complexity and achieve a clean separation of concerns. The model handles the data, views display the data, and the controller manages inputs. This separation enhances maintainability, facilitates reusability of components, and simplifies parallel development .

Web services improve interoperability by adhering to open protocols and standards such as HTTP and XML, allowing applications on different platforms and written in various languages to communicate seamlessly. They employ WSDL files for describing their functionalities and use XML or JSON for data exchange, facilitating a loosely coupled architecture and enabling diverse systems to work together over networks .

SOAP is a protocol with strict standards focusing on XML messages and defines its own security layer, making it suitable for secure transactions. It uses interfaces to expose business logic, maintaining compatibility across platforms. REST, on the other hand, is an architectural style utilizing HTTP and URIs, accepting multiple data formats like JSON and XML. It leverages the security of underlying transport protocols, is simpler to use, and better suited for web-based applications where stateless operations are beneficial .

JSF provides a component-based framework which simplifies the development of web applications by offering a clean separation between behavior and presentation. It is built on the Model View Controller (MVC) pattern, segregating the presentation, controller, and business logic. Key features include default exception handling, rapid web development, and a standard HTML tag library rendered into corresponding HTML output .

You might also like