PDA

View Full Version : Is it possible to have a hyperlink in a template to link without page refresh?



jhudson888
29 May 2009, 6:22 PM
Hello,

I am using the templating feature of GXT to put some HTML content inside an HTML panel.

I would like to have a hyperlink which links to another page which works if I use href="#foo" but the problem is that the whole page refreshes... Is there any way I can call a method or something from a hyperlink? Like javascript: whatDoIPutHere()

Thank you very much for the help.

Joe

Rvanlaak
3 Jun 2009, 1:48 AM
Make links like below:




<a href="some-description" onclick="javascriptFunction(); return false;">text</a>

jhudson888
3 Jun 2009, 5:12 AM
Thank you for the reply.

I understand how to call javascript from a hyperlink but what I don't understand is how to call a GXT method from a hyperlink. For example (I'm just writing pseudocode here because I don't have my workspace up)


// some extension of ContentPanel
onRender() {
Map context = new HashMap();
loadContextParameters(context);
XTemplate template = getTemplate(...);
String transformedResult = transformTemplate(template, context);
}

private void methodToCall() {
// this is the method I would like to execute from the hyperlink
}

private native String getTemplateContents /* {
return "<a href='#' onClick='???'>click me</a>
} */
So, somehow I would like to call the "methodToCall" method from the hyperlink in the template. What would I replace with ???. Is this possible? Thanks.

Joe

sven
3 Jun 2009, 5:16 AM
Yes it is. You need to make the method public with JSNI and than call this public method on the onclick.

jhudson888
3 Jun 2009, 7:21 AM
Thank you very much sven. I don't exactly understand what you mean by that. Would you, by any chance, have time to provide a simple example? Thank you.

Joe


Yes it is. You need to make the method public with JSNI and than call this public method on the onclick.