Re: [Actionframework-users] Passing objects from request to another...
Status: Inactive
Brought to you by:
ptoman
From: Mandip S. S. <ma...@su...> - 2002-07-23 09:31:31
|
Hi Petr I realy like the "optional attribute for <in/output-variable>" idea mentioned in your email. I want to discuss how we could take this forward. As I mentioned in my previous email I had problems passing Objects from one request to another using the framework and suggested a solution which I thought could be messy. However, I have since implemented this idea and it actually works quite well. The solution was: "I could think about creating a component existing session-wide and place objects in it and possibly check this component for objects in the /editObject action for example." My xml looks like: <action name="/addObject" method="newObject()"> <on-return value="*" assign-to="objectStoreId" show-url="objectURL"> <output-variable name="objectURL" value="/ActionServlet/editObject/$objectStoreId"/> </on-return> </action> <action name="/getObject/$objectId" method="newobject(String objectId)"> <on-return value="*" assign-to="objectStoreId" show-url="objectURL"> <output-variable name="objectURL" value="/ActionServlet/editObject/$objectSoreId"/> </on-return> </action> <action name="/editObject/$objectStoreId" method="getObjectStore(String objectStoreId)"> <on-return value="*" assign-to="object" show-template="org/visres/ivr/security/view/EditObject.html.vm"/> </action> I have also created a seperate ObjectStore class that holds objects in a HashMap and allows entry of objects into the HashMap, returning a unique id for the object just stored, and also a object remove method. Another point is that I'm only interested in having an object stored while I'm on its corresponding add/edit page otherwise there is no need to have it around. If in our system we choose to add an Object and execute the /addObject action, the newObject() method will create a new Object and place it in the ObjectStore returning a unique store id. Now that we have stored a new Object the url is redirected to the editObject action which will pull this object out of the ObjectStore. Much the same happens when editing an object already in the database. If we execute the /editObject action passing the selected objects database id to the newObject(String objectId) method, the objects values are retrieved from the database and the object is stored returning its unique store id (remember that we will now have two id's for an object one being its actual id in the database and the other its id for the ObjectStore). Again the url will redirect to the /editObject action. So if, for example, I wanted to change the /addObject action to use your "optional attribute for <in/output-variable>" idea, then I'd like to totally replace the ObjectStore class, meaning that when I save an object to the session I'd like to get a unique store/session id in return and I'd also like to be able to remove objects from the session. I don't think simply adding a scope attribute to the <output-variable> tag will provide this functionality. You could decide that you do not want to provide all this functionality apart from adding objects to the session and leave the unique id functionality to the developer. What do you think? Also, a quick update on other aspects of the framework. First the issue of show-template/show-url attribute, since being able to pass objects from one request to another things are working really well. Our implementation is such that the show-template attribute is only ever used once on each template, if another action wants to reach this template then you are forced to call the show-url attribute that redirects to the action that contains the show-template for the template you wish to see. This ensures that any <output-variable>'s that are required for this template are loaded. Secondly, I also think we were possibly trying to do too much with the framework, where when a user updates a particular object and the updates throw errors, we were using actually using the <on-exception> tag to catch these errors and take the appropriate action. I think as far as redirecting to different url's is concerned the framework works really well but when you want to stay on the same url and produce some error messages then it's best not to throw this up to ActionServlet but to deal with it in your components. Sorry for the length of the mail, but if you've understood it that would be good, if you could make some comments/suggestions that would be REALLY good and if you could actually implement some of the ideas that would be absolutely AMAZING!!!! :-) Regards Mandip Petr Toman wrote: > > However this seems a bit messy. Do you think we need to add more > > funtionality to the framework? Perhaps we could have > > <session-output-variables> that place things into the session and > > then when looking for parameters for a method the framework would not > > only look for parameters in the request but the session aswell? > > Great! I believe this has much to do with David's suggestion ( > http://dione.zcu.cz/pipermail/as-list/2002-March/000014.html ). I've > been looking for a way to implement this consistently, but I think YOU > have made it! :) > > I would only introduce a new optional attribute for > <in/output-variable> rather than a new element: > > <output-variable name="number1" value="1" scope="session"/> > <output-variable name="number2" value="2" scope="request"/> > <input-variable name="number3" value="3" scope="session"/> > <input-variable name="number4" value="4"/> > > This would put number1 and number3 into Context AND session, while > number2 and number 4 into Context only. When retrieving values, AS > would look first into session and then into Context. > > -Petr |