GWT: JsArray and JavaScript object - gwt

Am facing an issue while trying to implement an example given over a website.
One of the methods in a class has a signature like this -
private void updateTable(JsArray prices) {....}
And am trying to invoke this method from another method as -
updateTable(JsonUtils.safeEval(response.getText()));
while doing this am seeing a compilation error as -
The method updateTable(JsArray) in the type StockWatcher is not applicable for the arguments (JavaScriptObject)
Though I have just used the exact code displayed in the website, am seeing this error. Not sure what needs to be done. Please help.

The problem has been fixed by making the following change -
updateTable((JsArray)JsonUtils.safeEval(response.getText()));
introduced a casting in the above statement.

Related

Why can't I define a `delete` method?

I'm attempting to make a library with methods in a class that represent HTTP methods, such as GET, POST, and DELETE. I'm trying to do this with an abstract class that defines methods for each of these HTTP methods.
The problem comes in when I define a simple delete method for this class. This is what said method looks like:
/**
* A generic responder to a DELETE request.
*/
Response delete(Request request)
{
return new Response("Method not supported");
}
This should work fine in theory, but on compilation I get the error, no identifier for declarator Response.
Why is this error occurring? Removing the delete method makes the program compile, but having that one method in there makes it not compile at all.
Any help would be appreciated, thank you!
It is common practice to postfix keywords with underlines to be able to use them as variable names. See https://dlang.org/dstyle.html - Keywords

Glimpse ADO fails in Web Site project with TableAdapters - Part 2

This is a follow up to this problem.
That problem was fixed. However, new compiler errors occurred. The compiler errors indicate the following:
The Glimpse.Ado.AlternateType.GlimpseDbCommand class needs a default constructor
The Glimpse.Ado.AlternateType.GlimpseDbConnection class needs a constructor that takes a string (connectionString)
This second problem is strange, because the System.Common.DbConnection class does not have a constructor that takes a string either.

GWT Deferred binding failed for custom class: No class matching "..." in urn:import:

I am developing a couple of custom widgets that I would like to be able to use with UiBinder. Unfortunately I keep wasting my life away with chasing down the following error:
No class matching "..." in urn:import:...
This seems to be the catch-all exception that is thrown any time there is any error in the class that prevents the GWT compiler from processing it. This includes anything in the class's entire dependency tree.
To save myself and anyone of you who is running into the same issue some time and pain, let's compile a list here of the most unexpected and hard to find causes for this. I'll start with my latest one, which has made me decide to post this here.
I was using a CellList thusly:
private static RelationshipViewerUiBinder uiBinder = GWT.create(RelationshipViewerUiBinder.class);
#UiField(provided=true)
CellList<String> prioritisedDisplay;
public RelationshipViewer() {
prioritisedDisplay = new CellList<>(new TextCell());
initWidget(uiBinder.createAndBindUi(this));
}
note the Java 7 style <> on the CellList. Despite my IDE's protestations to the contrary, it turns out you DO need to explicitly say CellList< String> in that new call, or it wont compile and all you get is the above mentioned error. Thanks by the way, the existance of this question prompted me to scrutinise my code and probably saved me a couple of hours! This fixed it:
private static RelationshipViewerUiBinder uiBinder = GWT.create(RelationshipViewerUiBinder.class);
#UiField(provided=true)
CellList<String> prioritisedDisplay;
public RelationshipViewer() {
prioritisedDisplay = new CellList<String>(new TextCell());
initWidget(uiBinder.createAndBindUi(this));
}
I had written a component that used the GWT JSON functionality, but hadn't imported com.google.gwt.json.JSON into the module.
Thanks to your message here, this was only 2 hours down the drain...
I wrote a helper-class that this widget uses somewhere deep inside its dependency tree.
For this helper-class, I told Eclipse to auto-generate the hashCode() and equals(...) functions. The class contained a field of type double, for which Eclipse generates code that uses Double.doubleToLongBits().
Turns out GWT does not implement this method on its version of Double. But of course, neither does Eclipse detect this as a possible compile-error, nor does it cause any issues in Dev Mode if I use the widget inside the GWT-App's Java code rather than inside UiBinder.
3 hours down the drain... Great... Yay for helpful error messages.
UPDATE:
As of GWT 2.5.0 (RC1) GWT now supports Double.doubleToLongBits() rendering this particular error obsolete, but the general error mechanism of a missing JRE emulation remains and will probably manifest itself in a similarly unhelpful way.
I was trying to use a GwtQuery DragAndDropCellTree in a UiBinder .ui.xml, which was impossible as DragAndDropCellTree has no zero-arg constructor.
See more details

