How to use History.js with GWT? - gwt

I want to use History.js from Google Web Toolkit.
I know GWT has History functionality of it's own, but I don't like it because it uses the hashes in the URI, I want to use the new HTML5 History API as much as possible.
The only current way that I can think of to run History.js and GWT together is to write the History.js part in plain Javascript (or jQuery) and then manually call a GWT method.
It would be nice if it was possible to use the whole History.js functionality from within GWT's Java files.

No pain at all with that .
You just simple add your History js file on your document and you can use it .
Here i answered how you can use an external js in GWT .
Using externel js in GWT
After you call the native method you can continue with gwt method

Related

I am confused about JSNI.How and when use of JSNI in Google web toolkit

I am new Google web toolkit.I am confused about JSNI.Why and when use of JSNI in Google web toolkit.Advantage and limitation of JSNI.Thanks in advance.
I use native Javascript code when there is no other way of coding the feature other than in Javascript. For example, there is no wrapper for XmlHttpRequest object in GWT. I could use either third-party solution if it exists, or write my own classes based on javascript-based sample code found around on the web. So, I have this native method that I can call from my pure Java code and that contains only Javascript code. JSNI allows me to share the data between these two worlds.
And after all, after permutations are compiled, both Java and JS native methods are build into Javascript.
If you want to use various Javascript libraries, then JSNI will let you to call methods as designed wrapped into your Java methods. Again, for example, you can include Modernizr.js script into your html page and then have something like this in your class:
private native boolean isCSSAnimationSupported() /*-{
return Modernizr.cssanimations;
}-*/;
I do not use native methods when there is no actual need to inject inline Javascript.
Beside the points alexp already mentioned, there is another situation, where JSNI is a very useful.
Imaging, you have several GWT applications and in case you left one and start another, you want to send some informations to the starting GWT application.
You have several possibilities to do that:
you can use URL parameters
you can use a cookie
or use an JSP and JSNI.
There fore, you use a JSP instead of a HTML as your host page. Inside this JSP you can use a JSP tag of a hidden field to carry your parameter and with JSNI you can read the parameter out of your host page.

GWT IndexedDB available or any update on this?

is there any update on GWT IndexedDB?
Here are two projects of GWT IndexedDB but i dont know if this is usefull because these two projects seem to be dead?!
http://code.google.com/p/indexeddb-gwt/
http://code.google.com/p/gwt-indexeddb/
IS it possible to use GWT IndexedDB by JSNI? Has anybody experience with it?
Would like to learn and to use IndexedDB but dont know because iam using only GWT and not JavaScript.
Please help!
You can use any pure javascript/browser functaonlity from GWT using JSNI.
If youu look at the above linked Indexdb gwt libraries they do just that. They define JSO Overlay wrappers for the corresponding javascript objects. (see here as an example).
Alternatively you could also look into the Elemental library. I am not 100% sure but it might contain wrappers for IndexDB.
So you have 4 choices:
Manually call the indexdb javascript functons using JSNI.
Write your own wrapper using JSO and JSNI
Use on of the indexdb GWT wrappers
Use Elemental library.
I used java Maps (TreeMap) package to emulate indexedDB searching functions and GWT built-in html5 storage wrapper to store data offline in browser.

GWT and web template with javascript

I have GWT Web application and web template that consists of html+css+javascript files.
UiBinder holds html template in HTMLPanel. Problem is that this template is based on many javascript files and I know that GWT have problems with that. So my page is rendered without some javascript features.
What can I do with this? What is correct solution for GWT and external web templates?
The issue is not GWT-specific: you cannot inject <script>s using innerHTML (which HTMLPanel ultimately uses).
If you need to dynamically inject scripts in your app, then use ScriptInjector.

GWT Fragment Idenfiers

So far what I have used with my gwt application is a simple FI, like #login, #welcome etc.
However I want to "refactor" my application in a more descriptive way, I need make it this way:
http://localhost:8080/main#login
http://localhost:8080/main#search
http://localhost:8080/profile#<username>
http://localhost:8080/api
etc.
Can I do this with GWT?
If you want to stay on the same GWT application, you'll have to use the HTML5 History API (pushState and onpopstate) instead of GWT's default History (or DefaultHistorian) implementation; which means your app would only work with browser supporting the HTML5 History API (or you'd have to provide a fallback).
This is possible with GWT, but if you don't know how to do it and/or how the HTML5 History API works, it'll cost you a lot (of time).
BTW, if you ever switch to the HTML5 History API, why keep some fragment identifiers?
The alternative is, as milan says, to split your app into smaller parts (/main, /profile, /api, etc.)
Yes, but /main and /profile are going to be separate (html) pages, so you'll have EntryPoint for each then (loading/unloading GWT modules). Is that want you want? Google's AdWords is an example (written in GWT), each tab is a separate HTML page (/dashboard/, /cm/CampaignMgmt, ...).

GWT/java and javascript

can i design my web pages in html and css instead of java methods and use gwt only in parts of page that i need ajax? and which one is better gwt, extgwt, vaadin(it run apps in server-side.can i also use it in client-side?), etc...? do i also need to know javascript for using gwt?
thanks
can i design my web pages in html and
css instead of java methods and use
gwt only in parts of page that i need
ajax?
Yes, you can. You can create a div on your HTML page and insert your GWT widget there.
which one is better gwt, extgwt,
vaadin(it run apps in server-side.can
i also use it in client-side?)
I don't know about vaadin but Ext-GWT is a set of ready made components to use with GWT which make your life easier especially if you want to build an web app that looks and feels like a desktop application.
do i also need to know javascript for
using gwt?
No, it can be useful sometimes but is not necessary.