• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

struts 2: Stuck up with simple issue

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying with sample application to display values from object set in Action and trying to populate the same object values in jsp. But it is not populating in JSP file
Please help me, how to populate object values in jsp....

Here is my struts application code,


userList.java is normal java bean with getter and setter methods




JSP Page to access userList object values,


 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two problems with your code. One of them is logical and very small, since you know that you'll get only one row from your SQL statement, so you should use if condition instead of while loop i.e. if(result.next()) instead of while(result.next()). Now the id/var attribute of the s:bean tag is used to give the name of a bean on the value stack, but userList is a local variable not a field in your action class. If you move the declaration of userList outside of the execute method, your code should work...
 
Nandish Sri
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your quick response. I moved creation of userList object outside the execute method, but still nothing is displayed in the customerList.jsp.
Is there any other way, other than s:bean usage to access object in jsp like need to configure form-bean in struts.xml[I dont think it is required in struts 2.0]
I am not able to understand how to access object members from jsp page. Please let me know the solution.
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is there any other way, other than s:bean usage to access object in jsp


Yes, you can do it without using the s:bean tag like this

I actually didn't know the purpose of s:bean tag before this, it actually instantiates a new object and pushes it into the value stack, so your code won't work when you use s:bean tag even if you moved userList out of the execute method (as you already did)...
 
Nandish Sri
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried with these below code options, but still not getting userList object members.



 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did your Action class has setter & getter for UserList class?
 
Nandish Sri
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my userList.java file



And here is my Action class


And I tried with even by extends ActionSupport also. Not getting any value in jsp.
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sarada is spot on, you need to add setUserList and getUserList in your action class (at least getUserList is required)...
 
Nandish Sri
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He he... Thanks for your responses. Now I added getUserList in my Action class. Able to retrieve object members in jsp file.
Thanks a lot
 
reply
    Bookmark Topic Watch Topic
  • New Topic