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.
Related
First off, before the flames start, I do know that trying to hinder the back button in the browser is a dumb idea. I would not try to do this, but my business partners are very insistent on it. We are porting an existing .exe to the web and their definition of this is 'run it in a browser' and not "make it a web site". So, fact that it's a bad idea (I agree), here's the question:
Is there a way to ignore or trick the GWT PlaceController / History manager mechanisms so that when the back button is pressed, it just stays on the same page?
I have used Window.addWindowClosingHandler to add a handler which will prompt the user if they want to leave the page and overriden the newItem() method of the defaultHistorian so that no history is tracked at all, but this isn't quite what the business people want.
What they'd like is to just ignore the back button so that nothing happens when it is clicked.
If anyone knows how to do this with GWT, I'd be very grateful.
And I"ve done a lot of google searching and haven't found anything exactly like this question. At least, not close enough to help.
I was able to get GWT to not accumulate any history so that when the user presses the BACK button, they cause an onWindowClosing event to happen and the Browser will prompt them if they want to stay or leave. This will accomplish the goal of not allowing the BACK button to take them back, but it's a bit Draconian. This code does that:
class TvHistorian extends PlaceHistoryHandler.DefaultHistorian
{
#Override
public void newItem(String token, boolean issueEvent) {
// don't do anything - this will prevent history from accumulating
}
}
final PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper, new TvHistorian());
I've tried a bunch of stuff including extending the PlaceController.goTo() to save the "lastNormalFlowPlace". Then, I tried to override the History.onValueChange to use this saved Place if it was different than what the event specified. But I think I missed some subtlety because that didn't work as expected.
With the above exception, my code looks almost exactly like what is documented here: http://www.gwtproject.org/doc/latest/DevGuideMvpActivitiesAndPlaces.html#Putting_it_all_together
I have already posted an answer in the same context.
Please have a look at below links:
promt user on backspace and browser backbutton in gwt
how can i get a prompt on url change
Disable back button in GWT
Try with any option:
History.addValueChangeHandler
WindowClosingHandler
Event.addNativePreviewHandler
$wnd.onbeforeunload
--EDIT--
Sample code: (It's working perfectly fine in Firefox, Chrome as well as IE9)
Note: add below code in the beginning of the onModuleLoad() method.
final String initToken = "Place";
History.addValueChangeHandler(new ValueChangeHandler<String>() {
#Override
public void onValueChange(ValueChangeEvent<String> event) {
String token = event.getValue();
if (!initToken.equalsIgnoreCase(token)) {
History.newItem(initToken);
}
}
});
// fire the initial history state.
History.fireCurrentHistoryState();
Note: add checks for other allowed history tokens.
I am creating a chat view and loading images in a chat room using NetworkImageView (placed inside a Normal ListView) via Android Volley Framework, which works great but the problem is that when the chat gets loaded the images are downloaded after a while due to which scrolling to the bottom does not work as expected. What I want is the listview in which the images are kept should scroll to the end upon getting initialized.
Here is the code that does the scrolling to the bottom of the list:
listview.clearFocus();
listview.post(new Runnable() {
#Override
public void run() {
listview.setSelection(listview.getCount() - 1);
}
});
However, this does not scroll to the end of list. The issue is that volley does not load up the image by the time it is initialized and only initializes it when it is starting to get displayed (onAttachToWindow or onLayout calls). Refer to the code
A workaround to make sure the list gets scrolled is:
networkImageView.setImageResource(R.drawable.placeholderImage);
Although not a good solution, this gets the job done.
Anyone has better ideas?
Using setStackFromBottom(true) solves the issue. I don't know why it never came to my mind. Anyways, putting the question for people like me, having issues with volley.
I want to display an "img" element as a child of a panel. Should we be using the Image widget for this? I'm doing the following:
Image img = new Image();
img.getElement().getStyle().setWidth(80, Style.Unit.PX);
img.getElement().getStyle().setHeight(80, Style.Unit.PX);
// add it to a panel, which eventually gets added to the root panel.
somePanel.add(img);
// set the url
img.setUrl("stuff/test.png");
This works fine on FF. When I run the same code in mobile safari, the images never load. I've added a LoadHandler to the Image instance. I can see that on FF, the event callbacks are triggered. But on mobile safari, they're never triggered.
I recall that an Image must be added to the RootPanel in order for it to ever load, but I am indeed doing that. What else could be causing this? I'm sure the png resource is located correctly.
Thanks
Rule of thumb: always use absolute URLs, possibly using GWT.getModuleBaseURL(), GWT.getHostPageBaseURL() or GWT.getModuleBaseForStaticFiles() as a prefix:
img.setUrl(GWT.getHostPageBaseURL() + "stuff/test.png");
This is because GWT code runs in an iframe and is loaded from within a subfolder, and browsers differ in behavior on whether to use the host page or the iframe URL to resolve relative URLs.
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.
I just want to read a HTML file and display its content in a GWT widget. Already I have done it but i'm not getting its css and javascripts. So can anyone help me to get the content with its css and javascripts?
I tried the following code,
public class FrameExample implements EntryPoint {
public void onModuleLoad() {
Frame frame = new Frame("http://www.google.com/");
RootPanel.get().add(frame);
}
}
I got a rectangular box only. But I don't get the expected result. Can you help me?
Forget everything I said, you can get the answerer here!
(Iframe not displaying some pages)
Basically: google has a mechanism to detect if it is not hosted in a iframe. This of course raises the question why they us it in their examples.....
BTW: a site like http://en.wikipedia.com works.