Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing parameters between actions

 
Oliver Moore
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have the following 2 actions, addGalleryPictureAction and listGalleryAction shown below, chained together with struts. The general idea is that on successful file upload, a new list of pictures should be generated and then passed to a page to display this new list. All this depends on the paramter marina_id, which is passed from the upload form to the add action. However, it does not get passed to the list action. Printing the marina_id in the list action shows it as null, even though I am explicitly setting it in the add action.
The list action definitly works both individually and as part of a chain, and the add action completes as the picture is created, as are the DB entries. The only difference between this and other code blocks with a similar flow is that the original uplaod form on the jsp is set to multipart/form-data... Should this make any difference?
Any help would be gratefully recieved...
Regards,
ols

 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would this thread shed some light on things?
 
Oliver Moore
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lasse,
Thanks, that does illustrate a few things I wasn't aware of, however, I have a couple of questions.
As I understand it from the post you suggested, the following happens:
1)form submitted
2)paramters placed into request header
3)struts places parameters into associated formbean
4)action completes then forwards to uri defined in struts config
5)2nd action instanciates, and the only paramters available to it are those it submitted by the form (1)
Is this correct?
As I understand it now, all the original paramters should be available in the request accoss the whole action chain. Placing parameters in a form bean only copies them from the request into the bean, not remove them from the request?
By stating that the request parameters cannot be be changed, I assume this means that that the original values passed into the action (and therefore used to popluate the associated actionForm) cannot be changed. However, you can add parameters to the request, such as a resultSet which is then forwarded to a JSP and those values will be available. In the case above, I can add messages to the request which are passed, but no other parameters I put in are passed. Is this what you would expect as messages use a different mechanism to attach to the request?
Whilst exploring this problem, I stopped forwarding to the 2nd action, and started going to a JSP. I also added a hidden value "test" in the form which is not associated with the formBean for the add action. I would expect this to be available to the JSP the action forwards to by using a request.getParameter, but it is not. As this "test" request paramter is part of the original input, should I not be able to access it as I'm not attempting to modify it in any way?
Thanks for your help...
 
poornima balagopal
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am replying based on what i understood from your question ok
In my application i have one jsp which i am using for different puposes.
For each purpose i have different Methods in my action class . When i load the page for the first time i i will enter a value and submit the page to retrieve the data from the data base. then with the result it will be reloaded.
I want the value i selected in the method which i am calling at the last of my processes(i mean before this happens a number of times page will be reloaded for different purposes)
So when i come from the above mentioned method say getDetails() to the i set a value in the request as
request.setAttribute("dCode",dCode);
This value i get from FormBean
When i call the main method to do the actual processing i will pass this parameter from the jsp as
function getPrfdBorrowerDetails()
{
document.crmsMergeBorrowerForm.action = "<%=request.getContextPath()%>/crms/jsp/crms/MergeAction.do?option=getPrfdBorrowerDetails&dCode=<%=request.getAttribute("dCode")%>";
document.crmsMergeBorrowerForm.submit();
}
(This javascript function i call on the submit of the page )
I dont know this will solve your problem. And please check the scope you are giving in the action mapping.
 
Junilu Lacar
Bartender
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Oliver Moore:

By stating that the request parameters cannot be be changed, I assume this means that that the original values passed into the action (and therefore used to popluate the associated actionForm) cannot be changed. However, you can add parameters to the request, such as a resultSet which is then forwarded to a JSP and those values will be available. In the case above, I can add messages to the request which are passed, but no other parameters I put in are passed. Is this what you would expect as messages use a different mechanism to attach to the request?
Whilst exploring this problem, I stopped forwarding to the 2nd action, and started going to a JSP. I also added a hidden value "test" in the form which is not associated with the formBean for the add action. I would expect this to be available to the JSP the action forwards to by using a request.getParameter, but it is not. As this "test" request paramter is part of the original input, should I not be able to access it as I'm not attempting to modify it in any way?
Thanks for your help...

It seems to me you've gotten confused with the parameters and attributes collections of the Request object. The parameters collection cannot be modified -- there is no public setParameter() method on a Request object. The attribute collection can be modified with setAttribute(). This is the collection that you need to put your "test" value in, not the parameters. Then you need to call request.getAttribute instead of request.getParameter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic