• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to show all data in javabean with reflection API ?

 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to show all data in javabean with reflection API ?

i want to show data in all java bean BUT i don't need to write code like this in all javabean ::



BUT i want to write my code like this ::



So, i know how to implemet BeanUtil by using Reflection API to retrive data in java bean like Dynamic . BUT i don't know how to do that ???


thank for all javarancher .....
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure if java.lang.Class.getDeclaredFields()is what you are lookng for.
It returns all the fields for a Class.
Field supports a get(objectInstance) to get you the value for that field for a given object instance.
 
author
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Somkiat,

I agree with Karthik that getDeclaredFields() may get you what you want. Keep two things in mind when you use it:

1) It will get you fields of all visibility, but only those declared by the class, not the ones inherited. In order to get inherited fields, you have to traverse the inheritance hierarchy using Class.getSuperclass().

2) You may not want to display the values of all the declared fields. Your field names also may not be what you want to show. If either of these is the case, you'll want to use BeanInfo, etc. to do the job.

Also, I've been told that Apache Commons has some really great libraries for working with beans. I haven't had time to check it out myself yet, but they do some really good work...

Hope this helps,

Nate
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you very much.

I'm try to do that.
 
reply
    Bookmark Topic Watch Topic
  • New Topic