I am currently working on a GWT project where I am displaying an HTML file within an iframe in my application. This HTML file is actually being written to as it is getting displayed, and I am hoping to be able to reload the frame so that the changes made to the HTML file are reflected on screen. I am able to do this two different ways that both work when running in development mode, however neither seem to work when the project is deployed.
The first method I tried was setting the frame's URL to itself:
frame.setUrl(frame.getUrl());
The second method I tried using JSNI:
public native void refresh() /*-{
if($doc.getElementById('__reportFrame') != null) {
$doc.getElementById('__reportFrame').src =
$doc.getElementById('__reportFrame').src;
}
}-*/;
When deployed, the frame gets displayed in a Window, and when the file is finished being written to, a call to either of these refresh methods is made, and the frame refreshes to contain the finished HTML file. When I am deployed, the call to refresh does not reload the contents of the frame, however if I bring up the frame's context menu (in Firefox), then go into 'This Frame', and click Reload, it successfully reloads the frame to contain the finished HTML file. I have tested this on multiple versions of Firefox without any luck.
Does anyone have any suggestions? Why would the behavior be different from one mode to the other?
Thanks.
wow, google is really fast with his search^^
You can use some JSNI to do this. Create a method such as
protected native void reloadIFrame(Element iframeEl) /-{
iframeEl.contentWindow.location.reload(true); }-/;
Then call it with your iFrame element
so your question you posted twice was already answerd here
http://groups.google.com/group/google-web-toolkit/browse_thread/thread/64aa7712890652d3
We had a requirement where one GWT application(parent) had another GWT application(child) loaded in an iframe. The child application had to refresh the iframe after it performs certain DB operations. We used JSNI to accomplish the same.
private native void refreshChild(String url)/*-{
$wnd.location.href=url;
}-*/
In case, if the child frame needs to be redirected to another webpage, the url can be modified accordingly.
We did try to use the reload() method, but it did not help.
The above piece of code, of course needs to be written in the child application.
Related
I wanted to use window.name as a holder for some identifier to use whenever page refresh happens (or being forced). However, I've noticed that GWT sets it to rename-to property value defined in module definition. Is there any way to avoid it?
P.S. I know I can use sessionStorage, or maybe even some other mechanism. I'm just curious about this specific case -- would like to know how could I override such GWT behavior.
Are you sure the window is getting its name changed? I recall that the module changes the iframe that it loads into, but not the global window. Or are you using a different linker? Or referring to the window as window in your jsni instead of $wnd?
private native void setWindowName(String newName) /*-{
$wnd.name=newName;
}-*/;
We have an application built on GWT framework where we want to display a PDF file without any browser plugin and are currently evaluating PDF.js to do that.
The problem is, no matter what I do, I am not able to render a PDF file onto a canvas in our GWT application. Do give some background
The PDF file ticket is retrieved from server.
The PDF.js file ticket is retrieved from server and is embedded in the HTML body by using this script
var head= document.getElementsByTagName('body')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.setAttribute('charset', 'UTF-8');
script.src=url;
head.appendChild(script);
Canvas element is created in the View (using googles MVP pattern here) and a JSNI call is made to the script which embeds the PDF.js in the HTML body using the above function. The script then makes a call to function which works with PDFJS class defined in PDF.js file.
The function to render the PDF file on canvas is as below :
PDFJS.disableWorker = true;
PDFJS.getDocument(url).then(function getPdfHelloWorld(pdf)
{
pdf.getPage(1).then(function getPageHelloWorld(page)
{
var scale = 1.25;
var viewport = page.getViewport(scale);
canvas.height = viewport.height;
canvas.width = viewport.width;
page.render({canvasContext: context, viewport: viewport});
page.startRendering(context);
alert("Finished rendering");
});
});
The canvas and context are created in the View class and passed to the javascript.
The problem here is, after the call to JSNI is made, I show alerts of all variables. The browser shows alerts except when I make a call alert(PDFJS). This shows that PDFJS variable is not being recognised in the script.
This makes me think PDF.js file is not correctly embedded in the view or there is something else that I am missing.
Note: I have downloaded most of the examples over the net and most of them work locally i.e. I can modify the PDF.js file path to pick up a local copy and the HTML still renders the PDF. It has no problem reading the PDFJS variable. Its only in this GWT application that I see these problems.
Does anyone have any clue whats happening. Your help will be highly appreciated.
Thanks
Your problem is that you're injecting the script so it aloads asynchronously, but you don't wait until after it's loaded to start using it.
Try using ScriptInjector.FromUrl to inject the script and put the rest of your code in the Callback's onSuccess.
Injecting the script synchronously (by adding it to your HTML host page, or GWT Module descriptor —note: won't work with the xsiframe linker—), as proposed by Ilya is of course also a solution.
Try to add <script src="PDF.js"/> in your .gwt.xml file and put PDF.js file in your public director
Hi we have a gwt app hosted on google app engine.
In one of the page bound to an entry point class (using root panel id) we call a rpc service to get some data.
The problem I am observing is that when even the home page is loaded that time the entry module class bound to another page gets instantiated and thus the service is called un-necessary.
any options to defer this behavior until the page is opened?
You can load the data for the page in the onLoad method instead of in the constructor so that the data isn't loaded till after the widget is attached to the DOM.
Moving the code under the clause like shown below fixed the issue
if(RootPanel.get("login") !=null){
//moved here
}
Before you start shooting me down i have checked for answers and i have googled till my fingers bled but i havent been able to find a simple, concise answer. So im asking again for all those that might have this problem.
Question: how to open a new window with a formpanel in side.
Context: i have an app that lists lots of items, i want someone to edit an entry, i want a new window to open so they can edit properties then hit save. A standard thing you find in a lot of applications.
Architecture:
I have one client module called UI, it has a dozen classes that draw widgets and fill a main area when selected from a menu. I have a single html page called UI.html which has the tag in the head. Thats it.
Options Ive Seen
Call Window.Open() but you need to define a html file. I dont have one. I can create an empty one but how do you inject a widget in to it ?
use jsni $wnd to create a new window and get a reference to it. But how do i inject a form panel into it ??
use a popuppanel. They look sucky - plus if opening a window through JS is quite simple i would expect it to be in gwt.
Maybe im miss understanding how to use GWT i dont know.
Any help would be appreciated
Thanks
The way i got this to work is as follows:
i wrote a jsni method to open a new window
public static native BodyElement getBodyElement() /*-{
var win = window.open("", "win", "width=940,height=400,status=1,resizeable=1,scrollbars=1"); // a window object
win.document.open("text/html", "replace");
i added a basic body to the new window and returned the body element
win.document.write("<HTML><HEAD>"+css1+css2+"</HEAD><BODY><div class=\"mainpanel\"><div style=\"width: 100%; height: 54px;\"><div id=\"mainbody\"class=\"mainbody\" style=\"width: 100%;\"></div></div></div></BODY></HTML>");
win.document.close();
win.focus();
return win.document.body;
}-*/;
i then called this method from my main java method
BodyElement bdElement = getBodyElement();
I then injected my panel which has lots of widgets into the returned body element
SystemConfiguration config = new SystemConfiguration(); bdElement.getOwnerDocument().getElementById("mainbody").appendChild(config.getElement());
I agree with Bogdan: Use a DialogBox.
If you can't, you Window.open() as you mentioned in option 1:
Create another GWT module, and form.html that will load it
Window.open("form.html?entry=54")
Have the form gwt module read from the URL, load the entry, allow it to be edited, and provide Save and Cancel buttons
Close the popup when Save or Cancel is clicked
Can't you just use a DialogBox?
Example
has anyone encountered a problem where you register a LoadHandler on the image, and when the image is loaded the LoadHandler doesn't get called sometimes? Is there some voodoo to make it work? Like some ridiculous order of initialization? This is driving me nuts.
The code works on Firefox, Chrome, IE6 and IE7. The image is attached to the DOM (I know LoadHandler won't get called if the image is not attached).
Edit
I have reduce the larger code to the following snippet.
private void loadNext() {
if (count < urlList.size())
Image displayImage = new Image();
displayImage.addLoadHandler(new ImageLoadHandler());
displayImage.addErrorHandler(new ImageLoadError());
mainPanel.add(displayImage);
displayImage.setUrl(urlList.get(count));
return;
}
}
private class ImageLoadHandler implements LoadHandler {
public void onLoad(LoadEvent event) {
count ++;
Log.TRACE("Success");
loadNext();
}
}
private class ImageLoadError implements ErrorHandler {
public void onError(ErrorEvent event) {
Log.ALERT("Error");
}
}
So basically this loads images one by one once the previous one has finished loading. The problem that occurs is the first image shows up as red x in IE8 and an error is caught. Now, if I right click on the image and click "show picture" it shows up, and triggers something such that the onLoad event is fired and the rest of the images load without errors! Now all of a sudden onLoad event works, all the other images which are same type are no longer an error.
the urlList is a list of urls to the images. The URL does not contain an extension for image type. The URLs go to a servlet which generate an image. I have taken care to set the proper Content-type headers (image/jpeg) in the response.
Furthermore, if I right click on the broken image, IE8 shows that it doesn't know its type. If I copy the URL, paste it in the address bar, IE loads the image just fine on its own. Now it seems to know the type when it's not in tags.
Very frustrating.
Thanks.
I encountered the same problem, after several days of inspection we found that it is internal bug of IE8 with its image cache. Try to delete complete browser history if it works for the first time. If it is your case then working solution is to add dummyParam to every image URL (with value e.g. new Date().timeInMilis() or something similar). I made this param enabled for user.agent=ie8 only.
I am really afraid of IE9 :(.
It turned out that this is a known GWT Bug.
Updating to GWT 2.1 should solve the problem.