wood burning stoves*
The moose likes Beginning Java and the fly likes Sequence of Properties returned by BeanInfo's getPropertyDescriptors 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 "Sequence of Properties returned by BeanInfo Watch "Sequence of Properties returned by BeanInfo New topic

Sequence of Properties returned by BeanInfo's getPropertyDescriptors

Suresh Kumar Ramasamy

Joined: Mar 18, 2008
Posts: 7

I guess getPropertyDescriptors returns PropertyDescriptor(s) in the alphabetical order of (property)Name. Is there a way to change this (Requirement: Order same as the order, the properties are coded in the bean)?

One solution is to prefix the properties with a sequence no. (like _01, _02, and so on.), but this impact the getter and setter method names as well

If you know of any (neat) alternatives, could you please post.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

The API documentation of BeanInfo.getPropertyDescriptors() does not say that it returns properties in a certain order (alphabetical or otherwise). So, the order is undefined. That you see them in alphabetical order should be considered as a coincidence - there is no guarantee that you will get them in alphabetical order.

So prefixing names may work, but it may not work in an older or newer version of Java - the order is simply unspecified. If you want the properties in alphabetical order, you should sort the array returned by getPropertyDescriptors() yourself.

There's no way to get the properties in the order as defined in the source code of the bean.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
I agree. Here's the link: http://aspose.com/file-tools
subject: Sequence of Properties returned by BeanInfo's getPropertyDescriptors
Similar Threads
Call alot of setters from another class
[Wicket] Form Binding Overly Complex?
Properties file
Rearrange Order of Messages in FacesMessages
Dynamically populate java bean tree