Results 1 to 5 of 5

Thread: Easy way to read a bean property programmatically?

  1. #1
    Join Date
    Sep 2005
    Posts
    21

    Default Easy way to read a bean property programmatically?

    Given an application context, bean id and property name, I need to be able to read the property value. I figured out how to set properties (with appropriate configurer) but not how to read them. I am sure it is so simple, I overlooked it :-)

  2. #2
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    Of course, the 'normal' way is to just get the property using the bean you get from the context: String v = beanFromContext.getV();

    Do you mean using the factory API directly?

  3. #3
    Join Date
    Sep 2005
    Posts
    21

    Default

    Quote Originally Posted by jbetancourt
    Of course, the 'normal' way is to just get the property using the bean you get from the context: String v = beanFromContext.getV();

    Do you mean using the factory API directly?
    I meant: to find the way to implement:

    String getBeanProperty(String beanName, String propertyName)

    without reflection, etc.

  4. #4
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    You would have to get the context's beanfactory and if its ConfigurableListableBeanFactory, you could get the actual bean definition which then would allow you to get properties and other stuff.

    Something like: context.getBeanFactory().getBeanDefinition()

  5. #5
    Join Date
    Sep 2005
    Posts
    21

    Default

    I just did:

    Code:
    	  BeanWrapper wrapper = new BeanWrapperImpl(bean);
    	  return wrapper.getPropertyValue(propertyName).toString();
    Seems to work

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •