Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JSF example application to run in eclipse
12-13-2011, 12:17 AM (This post was last modified: 12-18-2011 05:26 AM by admin.)
Post: #1
Star JSF example application to run in eclipse
Hai Readers as i said in the previous JSF introduction post today we are going to learn the basic example in JSF,
You need two types of jar files

1.jstl.jar
2.standard.jar
and two tld files 1.jsf_core.tld
2.html_basic.tld to run a basic JSF program
First create the basic JSF program,create a jsp file simple.jsp later in web.xml it is converted and run as index.jsf now enter the code below
<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

Quote:<html>
<body>
<f:view>
<h:form>
<h:message for="value"/>
<h:inputText id="value" value="#{simple.field}">
<f:convertDateTime type="date" pattern="dd/mm/yyyy"/>
</h:inputText>
<h:inputText id="date" value="#{simple.date}"/>
<h:commandButton action="#{simple.submit}" value="submit"/>
</h:form>
</f:view>
</body>
</html>

In this file there is a tag to show the message about errors h:message and two inputtext box, one getting current date from bean and another inputtext box where we are going to enter the data and check whether it is in correct format.

Lets create the bean for the program Simplebean.java
package s2sgateway;
import java.util.Date;
public class Simplebean {
private String field;
public Date date;
public Date getDate()
{
date=new Date();
return date;
}
public String getField() {
return field;
}
public void setField(String field) {
this.field = field;
}
public String submit()
{
System.out.println(this.field);
System.out.println(this.date);
return "success";
}
}
Now lets create the faces-config.xml and enter the values such as bean name,class and scope values

Quote:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config >
<managed-bean>
<managed-bean-name>simple</managed-bean-name>
<managed-bean-class>s2sgateway.Simplebean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>

Now in web.xml file the the servelt-name->Faces Servlet&
url-pattern will be *.jsf so that you can run the file with .jsf extension like index.jsf otherwise you have to run as index.jsp

Quote:<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee" "http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

Now you can run this program when you enter any wrong date or no it shows conversion error if you give the date as 31/8/2010 then it doesn't shows any error,Any doubt ask us happy coding
Download Project here simplejsf .In order to view links, you must have to reply to this thread.

Happy coding
Find all posts by this user
Add Thank You Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies Views: Last Post
Photo First Hibernate example run in eclipse tutorial rajasri 2 914 Today 03:16 AM
Last Post: mukesh1234
Photo How to import a war file in to eclipse rajasri 0 531 12-13-2011 03:32 AM
Last Post: rajasri
Photo how to add .properties/.jar file to classpath in eclipse rajasri 0 680 12-12-2011 11:56 PM
Last Post: rajasri

Forum Jump:


User(s) browsing this thread: 1 Guest(s)


WE will share important jobs and updates on facebook so like us to get updates