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;
       }
}




18 comments:

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

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

    ReplyDelete
  3. Thanks for chosing my most favourite topic in java.This is nice info .THanks that u have explained in a very simple manner.
    iphone service centre
    ipad service center in chennai
    ipad service center
    apple mobile service centre in chennai
    iphone service centre chennai

    ReplyDelete
  4. Hi, thank you very much for the new information, i learned something new. Very well written. Keep posting article. If you are looking for any data science related information please visit our website data science course training bangalore

    ReplyDelete
  5. Thanks for sharing useful information on big data and Hadoop technology. Hadoop and Bigdata are going to be future of the computing world in the coming years. This field is a very good option that provides huge offers as career prospects for beginners and talented professionals. Taking a course from bigdata training institute in bangalore will help you to start a good career in big data technology.

    ReplyDelete
  6. Amazing and informative post,
    Thanks for sharing with us,
    We are again come on your website,
    Thanks and good day,
    If you need any logo then,
    Please visit our site,
    buylogo

    ReplyDelete
  7. Thanks for sharing this type of blog i really like it please keep sharing such useful information.

    Understanding Lifecycle in Android Activity

    ReplyDelete
  8. Hello.
    Are you looking for a amazing logo design for your business with 50% off I expect You will be impressed with us.Logo Designers

    ReplyDelete