Meaningless Drivel is fun!*
The moose likes Struts and the fly likes Populating the FormBean/Business Tier Bean - doubt on Introspection/Reflection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Populating the FormBean/Business Tier Bean - doubt on Introspection/Reflection" Watch "Populating the FormBean/Business Tier Bean - doubt on Introspection/Reflection" New topic
Author

Populating the FormBean/Business Tier Bean - doubt on Introspection/Reflection

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi there !
I�ve just had a problem for populating my Business Tier Bean from the FormBean. In fact, every attribute with compound names, like userName , dateOfBirth , and so on, ended �unpopulated� after the BeanUtils.populate... Searchig for the root cause, I remembered that for using JSTL ,for instance, (which uses Introspection/Reflection) I had to write setters and getters with their names all in lowercase or maximum the first letter of the attribute�s name in uppercase... (setusername() or setUsername,...) So I applied it to my beans and everything worked fine...
Does anyone could tell me the reason for this , once we usually name setters and getters as ordinary methods , like setUserName...
Thanks in advance,

Fabio
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
You say you are using BeanUtils.populate() and not BeanUtils.copyProperties(). The populate() method requires a Map as the source of the originating data according to the API, is this what you are passing in?
I ran the following test code and received the expected results. All I can think of is maybe double checking your capitalization for your properties and method names where appropriate (for example, userName and getUserName() ).
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
In fact , I used BeanUtils.populate(targetBean,BeanUtils.describe(sourceForm)) ... due to the Map question... But, my doubt is more concerning the need for this strange way of naming the setters and getters... If you code setUserName instead of setUsername or setusername, it doesn�t work ! The same when using JSTL...
tks
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
While copyProperties() is more efficient in this case, I did re-write my test code to do what you are trying to do (BeanUtils.populate from a DynaBean to a business object) and it works fine for me. There are no strange naming conventions I needed to do to get anything to work. All I can suggest is to have a closer look at your property and method names as suggested in my previous post.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks Jason . Very kind of you.
Refining the question :
I�m experiencing problems involving introspection/reflection under Tomcat when using JSTL and STRUTS.
In the command line, the above Jason�s example worked very well , BUT, when I try to do the same under Tomcat, it just doesn�t work unless I change the naming of the setters/getters methods... I mean , unless I create setUsername/getUsername or setusername/getusername and setDateofbirth/Dateofbirth or setdateofbirth/getdateofbirth , the instrospection doesn�t work at all ! I�ve already tested it for JSTL tags and STRUTS (populating a business tier bean from a FormBean) and unless I name these methods this way , I don�t get it working !
Could anyone please tell me what happens ???
Thanks !
F�bio
Tiago Fernandez
Ranch Hand

Joined: May 16, 2003
Posts: 167
F�bio,
I'm having the same problem, and the Jason's tip didn't work at all in the Apache Tomcat 4.1 web container.
The instrospection only work in the command line... spooky!


Tiago Fernandez
http://www.tiago182.spyw.com/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Populating the FormBean/Business Tier Bean - doubt on Introspection/Reflection