Could not find implicit value for parameter flash

I'm trying to port some code from Play Framework Java to Play Framework Scala but I'm having some issues with porting a tag.
The tag in question in the Java version checks the contents of the Flash scope and creates notifications to the user according to its values (error, success, etc).
I tried to create a Scala view (flag.scala.html):
#()(implicit flash:play.mvc.Scope.Flash)
#if(flash.get("error")) {
<p style="color:#c00">
#flash.get("error")
</p>
}
Which I call from main.scala.html via:
#views.Application.html.flag()
The error I get is:
The file {module:.}/tmp/generated/views.html.main.scala could not be
compiled. Error raised is : could not find implicit value for
parameter flash: play.mvc.Scope.Flash
The call to the new tag is correct, as if I replace the content by some String that's shown in the browser.
I'm sure it's something stupid but I got stuck. Any suggestion?
I don't know the details of Play, but this compile error is saying you should either:
Pass an explicit instance of play.mvc.Scope.Flash in the call to flag(),
views.Application.html.flag()(myFlash)
or
Make an implicit instance of Flash available in the scope where flag() is called. You could do this by importing the contents of some object (import some.path.FlashImplicits._) or by defining the implicit instance yourself,
implicit val myFlash: play.mvc.Scope.Flash = ...
...
views.Application.html.flag()
So the real question becomes: where do you want to get this Flash instance from?
You should not create an implementation for "implicit flash : Flash" on your own. Just add a "implicit request" to your action and it should work.
More details is here at the end of the page: https://github.com/playframework/Play20/wiki/ScalaSessionFlash
Ivan had the right suggestion, adding "implicit request". However, his link seems outdated. If you want a more explicit explanation, check out my answer to a similar question, here:
How to pass flash data from controller to view with Play! framework
I had the same issue but looking at the documentation i found the following:
If the error ‘could not find implicit value for parameter flash:
play.api.mvc.Flash’ is raised then this is because your Action didn’t
import a request object. Add an “implicit request=>”
of course the implicit Flash must appear in every view if you have nested views like:
#(implicit flash: Flash){
#main(){<h1>hello</h1>}
}
this view does not use flash scope but if main uses it, should be declared in views using main because the compiler will complain.
source: http://www.playframework.com/documentation/2.1.1/ScalaSessionFlash

GWT and Vaadin - variable is not a constructor stack

I have a strange error that I cannot make heads or tails of. A snippet of the error is below:
(TypeError): $wnd.EGeoXml is not a constructor stack: $jsInit([object Object],[object Object],null)
The actual lines of code is in GWT and looks like this:
private native void jsInit(JavaScriptObject map, String kmlFile) /*-{
var exml = new $wnd.EGeoXml("exml", map, kmlFile, {});
this.#com.example.client.EGeoXmlJava::ready(Lcom/google/gwt/core/client/JavaScriptObject;)(exml);
}-*/;
This code actually works when running as its own GWT project but when using this code with Vaadin, I get the constructor stack error. I'm positive the constructor exists. What I do not understand is why GWT thinks it's not a constructor? Thanks in advance.
You are calling it like new $wnd.EGeoXml(). The $wnd part looks bit weird to me. Is it necessary?
Anyway, if it is a problem only in Vaadin project, you might want check that the code resides in the right package. Remember that GWT wants the code to be in a package called .client. The server-side classes of Vaadin can be anywhere.