File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Passing parameter to action method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Passing parameter to action method" Watch "Passing parameter to action method" New topic
Author

Passing parameter to action method

John Sears
Greenhorn

Joined: Sep 15, 2009
Posts: 14
Hi,

I'm trying to implement table containing a list of elements with a link to delete each element. I am using struts2 for the project.

In my action class I have a method:


that removes the item at that index.

In my JSP, I basically want the following functionality:



This doesn't seem to work though. Is there a way to pass an argument like this?

Thanks!
John
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Yes; like you're doing it. Is dynamic method invocation turned on? Why doesn't your method return a String? What steps have you taken to debug it so far? ItDoesntWorkIsUseless .

Note that performing destructive operations from a link can be risky if your page is crawlable.
John Sears
Greenhorn

Joined: Sep 15, 2009
Posts: 14
Thank you for the quick reply! I get the following message when I click on the link:

java.lang.NoSuchMethodException: *.*.*.ViewParticipant.deleteProgram()

That's why I figured that it was probably not valid to pass the parameter like that. I haven't been sure how to debug because the method never actually gets called.

Finally, if I set id as a private instance variable (with getters/setters) of the viewParticipant action, it gets set on clicking 'Delete'. So it is passing the parameter to the action, not to the method.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Try creating the right method signature and see if that fixes the issue. The paradigm itself is fine; I used to use it fairly frequently.
John Sears
Greenhorn

Joined: Sep 15, 2009
Posts: 14
you mean returning a String? I actually was already, I just miscopied that when I posted this. I have edited the first post to correct the typos in the first one (apologies for that). If you could, take a look now:
John Sears
Greenhorn

Joined: Sep 15, 2009
Posts: 14
Also, thanks for the warning about destructive links and crawling. This page is going to be behind an authentication system and will be inaccessible to web crawlers.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Google desktop.
John Sears
Greenhorn

Joined: Sep 15, 2009
Posts: 14
well it will be running on a linux server, so hopefully not. In any case, any ideas why it would not be working?
Aj Kot
Greenhorn

Joined: Nov 04, 2009
Posts: 1
I am new to struts2 how to make the dynamic method invocation turned on?please advice on the jsp nested custom tags issue as well.
Did you got any solution to this problem,i am having similar Issue where the getter is not getting called in the action.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@Java struts: Please read the JavaRanch naming policy and fix your name accordingly. That aside, that's not even legal JSP--you can't nest custom tags like that. Also, please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.

@John: So far I'm not sure. Maybe post the complete configuration for the action, the HTML/JavaScript rendered, etc. Is dynamic method invocation turned on?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing parameter to action method