Wednesday, September 19, 2012

Rich Faces Application - Beginner


So I thought why not to make a simple newbie Richfaces Application:

I watched :


Even though it was a guide line I wanted a tutorial to walk me through

I have already set up Jboss-as-7 and Jboss tools in eclipse I would be blogging how to set up shortly or you can Google it up.

Step1:
Download Richfaces-4.2.2 from Stable Download

Step2:
Download Additional Jars
Step3: Install Jboss plugins.  (Ref: Eclipse market place )

Well "Dynamic Web Project"  for me was a difficult option for configuration better do with "JSF project"

Make sure to select Created web.xml option to true.

Navigate to WEB-INF/lib folder and add all the jars mentioned above

Refresh project in eclipse

There now you have Blank project to work with

Import Note: Make sure to add bean.xml eventhough its empty its necessary.

Example 1: Simple example of RichFace page and Bean by using ajax component

Project Structure

YourRichFacesProject/
     src/
     WebContent/
          META-INF/
          resources/
          WEB-INF/
               lib/
                    commons-annotations.jar
                    commons-beanutils.jar
                    commons-collections.
                    commons-digester.jar
                    commons-logging.jar
                    jstl.jar
                    richfaces-components-api-4.2.0.Final.jar
                    richfaces-components-ui-4.2.0.Final.jar
                    richfaces-core-api-4.2.0.Final.jar
                    richfaces-core-impl-4.2.0.Final.jar
                    guava-10.0.1.jar 
                    cssparser-0.9.5.jar
                    sac-1.3.jar
               web.xml
               faces-config.xml
          index.hxtml
          ...
WebContent/index.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:a4j="http://richfaces.org/a4j"> 

<h:head>
    <title>Rich faces</title>
</h:head> 
<body> 

            <h:messages />
            <h:form id ="form1">
            <h:inputText value="#{testbean.name}">
                <a4j:ajax event="keyup" render="form2">
                    
                </a4j:ajax>
            </h:inputText>
            </h:form>
            
            <h:form id = "form2">
            <h:outputText value="#{testbean.name}" />
            </h:form> 
</body> 
</html>
JavaSource/PackageName/TestBean
package com.tutorial.bean;

import javax.enterprise.context.RequestScoped;
import javax.faces.bean.*;

@ManagedBean(name="testbean")
@RequestScoped


public class TestBean {
    private String name="tosha";

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
WebContent/WEB-INF/web.xml
<?xml version="1.0"?>
<web-app version="3.0" 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-app_3_0.xsd">
 <display-name>Jboss_rich</display-name>

  <welcome-file-list>
   
    <welcome-file>index.jsf</welcome-file>
     <welcome-file>index.html</welcome-file>
  </welcome-file-list><context-param>

        <param-name>
            org.richfaces.SKIN
        </param-name>

        <param-value>
                blueSky
        </param-value>
    </context-param>

  
<context-param>

      <param-name>org.richfaces.CONTROL_SKINNING</param-name>

      <param-value>enable</param-value>

</context-param>>

 <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>*.jsf</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.faces</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>/faces/*</url-pattern>
 </servlet-mapping>
</web-app>
WebContent/WEB-INF/aces-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_2_0.xsd"
    version="2.0">

</faces-config>


WebContent/WEB-INF/beans.xml
<?xml version="1.0"?>
<beans 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://jboss.org/schema/cdi/beans_1_0.xsd"/>


Output:



Will try to implement
Data Table example : Source

Thats much work for a Day! :)

No comments:

Post a Comment