Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Struts and the fly likes Struts 2 cannot retrieve java bean object 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 » Frameworks » Struts
Bookmark "Struts 2 cannot retrieve java bean object" Watch "Struts 2 cannot retrieve java bean object" New topic
Author

Struts 2 cannot retrieve java bean object

Abhilash Chander
Ranch Hand

Joined: Oct 18, 2009
Posts: 39
Hi All, I am devolping an application in struts 2 ver 2.0.11. I have created a login screen and back end validation of Username and password. When the user gets validated, I set his username and password in a java bean. Which I want to display on the home screen. But I am unable to do so. My code is given below.

Here is my action class loginCheck.java :


My Business class 'loginVal' :


java bean class 'setUserPass.java' :


And finally my Home page 'home.jsp' :


In the home page if I use 'var' attribute it gives me an error. so I'm bound to use 'Id' tag here. But its still not working with that.
Thanks in advance.
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Quoting the bean tag's documentation:

Instantiates a class that conforms to the JavaBeans specification.


You don't want to instantiate the bean, you need to access the one created in checkUser(), which currently is lost. You could add it to the session and access it with s:property!


OCJP 6 (93%)
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
The bean you are creating with this tag:

<s:bean name="com.off.others.setUserPass" id="sup">

is a new instance of the class, unrelated to the one you populated during execution of your class. This is why you aren't seeing any values for user name and password. In your JSP, the data you have access to is the data that can be obtained for the getter and setter methods of your action class. If you take away your bean tag you'll access these values, but I'm not sure thats the data you are looking for. You probably either want to update the fields in the action class with the values you want to show up on the screen, or put new properties (and thier getters and setters) in your action class for the values you want to display.

Hope this helps
 
Don't get me started about those stupid light bulbs.
 
subject: Struts 2 cannot retrieve java bean object
 
Similar Threads
IBatis: boolean mapping misunderstanding
Implementing HttpSession in the Spring MVC
Problems with bean example
How to display Dynamic Menus and sub-menus using <s:iterator> tag in struts
Boolean and boolean problems in JavaBeans