... | ... | @@ -232,3 +232,39 @@ Executing a Java function from within the html or another Javascript function is |
|
|
}
|
|
|
```
|
|
|
|
|
|
This snippet create an instance of a ```CorefViewParameterlessFunction``` and passes the function that should get called, the browser widget and the name of the function as parameter. By just creating this function, we basicly ntegrate it into the known functions of the browser. We can now actually call this function from within our HTML:
|
|
|
|
|
|
```html
|
|
|
<button type="button" class="btn btn-primary" onclick="createEntity();">New Entity</button>
|
|
|
```
|
|
|
|
|
|
This could obviously also happen in your separate javascript file. The mystery seems to be hidden in the implementation of the ```CorefViewParameterlessFunction```, which is shown below:
|
|
|
|
|
|
```java
|
|
|
public class CorefViewParameterlessFunction extends BrowserFunction {
|
|
|
|
|
|
Browser browser = null;
|
|
|
String functionName = null;
|
|
|
Runnable runnable;
|
|
|
|
|
|
|
|
|
public CorefViewParameterlessFunction(Browser browser, String name,Runnable r) {
|
|
|
super(browser, name);
|
|
|
this.runnable = r;
|
|
|
this.functionName = name;
|
|
|
System.out.println(name);
|
|
|
}
|
|
|
|
|
|
public Object function(Object[] args) {
|
|
|
if (args.length != 0)
|
|
|
return null;
|
|
|
|
|
|
runnable.run();
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
This class extends ```Browserfunction``` and the delegation to ```super()``` registers our function to the browser. The function ```function(Object[] args)``` gets called, whenever someone pushes the according button. Since we allowed this implementation to take a ```Runnable``` as input (which is a procedure that has no param and no return value) we can just run it inside the method.
|
|
|
|
|
|
|