I'm not very happy with my previous solution - I mean that I call one, named JavaScript function for modifying style for the row.
In this example it does not matter but assume that we have a lot of views and every view requires different row modifier. Calling one JavaScript function for all view is not a good idea.
So I decided to introduce "dynamic" JavaScript function - the name of JavaScript function is taken from resource and can vary.
So instead of:
private class AddStyle implements RowStyles<EmployeeRecord> { |
|
@Override |
public String getStyleNames(EmployeeRecord row, int rowIndex) { |
|
.... String jsString = js.createJsonString();
return jsAddStyle(parseJson(jsString)); |
} |
}
public static native String jsAddStyle(JavaScriptObject o) /*-{ |
return $wnd.jsAddStyle(o); |
}-*/; |
|
The following code was introduced (
code).
private class AddStyle implements RowStyles<EmployeeRecord> { |
private final String jsString; |
@Override |
public String getStyleNames(EmployeeRecord row, int rowIndex) { |
|
|
String jsString = js.createJsonString(); |
|
return callJsStringFun(jsFun, jsString); |
} |
|
} ....
public static native String callJsStringFun(String jsonFun, String paramS) /*-{ |
return $wnd.eval(jsonFun + '(\'' + paramS + '\')'); |
}-*/; |
|
JavaScript function should follow the
pattern. Of course - in this example jsString (as above) should be equal to 'jsAddStyle'.
|
function jsAddStyle(s) { |
var o = eval('(' + s + ')'); |
var job = o.Employee.job; |
if (job == 'MANAGER') { return 'addRow'; } |
return null; |
} |
|
So this way every view could have its own customized function identified by name.
Brak komentarzy:
Prześlij komentarz