my dog learned polymorphism*
The moose likes Struts and the fly likes two actions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "two actions" Watch "two actions" New topic
Author

two actions

James Workmen
Greenhorn

Joined: Oct 06, 2004
Posts: 26
I have some links in my jsp page and each link should submit to different action. My actions inhert from DispatchAction.




When I click the link, it should execute the viewEditRequest method in
CreateRequestAction. My RequestForm.java also has the variables dispatchID and methodName ...abd corresponding get/set.

Its working when I directly submit the form by clicking a submit button with hidden fields but wont work when I have a link with different action.
May be because its cofused with the ActionForm...i dont know...
Help!!!
John Smith
Ranch Hand

Joined: Sep 02, 2004
Posts: 61
Have you given the hidden submit buttons an id each and tried document.getElementById('button_id').click() to ensure you're submitting the correct button?
James Workmen
Greenhorn

Joined: Oct 06, 2004
Posts: 26
When I click the submit the button, it submits to the 'createSearchAction'
action and I am sending two hidden values along with it.

And in the Search Action it is executing the viewEditSearch method.

The problem is when I submit those values along the link, like,


it is not executing the method in Request action.
I do not the reason...
James Workmen
Greenhorn

Joined: Oct 06, 2004
Posts: 26
All I need is submit to a different action with different form bean in JSP.
John Smith
Ranch Hand

Joined: Sep 02, 2004
Posts: 61
I'm not sure what you're trying to acheive and why you're doing that. If you put the values on the request you're not actually submitting the form and don't need an ActionForm class at all, you can put those values there dynamicaly with javascript from any normal text input field. So unless i've mis-understood what you're saying here you either don't need a form at all or you should have 2 hidden submit buttons (not links) that don't have request parameters which will submit to your dispatch action path. The whole idea of a dispatch action is to not have 2 action paths so having that setup the way you do with seperate forms isn't the right way to go about it.

I would make an action mapping to submit your form to which will internally select whichever method and redirect from there to whichever action you want to invoke. The idea of a dispath action is not to call two different actions but to call one action which will internally execute the approriate method as you have set up in the java class
James Workmen
Greenhorn

Joined: Oct 06, 2004
Posts: 26
You are right. I am doing exactly like you mentioned. I have action mapping to submit the form which will internally select whichever method.

But what do you mean when you said 'redirect from there to whichever action you want to invoke.'


The scerario is I have a JSP...and I have couple of actions in the JSP like 'edit', 'save' and 'delete' buttons which I when I click, invoke the appropriate method in my action.

But I have at the top of the page have menus, (href links) which should take to another page, so I have given a value of another action with some required data,
like
<a href="/anotherAction?disoatchID=3...">Request</a>

So the whole page is like this...


The above submit button, submits to searchAction and is executing the viewSearch method in the action. But when I click on the above link it is submit to 'anotherAction' and execute the 'viewEditRequest' method in it.
It is throwing the following error

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: two actions