• 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

Passing objects in struts2 <s:select

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

A newbie question. I have an <s:select set like this:

It renders fine on the page. Now I want to retrieve the selected doctor on my next page. But all I'm able to get is a String, which comes from the listKey. On my nextPage.jsp I have this:


If I change the type from String to Person, like this:

I get a

caused by


I could attach the whole stacktrace but it seems like my question is quite basic and I don't want to spam the post with it. So what's going on? How can I pass the selected Person object from one page to another? Right now I'm using the personID to get the object from the database but it's a bit ridiculous.


Thanks,
Eddy
 
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
Well using the id is generally the way to do it. You can create a custom type converter which will take the id and retrieve the related Person class object from the database (or wherever all Person objects are stored)...
 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit, thanks for writing back. So there's absolutely no way to pass objects? Not even on the request or the session?

Thanks,
Eddy
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

eddy johns wrote:Hi Ankit, thanks for writing back. So there's absolutely no way to pass objects? Not even on the request or the session?

Thanks,
Eddy



If you are looking to avoid database call then there are few ways to do so:
1. Implement caching mechanism in your application, where in during the first database call you can store the result in a map and next time using the key you can fetch the object back from the map.
2. If you are fine using the session object, then you can put the result from the first database call into session and later during the second submit, use the key to fetch the value back from the session object.
 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jaimesh, thanks for writing. Yes, I can see that these options would work. But still, disappointed I can't simply retrieve the object through the framework. It should be possible in our day and age..
 
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
What way do you expect to retrieve the Person object?? As Jaimesh said, you can store the Person list in a session. You can't know in advance which person the user will select so you'll have to store the whole list in the session. The other way is to retrieve the Person object through its ID and I told you how to do that in a modular way so that you can reuse the same code...
 
eddy johns
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just like the framework (struts) is passing the id, it can pass the object. So for example itemValue (or any other name) can carry the Person object. Other frameworks do that. For example Apple's WebObjects did just that over 10 years ago.
 
reply
    Bookmark Topic Watch Topic
  • New Topic