File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Form Bean scope problem   Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Form Bean scope problem   " Watch "Form Bean scope problem   " New topic
Author

Form Bean scope problem

Java Buzz
Greenhorn

Joined: Mar 11, 2005
Posts: 10
Hi,
I am facing a weird problem with struts. I have a link on the first page of my application, clicking on which I invoke a action class. It connects to database, pulls out data populates a form bean and forwards to a jsp.

In the jsp, I am accessing the properties of the form bean and I am displaying. But when I run the same, all the values displayed are empty. However logs at action classes convey that data was fetched from database and is set into the form bean. I have set the scope of the bean to be request.

Any guess what could be the problem?

Regards,
Hari
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
This question is better suited for Struts forum.


In the jsp are you getting the bean or you are getting the bean without the values?
Note : If the bean doesn't not exits , then its creates one.What I guess is you are setting the bean in one scope and then trying to retrieve it back from some other scope , that might be the reason that you are getting the bean and not the values.

You can even look at the serverts which is being created out of your jsp for seeing as what actually is going.


Rahul Bhattacharjee
LinkedIn - Blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

"Java Buzz", you have previously been warned on one or more occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it prior to your next post.

Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Be aware that accounts with invalid display names are removed.

bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Mr. Buzz:

Are you instantiating a new instance of your Action Form in your action code or are you using the form passed in as a parameter to the execute method? If you are instantiating a new form, then you have to save it as a request attribute with the same name defined in struts-config. A better option might be to change your action mapping and use the form passed in.

- Brent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Form Bean scope problem
 
Similar Threads
form field population done right
problem with registration page
Maintaining form data across pages
Combo box building
Collections and Struts...