File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Passing values to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Passing values to jsp" Watch "Passing values to jsp" New topic
Author

Passing values to jsp

Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
Hi

I want to be able to pass an object to jsp from one action class and then when user perform some action I want to be able to get that object. How di I do that. I tried using html:hidden tag but it gives me an "Illegal Argument Exception Null Value for 'MyObject'.

Any help is appreciated.
Thanks
Imad
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
One solution would be to specify the scope of your ActionForm as "session". This way the form and all objects attached to it will persist between requests.


Merrill
Consultant, Sima Solutions
Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
Sir

This is not a good option in my case. I dont want to set anything in session. Right now how it is working is in my struts config I have following

<form-bean
name="addressMaintenanceForm"
type="org.apache.struts.action.DynaActionForm">
<form-property
name="location"
type="com.r911.core.model.Location" /> .....
....</form-bean>

When I click save button on my addressMaintenanceForm I want this location object to be available as it is. Is there any other way beside setting it in session.
Thanks for your reply.
Imad
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Another solution would be:
  • Discontinue use of DynaAction form and write a form bean extending ActionForm.
  • put all fields needed to construct the Location object in the JSP as hidden fields (e.g. location.property1, location.property2, etc.)
  • In the getLocation() method, check to see if the location object is null. If it is null, instantiate it. Then, when Struts calls getLocation().setProperty1() the location object will be there.

  • Warning: The below statements consist of me getting on my soap box. Read on at your own risk

    We've all read the J2EE best practice white papers that say "Don't put unnecessary data or a lot of data in your HTTPSession". While I agree with this in principle, I believe many of this have taken this to mean "Don't put anything in an HTTPSession, and go to whatever extraordinary lengths necessary to avoid using it."

    The whole point of having an HTTPSession object is to allow us as developers to save bits of data that we might need between requests. As long as we use it judiciously and don't put the kitchen sink in the session, using it is quite often the best and simplest way of solving a problem.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Passing values to jsp