Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Struts and the fly likes Set a method when clicked on a hyperlink Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Set a method when clicked on a hyperlink" Watch "Set a method when clicked on a hyperlink" New topic

Set a method when clicked on a hyperlink

Dee Gee

Joined: May 10, 2006
Posts: 10
Hi All

In my application user needs to delete a few messages from time to time.
So the user will have a check box to select the messages and then a hyperlink "Delete the selected messages".

I have 2 problems here.
1)When the checkbox is clicked the textarea with the message should be disabled.
2)The hyperlink "Delete the selected messages" when clicked on should set a method DeleteMessage in class Messages. I am using a function setMethod which would set the particular method when a related button or link is cliked on. The code for the funciton is give below.

How do I achieve these two tasks. Please advice.

function setMethod(method){


Thank you,
Dee Gee
Chris Montgomery
Ranch Hand

Joined: Jan 14, 2004
Posts: 141
The disabling can be accomplished using JavaScript OnClick() event.

regarding the hyperlink item:
It looks like you are on the right track. You've created a field to hold the value of the method call. At the end of your java script, submit the form - document.forms[0].submit()

Then modify your action class to handle the method field.
if(myForm.getMethod() == "deleteSelectedMessages"){
// then forward me somewhere or back to that same screen...

// do other stuff

or however you want to do it...
Dee Gee

Joined: May 10, 2006
Posts: 10
Hi Chris

Thank you.

I have another problem,
How do I call this method from an hyperlink?

Say "when I click on Delete selected messages I should be calling a method and not going to another page.
If the method executed successfully it would forward you to a new page.

Dee Gee.
I agree. Here's the link:
subject: Set a method when clicked on a hyperlink