This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes help with reflection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help with reflection" Watch "help with reflection" New topic
Author

help with reflection

Marco Vanoli
Ranch Hand

Joined: Jan 12, 2005
Posts: 99
Hi,
I have a javabean;
in my program i have to analyze the bean , then put in a list all properties name (String) that have a set method and also a get method. (some properties could have only get or set method).

What can i use to do this work..??

I thinked to use the java.lang.reflect showMethods(bean) but i have to parse all stings and make checks for get and set.. it is cumbersome.

Isn' t there a quickest pratice to do this?
tnk


bye, <br />Marco
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The java.beans.Introspector class does exactly what you need. It provides all the information in a nicely structured way.


[Jess in Action][AskingGoodQuestions]
Marco Vanoli
Ranch Hand

Joined: Jan 12, 2005
Posts: 99
Yes think this is the right way but no example ho to use it

can somebody gimme an example of how to use Introspector on a bean to show its properies?

tnk
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Use Introspector's getBeanInfo() method and provide the class that has your bean properties as an argument. This method returns a BeanInfo object which will then return a list of properties from the class.

The challenge to you is to try it; post your code here for review if you like. More than happy to help you with code that isn't quite doing what you want.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Marco Vanoli
Ranch Hand

Joined: Jan 12, 2005
Posts: 99
Nice , i do it


Is it ok? It seems to work ..

Thank you very much!
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292



Nicely done; nothing to it.
 
jQuery in Action, 2nd edition
 
subject: help with reflection
 
Similar Threads
How to access method of another Bean
Show a progress page using Struts
bean method question
how to reset form bean properties
java bean in JSP ?