• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts 2 cannot retrieve java bean object

 
Abhilash Chander
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic