wood burning stoves 2.0*
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
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
Author

Set a method when clicked on a hyperlink

Dee Gee
Greenhorn

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.

<script>
function setMethod(method){
alert(""+method);
document.forms[0].method.value=method;

}
</script>

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.
<code>
if(myForm.getMethod() == "deleteSelectedMessages"){
myBusinessObject.DeleteSelectedMessagesMethod(myForm);
// then forward me somewhere or back to that same screen...

}
else{
// do other stuff
}
</code>

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

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: http://aspose.com/file-tools
 
subject: Set a method when clicked on a hyperlink