Javascript Na­tive In­ter­face (JSNI)

OpenSource For You - - DEVELOPERS OVERVIEW -

bven­tu­ally, we might need to in­te­grate hand­writ­ten gavaScript func­tions or third-party gavaScript li­brariesLwid­gets. GWT al­lows de­vel­op­ers to in­te­grate th­ese gavaScript li­braries into the client side of ap­pli­ca­tions through the gSNI in­ter­face. au­r­ing GWT com­pi­la­tion, gava source code is con­verted into gavaScript, and that’s when th­ese gSNI in­ter­faces are di­rectly XVHG Ln WKH finDO RXWSXW. TKH FRnFHSW RI -S1, LV LnVSLUHG IURP gava na­tive in­ter­faces. The key features of GWT gSNI are its abil­ity to im­ple­ment a gava method as a gavaScript snip­pet, and the abil­ity to call gavaScript from gava, and vice-versa. gSNI func­tions have to be de­clared na­tively and as static func­tions. All gavaScript code has to be em­bed­ded into com­ment blocks in­side the func­tion, as fol­lows: // gpkf func­tion SuEliF sWaWiF naWive voiG alerW(SWrinJ msJ) /*-{

$wnd.alert(msg); }-*/; // Call­ing gp func­tion from gava func­tion pub­lic void onClick() {

alert(“call­ing gpkf func­tion”); } //pam­ple in­vo­ca­tion sig­na­ture [in­[email protected]@Tual­i­fieG-Flass-name::meWhoG-name(in­SuW-Saram­sig­na­ture)(in­put-param-val­ues)

In or­der to in­voke gava code from a gSNI func­tion, it has to use a de­tailed method sig­na­ture ap­proach to dif­fer­en­ti­ate be­tween over­loaded func­tions.

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.