Pages

Thursday, September 26, 2013

JSF(Java Server Faces):-
A server side user interface component framework for Java technology-based web applications.

What is JSF?
● A specification and reference implementation for a web application development framework
● A JSF application run in a standard web container, for example Tomcat or Jetty.
    – Components
    – Events
    – Validators & converters
    – Navigation
    – Back-end-data integration

Why JSF?
● MVC for web applications
● Clean separation of roles
● Easy to use
● Extendable Component and Rendering architecture
● Support for client device independence
● Standard

● Huge vendor and industry support
● JSP and Servlet
    – No built-in UI component model
● Struts (I am not saying you should not use Struts)
    – No built-in UI component model
    – No built-in event model for UI components
    – No built-in state management for UI components
    – No built-in support of multiple renderers
    – Not a standard (despite its popularity)
● Struts and JSF can be used together


 Download  The Following jars related to jsf 1.2 and jsf 2.0.
  1.jsf-api.jar Download jsf-api.jar
 2.jsf-impl.jar Download jsf-impl.jar
 3.jstl-1.2.jar Download jstl-1.2.jar

Example of Jsf 1.2:-
--------------------
1.Create a dynamic web project as flows.
    a)choose dynamic web project and provide project name as your wish
    b)add or select target runtime environment .
    c)Click on modify button to change the configuration,then project facets windows will be open.
    e)check "Java Server Faces" and select version 1.2(from right side arrow button).
    f)click on save as button and provide some name and click on ok button of Project facets window.
       Click on Next button of three coming windows.
   g)Click on manage Libraries(this is icon)
   h)Click on New and provide Library Name Ex.JSF1.2-Lib
   i)Add three jar to above created user library,click on Ok button.
  j)check the user library as you created and provide config file and url pattern.
  k)click on finish.

then take below page and write code.
 1)index.html
2)login.jsp
3)home.jsp
    
     




4)UserBean
 public class UserBean {
    private String username;
    private String password;
    private String errMsg;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
    public String getErrMsg() {
return errMsg;
}
public void setErrMsg(String errMsg) {
this.errMsg = errMsg;
}
public String verifyUser() {
String status="failed";
if(username.equals(password)){
status="success";
}else{
errMsg="Invalid Username or Password";
}
return status;
}
    public String goToLogin() {
return "login";
}
}
5)faces-config.xml
   
6)web.xml
          
After writing these all file to run this application flows these step
 1)right click on project and choose Run As->Run on Server and chose tomcat 7 and click on finish.
   after start the server you can also type below url in any browser
   http://localhost:8080/JSFExample/login.sk

Best of Luck!!!!!!!!!

No comments:

Post a Comment