java - GWT : Render a hyperlink in a TextColumn of a CellTable -
first of - beginner java , gwt. have scripting language background please explicit.
i have celltable populated data database( serverkeyword class gets data ).
mycelltable.addcolumn(new textcolumn<serverkeyword>() { @override public string getvalue(serverkeyword object) { // todo auto-generated method stub return object.getname(); } });
the example above works, shows data text. need make hyperlink, when click it, opens new tab location. i've surfed web , got conclusion need override render.
public class hypertextcell extends abstractcell<serverkeyword> { interface template extends safehtmltemplates { @template("<a target=\"_blank\" href=\"{0}\">{1}</a>") safehtml hypertext(safeuri link, string text); } private static template template; public static final int link_index = 0, url_index = 1; /** * construct new linkcell. */ public hypertextcell() { if (template == null) { template = gwt.create(template.class); } } @override public void render(context context, serverkeyword value, safehtmlbuilder sb) { if (value != null) { // template sanitize uri. sb.append(template.hypertext(uriutils.fromstring(value.getname()), value.getname())); } } }
now ... how use hypertextcell class addcolumn method in first code example?!
thank in advance!
hypertextcell hypertextcell = new hypertextcell(); column<serverkeyword, serverkeyword> hypercolumn = new column<serverkeyword, serverkeyword>( hypertextcell) { @override public serverkeyword getvalue(serverkeyword keyword) { return keyword; } }; mycelltable.addcolumn(hypercolumn);
Comments
Post a Comment