Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated vaadin-grid can't seem to utilize getItem #61

Closed
cpboyd opened this issue Feb 4, 2016 · 3 comments
Closed

Generated vaadin-grid can't seem to utilize getItem #61

cpboyd opened this issue Feb 4, 2016 · 3 comments

Comments

@cpboyd
Copy link

cpboyd commented Feb 4, 2016

Example code:

// Load 
grid.getPolymerElement().addEventListener(SelectedItemsChangedEvent.NAME, event -> {
    JsArrayNumber n = grid.getSelection().selected(null, 0, 200).cast();
    if (n.length() == 1) {
        grid.getItem(n.get(0), new Function<JavaScriptObject, Object>() {
            @Override
            public JavaScriptObject call(Object arg) {
                main.load(arg);
                return null;
            }
        }, false);
    }
});

The Object arg always seems to be null, regardless of which row is selected.

The issue seems to be that getItem() should take a function with two inputs (JSFunction2 in vaadin-grid's gwt code).
function (error, item) {}

Perhaps arg is simply the "error" input? (Which would make sense, as it should be null.)

There's not currently any way to easily get a specific row's data via the generated code.

@cpboyd
Copy link
Author

cpboyd commented Feb 4, 2016

It's not a huge issue in this particular case, since I'm keeping a copy of the item list in GWT and can just pull from there.

However, it could pose issues if there's other JS functions that take callback functions with more than one argument as parameters.

@manolo
Copy link
Owner

manolo commented Aug 23, 2016

It's almost impossible to figure out the arguments of a callback. Hydrolysis does not provide that info. Also we would need to define a hight amount of functional interfaces for all possibilities.

But because we are using the JsInterop @JsFunction, we can cast different implementations and your code would be like this:

// Define the function which matches the JS signature
@JsFunction
 public interface Function2 {
     void call(Object a, Object b);
 }
// Create your Function implementation
Function2 callback = (error, object) -> {
   if (error == null) {
       // Do something with object
   }
 };

grid.getPolymerElement().addEventListener(SelectedItemsChangedEvent.NAME, event -> {
    JsArrayNumber n = grid.getSelection().selected(null, 0, 200).cast();
     if (n.length() == 1) {
       // Cast it in the method call
        grid.getItem(n.get(0), (Function)callback, false);
     }
});        

@cpboyd
Copy link
Author

cpboyd commented Aug 23, 2016

Ah, ok. That works!

Thanks!

@cpboyd cpboyd closed this as completed Aug 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants