Saturday, 27 October 2012

JSF InputText tag example

1). JSF InputText tag example structure

  

2). index.html

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>index.html</title>
    <meta http-equiv="Refresh" content="0; URL=index.faces"/>
  </head> 
</html>

3). index.jsp

 

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   <title>My JSP 'index.jsp' starting page</title>
  </head> 
  <body>
    <f:view>
        <h:form>
            <h:messages style="color: red;"></h:messages>
            <table>
                <h:outputText value="Enter following Information"></h:outputText>
                <tr>
                    <td>
                        <h:outputText value="Name"></h:outputText>
                    </td>
                    <td>
                        <h:inputText id="name" value="#{Bean.name}" required="true">
                            <f:validateLength minimum="2" maximum="25"></f:validateLength>
                        </h:inputText>
                    </td>
                </tr>
                <tr>
                    <td>
                        <h:commandButton id="button" action="result" value="Submit"></h:commandButton>
                    </td>
                </tr>
            </table>
        </h:form>
    </f:view>
  </body>
</html>

 

3). display.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   <title>My JSP 'display.jsp' starting page</title>
  </head> 
  <body>
    <f:view>
        <table>
            <tr>
                <td><b>
                    <h:outputText value=" Hello #{Bean.name}"></h:outputText></b>
                </td>
            </tr>
            <tr>
                <td>
                    <a href="/JSF InputText tag/index.faces">Back</a>
                </td>
            </tr>
        </table>
    </f:view>

  </body>
</html>

 

4). web.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

5). faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
    version="1.2">
    <navigation-rule>
        <from-view-id>/index.jsp</from-view-id>
        <navigation-case>
        <from-outcome>result</from-outcome>
        <to-view-id>/display.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>
    <managed-bean>
        <managed-bean-name>Bean</managed-bean-name>
        <managed-bean-class>com.satyamsoft.in.Bean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
</faces-config>

 

6). Bean.java

  package com.satyamsoft.in;

public class Bean {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }   
   
}
 

7). Output

  If u press submit button with out giving input in textbox then we get Error.

 

-->

   

  Download JSF InputText tag Example source code

JSF Hello World

1). JSF Hello World Program Structure:        




2). index.html

       Copy below code and paste in the index.html file. 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>index.html</title>   
    <meta http-equiv="Refresh" content="0; URL=index.faces"/>
  </head>
</html>

3). index.jsp 

      Copy below code and paste in the index.jsp file.

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  </head> 
  <body>
   <f:view>
       <h:form>
           <h:messages style="color: red;"></h:messages>          
               <h:outputText value="HelloWorld" />
       </h:form>
   </f:view>
  </body>
</html>

4). web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

5). faces-config.xml

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

<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
    version="1.2">
   
</faces-config>

6). OutPut



  Download JSF Hello World Example source code

JSF Tutorail,Examples


JSF Tutorial   

 

 JSF Tag Examples

1). JSF Hello World Example
2). JSF  inputText tag Example
3). JSF inputSecret tag Example 
4). JSF inputTextarea tag Example 
5). JSF inputHidden tag Example 
6). JSF selectBooleanCheckbox tag Example  
7). JSF selectManyCheckbox tag Example  
8). JSF selectOneRadio tag example 
9). JSF selectOneListbox tag example 
10). JSF selectManyListbox tag example  
11). JSF selectOneMenu tag example 
12). JSF outputFormat tag example 


JSF Examples 

1). Calendar using JSF
2). JSF login Example

 

JSF with JDBC Examples 

Friday, 26 October 2012

Core JAVA Tutorial

Introduction to Java

1.  Features of Java

      a) Simple : Java is simple programing language. The main aim is Java has to work on electronic devices, where less memory available. So the people who knows C and C++ they can learn Java very easily. Here we are maintaining the same syntax of C and C++ in Java.

     b) Object-Oriented : Java is an Object Oriented Programing language. This means Java programs use Objects and Classes. What is an Object? An Object is anything that really exists in the world and can be distinguished from others. Everything that we see physically will come into this definition, for example, every human being, a book,a tree, and so on.

2. The Java Virtual Machine

           Difference between C++ and Java

JAVA Tutorial

JDBC
Servlets
JSP
Struts
Hibernet
Spring