Wednesday, July 11, 2012

Introduction of JSF configuration and setup




Create jsf project using following bellow step....


Step0:      Create project --> new --> web --> dynamic web project.
Step1:      Right click project properties and then choose Project Facets or type in the box of properties.
Step2:      Choose dynamic web module, java, java persistence, java script toolkit. then apply --> ok
Step3: Persistance.xml file will be created into src folder. Now open Persistance.xml with persistence xml editor. There is
                a. name    : project name
                b. persistence provider and more.
NB: better to copy all contain from actual written Persistance.xml file. which is availabel into autojsfcode projec.

Actual persistance.xml file contains:


<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="autojsfcode">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jsftest"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.connection.username" value="root"/>
        <property name="hibernate.connection.password" value=""/>
        <property name="show_sql" value="true" />
     </properties>
</persistence-unit>
</persistence>

For understanding..
---> Name= "autojsfcode"  (project name)
---> Database name = jsftest

Step4:      Right click project properties and then choose java persistence or type in the box of properties.
Step5:      Choose connection: New Mysql --> choose Add connection --> Connection Profile Types: MySql --> click Next.

                a. Database    :         jsftest (database name)
                b. URL         :           jdbc:mysql://localhost:3306/jsftest
                c. User Name:          root
                d. Password: (type if you have)
                e. Click test connection button. (Ping Successfully message will be given)

We have to generate bean java file. For that …
Now we have to create hibernate.cfg.xml file and hibernate.reveng.xml file.

hibernate.cfg.xml

Step6: select right click on project à new à others à type hibernate à Hibernate configuration file.




Then click finish.

hibernate.cfg.xml (must contain)
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jsftest</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.search.autoregister_listeners">false</property>
        <mapping class="generatedcode.Info" />
    </session-factory>
</hibernate-configuration>

Step6: select right click on project à new à others à type hibernate à Hibernate console Configuration. à do setting à Finish


Now go change mode (Example java, Hibernet, java Browsing, Debug). Right corner of springsource you get this. So select Hibernate. Then left side beside project explorer you will get Hibernate configuration. If does not come then window à reset prospective.

Example : check database

Step7: select right click on project à new à others à type hibernate à Hibernate Reverse Engineering file


Click include à Finish
hibernate.reveng.xml (must contain)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>
  <table-filter match-catalog="jsftest" match-name="info"/>
</hibernate-reverse-engineering>

Step8: make automatically generate code  for that click picture option and then choose Hibernate code generation configuration




……………..
Create new record just beside Red Cross symbol and do setting as per image.
Now run. Code will automatically generate.


After generating code you get error in java file.
For solving that error: keep your mouse on import package. Then

Then organize import click.
Again above class write this code @Entity
@Table(name = "info", catalog = "jsftest")

Change db : jsftest to your db and name info to your info

Date: 21-12-11
=============================== Done =====================================
















































 

No comments: