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
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.
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 wrote:Hi Ankit, thanks for writing back. So there's absolutely no way to pass objects? Not even on the request or the session?
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.
Joined: Feb 16, 2010
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..
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...
Joined: Feb 16, 2010
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.