File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6450
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6450
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 167
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic