Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to show all data in javabean with reflection API ?

 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • 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 .....
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • 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.
 
Nate Forman
author
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thank you very much.

I'm try to do that.
 
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!