Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing values to jsp

 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic