Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2005

Tip: Looking for answers? Try searching our database.

invoking all setters in bean

Thread view: 
seller - 11 Mar 2005 17:45 GMT
coded this method in bean.  The intent was for the bean to run
all the setters using the values in a vector argument.  here's
the code:

    public void loadSelf(Vector v) throws Exception {
        String[] parms = new String[1];
        Class cls = getClass();
        java.lang.reflect.Method[] methods = cls.getMethods();
        java.lang.reflect.AccessibleObject.setAccessible(methods, true);
        int vectorPointer = 0;
        for (int i=1;i<methods.length;i++) {
            String method = methods[i].getName();
            if (method.indexOf("set") == 0) {
                if (!method.substring(3).equals("Class")) {
                    parms[0] = (String)v.get(vectorPointer);
                    methods[i].invoke(this, parms);
                    vectorPointer++;
                }
            }
        }
    }
my problem is that the setters are not running in the order that was
coded.
in other words, when i constructed the vector argument, the values do
not
match the setters.  

any ideas??
Dan Nuttle - 12 Mar 2005 03:59 GMT
The javadocs for Class.getMethods says, in part:

"The elements in the array returned are not sorted and are not in any
particular order."

So that's why they don't match.  There is no way to tell in what order the
methods will be in your Methods[] array.  To fix this, you could put your
values into a Map instead of a Vector (a List), and the keys for the map
could be the method names.

> coded this method in bean.  The intent was for the bean to run
> all the setters using the values in a vector argument.  here's
[quoted text clipped - 24 lines]
>
> any ideas??


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.