Sunday, 22 May 2016

JavaBeans in Hybris..

JavaBeans: 

 JavaBean  is a Java class that:
1.     Implements the Serializable interface
2.     Has a no-argument constructor
3.     JavaBean properties must have public setter and getter methods
 Java Bean makes it easy to reuse software components.

Example of JavaBean:

public class JavaBeanDemo  implements java.io.Serializable
{
          private int num;
          private String Fname;
                  
          public JavaBeanDemo()
          {
                   // default constructor
          }
          public void setNum(final int num)
          {
                   this.num = num;
          }              
          public int getNum()
          {
                   return num;
          }
          public void setFname(final String Fname)
          {
                   this.Fname = Fname;
          }
          public String getFname()
          {
                   return Fname;
          }   
}

 JavaBean in Hybris:

  • In hybris javabeans are automatically generated.
  • Each extension may provide a bean configuration file in this file class name, attributes or superclass are defined. 
  • Java Beans or Enums definitions are melded across extensions.
  • Java beans Contain an abstraction of models.  

Example for custom java bean Generating:

Configure the bean in extension-beans.xml
    <bean class="com.hybrisdemo.data.JavaBeanDemo">
             <property name="num" type="int"/>
               <property name="Fname" type="String"/>
        </bean>
The following JavaBean is Generated under platform/bootstrap/gensrc folder based on above configuration. it generated  when ever we call “ant all” ( or)  “ant clean all” target.
 public class JavaBeanDemo  implements java.io.Serializable
{
          private int num;
          private String Fname;
                  
          public JavaBeanDemo()
          {
                   // default constructor
          }
       //Setters and getters methods..
}
  • Java beans are useful as DataObjects used by Frontend layer.
  • Merge attributes into existing beans.

For example:- extenstion1 and extenstion2 have same bean class with different attributes that attributes merge into one javabean class Generated under platform/bootstrap/gensrc.

 extension1-beans.xml:- 

        <bean class="com.hybrisdemo.data.JavaBeanDemo">
             <property name="num" type="int"/>
                  <property name="Fname" type="String"/>
        </bean>

 extension2-beans.xml:-

        <bean class="com.hybrisdemo.data.JavaBeanDemo">
             <property name="num" type="int"/>
                  <property name="Fname" type="String"/>
                  <property name=”Lname” type=”String”/>
        </bean>

Generated JavaBean Class:- 

public class JavaBeanDemo  implements java.io.Serializable
{
       private int num;
       private String Fname;
       private String Lname;
             
       public JavaBeanDemo()
       {
              // default constructor
       }
       public void setNum(final int num)
       {
              this.num = num;
       }           
       public int getNum()
       {
              return num;
       }      
       public void setFname(final String Fname)
       {
              this.Fname = Fname;
       }      
       public String getFname()
       {
              return Fname;
       }              
       public void setLname(final String Lname)
       {
              this.Lname = Lname;
       }       
       public String getLname()
       {
              return Lname;
       }
}




4 comments:

  1. Very Good Blog if someone need any help in technological things please visit our blog page

    ReplyDelete
  2. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog. It is very nicely explained. Your article adds best knowledge to our Java Online Training from India. or learn thru Java EE Online Training Students.

    ReplyDelete
  3. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site. Technically storng. Best Java Training Institute Chennai

    ReplyDelete