java left logo
java middle logo
java right logo
 

Home arrow Java SE Tips arrow java.beans arrow How to list names of the properties of a Bean
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4089
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to list names of the properties of a Bean E-mail
User Rating: / 3
PoorBest 

This Java tip demonstrates a method of listing names of various properties of a bean. The bean properties are entities that participate to the mapping process. They are usually the fields of the data bean. However, this isn't a requirement since the get & set methods of the data bean define the bean properties. The mapping utilities use the JavaBeans' introspection API to get the names and the types of the properties of a data bean.

    try {
    
        BeanInfo bi = Introspector.getBeanInfo(MyBean.class);
        PropertyDescriptor[] pds = bi.getPropertyDescriptors();
        
        for (int i=0; i<pds.length; i++) {
            // Get property name
            String propName = pds[i].getName();
        }
        
        // class, prop1, prop2, PROP3
        
    catch (java.beans.IntrospectionException e) {
    }
    
    public class MyBean {
        
        // Property prop1        
        public String getProp1() {
            return null;
        }
        
        public void setProp1(String s) {
        }
    
        // Property prop2
        public int getProp2() {
            return 0;
        }
        
        public void setProp2(int i) {
        }
    
        // Property PROP
        public byte[] getPROP3() {
            return null;
        }
        
        public void setPROP3(byte[] bytes) {
        }
    }


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.