SV: What is the best way to pass a parameter to a forward? Create a utility class .Client code
Forgot to show the code how to use it! In your action you should not return return mapping.findForward("bla") but Hashtable a = new Hashtable();//add what ever key/value pairs you need return new ActionForwardParameters().add(a).forward(mapping.findForward("success")) ; -Oprindelig meddelelse- Fra: Tommy Holm - TELMORE Sendt: 16. marts 2004 13:48 Til: Struts Users Mailing List Emne: SV: What is the best way to pass a parameter to a forward? Create a utility class Some time ago this question has been asked before and someone showed some utility class code. I used the code and created a class like this: import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import org.apache.struts.action.ActionForward; /** * Simple utility class to add parameters to an ActionForward * from within an action. This action is useful when you from * within an action need to pass parameters to the jsp page or another action * you are forwarding to. */ public class ActionForwardParameters { /** * Encupsulates parameters for ActionForward. */ private Map params = new HashMap(); /** * add all the parameters and values from the hashtable to the actionforward * @param parametersValues a hastable with key value pairs * @return ActionForwardParameters object */ public ActionForwardParameters add(Hashtable parametersValues) { for(Iterator i = parametersValues.keySet().iterator();i.hasNext();){ String key = (String) i.next(); params.put(key,(String) parametersValues.get(key)); } return this; } /** * Add parameters to provided ActionForward * @param forward ActionForward to add parameters to * @return ActionForward with added parameters to URL */ public ActionForward forward(ActionForward forward) { StringBuffer path = new StringBuffer(forward.getPath()); Iterator iter = params.entrySet().iterator(); if (iter.hasNext()) { //add first parameter, if avaliable Map.Entry entry = (Map.Entry) iter.next(); path.append("?" + entry.getKey() + "=" + entry.getValue()); //add other parameters while (iter.hasNext()) { entry = (Map.Entry) iter.next(); path.append("&" + entry.getKey() + "=" + entry.getValue()); } } return new ActionForward(path.toString()); } } Please note that I didn't come up with the idea of this class, I simply created the class after reading the information that a fellow programmer Provided.! -Oprindelig meddelelse- Fra: Jay Glanville [mailto:[EMAIL PROTECTED] Sendt: 16. marts 2004 13:13 Til: 'Struts Users Mailing List' Emne: RE: What is the best way to pass a parameter to a forward? It's funny that you say that it will not work, because it does for me, and without throwing any exceptions. That being said, your point about modifying an action mappings forwards is a good one. It is unfortunate that the ActionForward class doesn't have a copy constructor -- Jay Glanville > -Original Message- > From: news [mailto:[EMAIL PROTECTED] On Behalf Of Martin Cooper > Sent: Monday, March 15, 2004 8:30 PM > To: [EMAIL PROTECTED] > Subject: Re: What is the best way to pass a parameter to a forward? > > > What you are doing will not work - at least, not the way you are doing > it. You are trying to modify the ActionForward instance that is > owned by Struts, > and calling setPath() on that instance will result in an > IllegalStateException. > > You need to create your own ActionForward instance, instead of trying > to modify Struts' one. You can do that with something like this: > > ActionForward goto = mapping.findForward( "success" ); > String path = ...; // Put together your new path > ActionForward myGoto = new ActionForward(path, > goto.getRedirect()); > return myGoto; > > -- > Martin Cooper > > > "Glanville, Jay" <[EMAIL PROTECTED]> wrote in > message > news:[EMAIL PROTECTED] > I'm trying to solve a problem, but I'm not sure my solution > is the best > way. Basically, I want to set a parameter on a forward within the > action's execute. > > I'm in my action's execute method. I've just successfully performed > some work, and I now want to forward/redirect to the next page. So, > I've got some code that looks like this: > >public ActionForward execute(ActionMapping.) { > // do some work > ActionForward goto = mapping.findForward( "success" ); > return goto; >} > > With an action mapping th
SV: What is the best way to pass a parameter to a forward? Create a utility class
Some time ago this question has been asked before and someone showed some utility class code. I used the code and created a class like this: import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import org.apache.struts.action.ActionForward; /** * Simple utility class to add parameters to an ActionForward * from within an action. This action is useful when you from * within an action need to pass parameters to the jsp page or another action * you are forwarding to. */ public class ActionForwardParameters { /** * Encupsulates parameters for ActionForward. */ private Map params = new HashMap(); /** * add all the parameters and values from the hashtable to the actionforward * @param parametersValues a hastable with key value pairs * @return ActionForwardParameters object */ public ActionForwardParameters add(Hashtable parametersValues) { for(Iterator i = parametersValues.keySet().iterator();i.hasNext();){ String key = (String) i.next(); params.put(key,(String) parametersValues.get(key)); } return this; } /** * Add parameters to provided ActionForward * @param forward ActionForward to add parameters to * @return ActionForward with added parameters to URL */ public ActionForward forward(ActionForward forward) { StringBuffer path = new StringBuffer(forward.getPath()); Iterator iter = params.entrySet().iterator(); if (iter.hasNext()) { //add first parameter, if avaliable Map.Entry entry = (Map.Entry) iter.next(); path.append("?" + entry.getKey() + "=" + entry.getValue()); //add other parameters while (iter.hasNext()) { entry = (Map.Entry) iter.next(); path.append("&" + entry.getKey() + "=" + entry.getValue()); } } return new ActionForward(path.toString()); } } Please note that I didn't come up with the idea of this class, I simply created the class after reading the information that a fellow programmer Provided.! -Oprindelig meddelelse- Fra: Jay Glanville [mailto:[EMAIL PROTECTED] Sendt: 16. marts 2004 13:13 Til: 'Struts Users Mailing List' Emne: RE: What is the best way to pass a parameter to a forward? It's funny that you say that it will not work, because it does for me, and without throwing any exceptions. That being said, your point about modifying an action mappings forwards is a good one. It is unfortunate that the ActionForward class doesn't have a copy constructor -- Jay Glanville > -Original Message- > From: news [mailto:[EMAIL PROTECTED] On Behalf Of Martin Cooper > Sent: Monday, March 15, 2004 8:30 PM > To: [EMAIL PROTECTED] > Subject: Re: What is the best way to pass a parameter to a forward? > > > What you are doing will not work - at least, not the way you > are doing it. > You are trying to modify the ActionForward instance that is > owned by Struts, > and calling setPath() on that instance will result in an > IllegalStateException. > > You need to create your own ActionForward instance, instead > of trying to > modify Struts' one. You can do that with something like this: > > ActionForward goto = mapping.findForward( "success" ); > String path = ...; // Put together your new path > ActionForward myGoto = new ActionForward(path, > goto.getRedirect()); > return myGoto; > > -- > Martin Cooper > > > "Glanville, Jay" <[EMAIL PROTECTED]> wrote > in message > news:[EMAIL PROTECTED] > I'm trying to solve a problem, but I'm not sure my solution > is the best > way. Basically, I want to set a parameter on a forward within the > action's execute. > > I'm in my action's execute method. I've just successfully performed > some work, and I now want to forward/redirect to the next page. So, > I've got some code that looks like this: > >public ActionForward execute(ActionMapping.) { > // do some work > ActionForward goto = mapping.findForward( "success" ); > return goto; >} > > With an action mapping that looks like this: > > path="/EntrySave" > type="com.package.EntrySaveAction" > name="EntryForm" > validate="true" > input="/Entry.do"> > > > > > Basically, if I left the EntrySaveAction.execute do what's doing right > now, then upon successful completion, it would redirect to > "/Container.do". However, what I want it to do is redirect to > "/Container.do?id=45", where 45 is the id of the container that I want > to go to. The value of "45" is dynamic, and is know at the time of > the EntrySaveAction.execute command. > > The way I'm currently doing it is something like this: > >public ActionForward execute(ActionMapping.) { > // do some work > ActionForward goto = mapping.findForward( "success" )
SV: Iterating List
The latter method would be the correct ! You could for clarity write the type of the id="myString" which is the object you access in every iteration and it would be required for other custom objects /Tommy -Oprindelig meddelelse- Fra: Daniel Henrique Alves Lima [mailto:[EMAIL PROTECTED] Sendt: 10. marts 2004 06:21 Til: Struts Users Mailing List Emne: Re: Iterating List How about this ? Ramadoss Chinnakuzhandai wrote: >finally I got the following working.. > > > > > >-Ramadoss > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
SV: Struts Workflow - Questions ?
Hi I am not sure if I understand your question right, but the way I understand it is. You have some action that either can forward to itself (looping) 3 times ( 4 time it should be a workflow violation) or in case everything is ok forward to another action ? Well you have a couple of options. You could have a action mapping like this In your somePossibleLoopingAction you could have a session variable that holds the count of unsuccessful logins, after the third it could foward to /someActionThatViolates, this action should of course have some states that would be violated and then the workflow engine would trigger a workflow violation where your session forms would be cleaned and you could eventually make sure that the user is banned or whatever you want. This should happen in your workflow violation action class. Just make sure you have a global forward like this ! And then of course the action mapping represented by the /handleWorkflowLoginViolation.do. - makes sure that this workflow is ended mailto:[EMAIL PROTECTED] Sendt: 2. marts 2004 18:16 Til: [EMAIL PROTECTED] Emne: Struts Workflow - Questions ? Hi, I'm trying to resolve a problem I have by making use of Struts Workflow - Using this as I need something that will prevent "jump-out" within the process The login process of my app has a number of conditions which dictate which page I send the user to next. I understand the basic's of the Struts Workflow but am a little confused when we get to the looping/forwarding aspects Basically the section of the flow is as follows: SecurityFilterAuthentication -> Is User Authenticated ? If Y -> StartWorkflow -> Retrieve User Settings -> Is 3fromN login required ? If Y -> Do 3FromN Else ->Record Successful Login -> ...Continue Workflow The 3FromN section has to allow the user 3 attempts and then do a Lock Out Action or if successful continue to the Record Successful Login Action How do I make those decisions within the workflow ? Do I have to have an action for every decision node or can I set what the next action should be in the active one using return (new ActionForward()); Regards Joanne Corless - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
SV: How to create an include which calls an action:
What I did is the following. I have a master jsp and in this jsp I inserted the following page. Now there are two important things to consider. First in your action mapping definition in this case viewNavigation.do you must add the redirect=true to the foward attribute. If you do this, your navigation action does not need to return null, if you don't add this attribute, then your action must return null. The problem with the latter, is that you can't call this action (viewNavigation.do) in any other way than using the tile tag, because it will jus be a blank page. Here is my action mapping! On my jsp page it looks like this Jsp start *** Bla bla Bla bla Bla bla Bla bla Jsp end My action does not return null because of the redirect="true" Hope this helps Cheers Tommy -Oprindelig meddelelse- Fra: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sendt: 25. februar 2004 21:31 Til: Tommy Holm - TELMORE Emne: SV: How to create an include which calls an action I'm getting the following error. Can you send me an usage example. I wonder if controller action returns jsp to include why should we give page attribute again? Thanks, Giri. Old message from Tommy ** No currently none of the proposed solutions worked. I am currently looking into the Tiles:insert tag Attributes are page = the jsp page to insert And most importantly there is an controller attribute which should be an action that perhaps prepares the jsp page. Just testing it now - HOLD ON - it works ... Check the
SV: How to create an include which calls an action
No currently none of the proposed solutions worked. I am currently looking into the Tiles:insert tag Attributes are page = the jsp page to insert And most importantly there is an controller attribute which should be an action that perhaps prepares the jsp page. Just testing it now - HOLD ON - it works ... Check the mailto:[EMAIL PROTECTED] Sendt: 25. februar 2004 15:39 Til: Struts Users Mailing List Emne: Re: How to create an include which calls an action Did anyone figure out how to do this? Giri SENji. -"Tommy Holm - TELMORE" <[EMAIL PROTECTED]> wrote: - To: <[EMAIL PROTECTED]> From: "Tommy Holm - TELMORE" <[EMAIL PROTECTED]> Date: 02/23/2004 10:38AM Subject: How to create an include which calls an action Hi everyone. I have a problem, I have a jsp page which should include the result of an action call. The action should prepare the bean associated with the action and create the jsp which then in the end should be included in the master jsp.(The include is a menu, which the action should prepare). The problem is that after the include, the rest of the JSP page is not rendered. It does somehow make sense but is there anyway around this or a common strategy to achieve this. Any help is greatly appreciated. Cheers Kind regards Tommy - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
SV:
Thx for your reply but if you don't foward to a jsp page, the jsp page never gets rendered and nothing is inserted in the main jsp page! Cheers -Oprindelig meddelelse- Fra: Niall Pemberton [mailto:[EMAIL PROTECTED] Sendt: 25. februar 2004 14:18 Til: Struts Users Mailing List Emne: Re: To: <[EMAIL PROTECTED]> Sent: Wednesday, February 25, 2004 1:07 PM Subject:
struts-user@jakarta.apache.org
Hi everyone. I have already asked this once but didn't get any answer, I have tried everything that I could think of but no luck, so if any of you have an idea what to do, I would really be happy for any help. I have a problem, I have a jsp page which should include the result of an action call. The action should prepare the bean associated with the action and render which then in the end should be included in the master jsp.(The include is a menu, which the action should prepare). The problem is that after the include, the rest of the JSP page is not rendered. It does somehow make sense but is there anyway around this or a common strategy to achieve this. Any help is greatly appreciated. Cheers Kind regards Tommy Cheers /Tommy - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to create an include which calls an action
Hi everyone. I have a problem, I have a jsp page which should include the result of an action call. The action should prepare the bean associated with the action and create the jsp which then in the end should be included in the master jsp.(The include is a menu, which the action should prepare). The problem is that after the include, the rest of the JSP page is not rendered. It does somehow make sense but is there anyway around this or a common strategy to achieve this. Any help is greatly appreciated. Cheers Kind regards Tommy - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
SV: SV: Struts Actions Forms Actions - ?????????
Ok lets look at it. You have a flow like this 1.) Selectmodel.jsp -> 2.) listModels.do -> 3.) listmodels.jsp -> 4.)listModels.do -> 5.)listmodels.jsp *** Correct ? >From which point doesn't it work anymore, after number 3 ? Are you using an action for forwarding to Selectmodel.jsp ? If you could show me your struts-config.xml, I probably would be able to help you much faster, because Your flow is extremely simple and should work straight out of the box. Anyway you must be able to find some log information somewhere. Cheers -Oprindelig meddelelse- Fra: Vinicius Carvalho [mailto:[EMAIL PROTECTED] Sendt: 26. januar 2004 17:21 Til: Struts Users Mailing List Emne: Re: SV: Struts Actions Forms Actions - ? Sorry, I don't think you understood my question. The problem is not within th but which action is the same that the on the other page will use. Got it? | Selectmodel.jsp | -- calls an action (listModels.do) via link --> forwards to |listmodels.jsp| -- calls an action (listModels.do) via submit --> forwards to listmodels.jsp Got it? At 14:21 26/1/2004, you wrote: >Are you using a and are you sure that you are mapping the action to the correct action >in the Did you implement the token check and >forgot about it, so that you actually are getting double form submit >exceptions ? > >I have once had the problem that we implement a token test on form >submits to catch client double submits, well that's great when you >update data but when you just view data it's not needed! Cheers >Tommy > >-Oprindelig meddelelse- >Fra: Vinicius Carvalho [mailto:[EMAIL PROTECTED] >Sendt: 26. januar 2004 17:07 >Til: [EMAIL PROTECTED] >Emne: Struts Actions Forms Actions - ? > > > Well, sometimes I wonder if struts is really the best >framework to use in our application scope, it brought so many problems >then solutions... > But now I think its too late. > Here's my problem (another one in the huge, never-ending list) > >I need to call the same Action from a link and a Form, this is simple >cuz the page rendered is the same, the diff. is that the first time >it's called >from a link it renders the form, and a list of default attributes, when >the >user submits the form (actually just change a select object) the list is > >changed (the select acts like a filter). Well, problem is its not >working. > >when the user clicks on the link, it fowards to the default error page, >trying to debug, I've noticed that the controller never gets to the >desired action (probably cuz the form class, can not get the getter and >setter for >its properties, cuz in the first call, the form does not exists yet). So > >what can I do to solve this? If at least the controller where getting >to > >the desired action, but it redirects the user before that. > >Thanks > >Vinicius > > >- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] > > >- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
SV: Struts Actions Forms Actions - ?????????
Are you using a Did you implement the token check and forgot about it, so that you actually are getting double form submit exceptions ? I have once had the problem that we implement a token test on form submits to catch client double submits, well that's great when you update data but when you just view data it's not needed! Cheers Tommy -Oprindelig meddelelse- Fra: Vinicius Carvalho [mailto:[EMAIL PROTECTED] Sendt: 26. januar 2004 17:07 Til: [EMAIL PROTECTED] Emne: Struts Actions Forms Actions - ? Well, sometimes I wonder if struts is really the best framework to use in our application scope, it brought so many problems then solutions... But now I think its too late. Here's my problem (another one in the huge, never-ending list) I need to call the same Action from a link and a Form, this is simple cuz the page rendered is the same, the diff. is that the first time it's called from a link it renders the form, and a list of default attributes, when the user submits the form (actually just change a select object) the list is changed (the select acts like a filter). Well, problem is its not working. when the user clicks on the link, it fowards to the default error page, trying to debug, I've noticed that the controller never gets to the desired action (probably cuz the form class, can not get the getter and setter for its properties, cuz in the first call, the form does not exists yet). So what can I do to solve this? If at least the controller where getting to the desired action, but it redirects the user before that. Thanks Vinicius - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Logic:iterateTag
Hi. I have created a html tag which can used neted inside the struts iterate tag. The idea is that the tag will generate the surrounding TR and TD tags, so that the data exposed from the iterate tag can be properly displayed in several columns for each row. Now the problem is that my tag requires to know the size of the collection which the iterate tag is iterating over. What I have done in the doStartTag is this: IterateTag parent = (IterateTag)findAncestorWithClass(this, IterateTag.class); if (parent == null) { throw new JspTagException("This tag must run inside " + "org.apache.struts.taglib.logic.IterateTag"); } else{ Collection temp = (Collection)parent.getCollection(); if(temp != null){ logger.debug("YEAH parent collection was not null and size is " + temp.size()); logger.debug("Lets check the ofset "); String offset = parent.getOffset(); if(offset != null){ logger.debug("Ofset is not null " + "value is " + offset); logger.debug("So the actual size should be " + (temp.size()- Integer.parseInt(offset))); } } else logger.debug("Collection from parent tag was null"); No matter what the collection from the struts iterate tag is alway null, which means it's a non initialized collection. What am I doing wrong ? How do I gain acces to the size of the collection that the iterate tag is iteration over ? Any help is greatly appreciated. Thanks Cheers Tommy Holm, System Developer TELMORE A/S - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Struts workflow question
Hi I have a problem which best is described as follows. I have a primary workflow(WF1) that at a certain time branches off to a secondary workflow. It is left in a state so that progess can be continued at a later stage. I my new workflow (WF2) I describe that a secondary workflow exist(WF1) etc. Now the problem, if WF2 fails, a cleanup of WF2 is performed but WF1 is left untouched which is not desireable. I would like to cleanup WF1 as well, how can you achieve that ? Now my second question, it should be possible for WF2 to depend on a secondary workflow (WF3), which means that I want to say, only execute the action belonging to WF2 if either WF1 is active or WF2. That does not seem to work. Can you not have more than one secondary workflow ? And what if only on of the secondary workflows are active, when the action associated with with WF2 is executed, will we have a violation then ? Thanks for your time Cheers Tommy Tommy Holm, System Udvikler TELMORE A/S Carl Gustavsgade 3, 2630 Taastrup Telefon 70218700, Mobil 22582344 www.telmore.dk - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
State change before form validation
I am currently using the struts workflow extension and I have stumbled upon some strange behaviour. When you on a jsp page with form and submit that form, the workflow state changes before the validation result is taken into consideration. Please correct me if I am wrong. This puzzles me because the idea of struts form beans are that if validation fails, you are being returned to the same page you originated from. That gives a problem because you then need to have a previous state for your action that is the same as the newState, otherwise you get a violation. Maybe I remember wrong but I seem to remember seing an answer (from Matthias who is one of the developers of the workflow extension) on the struts mailinglist that it's not a good idea to have a previous state that is the same as the newState, didn't understand why, so could anybody perhaps give a few comments on the state being set before form validation Cheers and regards Tommy Holm, System Udvikler TELMORE A/S Carl Gustavsgade 3, 2630 Taastrup Telefon 70218700, Mobil 22582344 www.telmore.dk - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
logic:iterate & JspException
Dear All I've got a question and seeking for answers. does anyone know what's wrong in the following code. tommySelectForm- public Collection getUse_list(){ ArrayList aa=new ArrayList(); aa.add("AAA"); aa.add("BBB"); aa.add("CCC"); return aa; } tommy_Select.jsp- struts-config.xml- type="tw.com.bct.online.tommy.TommySelectAction" name="tommySelectForm" scope="request" > Exception- Root cause of ServletException javax.servlet.jsp.JspException: Cannot find bean ddd in scope null Thanks Tommy