FileUpload.reset() has different behavior for IE, Chrome - gwt

I tried to create a fileUploader with GWT.
Here is the problem, while I was adding ChangeHandler to fileUploader, I found that the behavior of IE and Chrome are different. If I choose the same file I uploaded, IE will trigger the onChange(), while Chrome won't. That's too weird. Can anybody tells me if it is a bug of GWT of not??
FileUpload fileUploader = new FileUpload();
fileUploader.addChangeHandler(new ChangeHandler(){
#Override
public void onChange(ChangeEvent event)
{
submitButton.setEnabled(true);
}
});

There are browser discrepancies that GWT cannot hide. The only mean to really reset a FileUpload in a cross-browser way, is to create a new one to replace the previous instance.

Related

GWT: Opening new mail window without browser tab opened

I am trying to open an email client just like using mail me tag.
But I want to use my custom widget, which is not hyperlink, anchor or so. I added a DOM handler to my widget to listen to clicks:
public class VContactWidget extends VHorizontalLayout implements ClickHandler {
private HandlerRegistration clickHandler;
public VContactWidget() {
// added some content here
clickHandler = addDomHandler(this, ClickEvent.getType());
}
#Override
public void onClick(ClickEvent event) {
Window.open("mailto:john.doe#mail.com", "_blank", "");
}
}
Everything is working fine except one detail: When the widget is clicked, new empty browser tab will open with url set to mailto:john.doe#mail.com. I don't want the new tab opened. Can I avoid it somehow?
Note I set _blank parameter, as used in many examples. I also tried to use empty string or some other values as well. I looked into documentation, but didn't find anything useful.
https://developer.mozilla.org/en-US/docs/Web/API/window.open
One solution may be to use Anchor, but my component is more complex, not just single <a> link.
Another detail to note may be application server - I am using Tomcat 7 now.
Trying to fire native event on hidden Anchor programatically did not work for me. (Which does not mean it cannot be done.)
This is, how I actually solved my problem: Instead of Window.open(), I used following call:
public void onClick(ClickEvent event) {
Window.Location.assign("mailto:john.doe#mail.com");
}
This is not something that you can control. Whether this link opens in a new tab or a new window depends on the browser settings and user preferences.
I don't think it will make a difference if you use an Anchor or Window.open. In either case, the behavior may be different in different browsers. Also remember that for some users a click on this link will open Outlook or Mail, while for other users it will open Gmail in a browser window.
UPDATE:
If you want an exact behavior of an <a> element, create a hidden anchor element and fire a click on it when a user clicks on your composite widget.
Firing click event from code in gwt

mouseenter event does not working for gwt celltable

I have one celltable and I need to add handler on its row for "mouseenter" event.
I have tried something like following, but its not working for "mouseenter" althought it works for "mouseover".
cellTable.addCellPreviewHandler(new CellPreviewEvent.Handler<Test>(){
#Override
public void onCellPreview(CellPreviewEvent<Test> event) {
if ("mouseenter".equals(event.getNativeEvent().getType())){
Window.alert("mouse entered");
}
}
});
Is not working properly for mouseenter events because apparently is only implemented by IE and Opera, since you're Chrome, you can just wait until they implement it.
Unfortunately Firefox, Chrome, and Safari still haven’t copied this brilliant Microsoft invention, that has even made it to the spec. Come on, guys!
From this source.

Change opacity of a TreeItem

I have a server and client using gwt.
In my client page i have a tree item displayed.
I want to do one of the following:
- disable the tree item when a function is called.
- made opaque the entire client page or only the tree item when a function is called.
By made opaque, i want to do the same as occur when i debug my project with eclipse and i stop and i get the following in the client page
GWT Code Server Disconnected
Most likely, you closed GWT Development Mode. Or, you might have lost network connectivity. To fix this, try restarting GWT Development Mode and REFRESH this page.
Please give me some indication on how to do it and if it is possible.
you create a handler for you function call(s) and add the style when the funciton is called. Because GWT works with javascript it changes your appearance during runtime.
item.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
event.getItem().setStyleName("newStyle");
}
});
and in the css you define you style:
newStyle: {
...
your style definition
}

GMaps controls broken in GWT 1.6+?

I've ported my GWT app to 1.7.0 from 1.5.2 and widgets that are used as a control on a GoogleMap no longer get ClickEvents. I've checked that the DOM insertion of the control is the same and there are no differences there. Since GWT 1.6 introduced a significant change in the way events are handled I'm thinking something has gone amis there.
I use a GWT image as a a GoogleMaps control:
Image control = new Image("/oeg/images/info_32.png");
Which I place on the map using the Mapitz GMaps lib (yes I know its old, but I have kept supporting a working version that is updated - if anyone is interested just ask)
GControlPosition infoPosition =
new GControlPosition(GControlAnchor.G_ANCHOR_TOP_RIGHT(),
new GSize(7, 30));
getGmap().addControl(new GControl(control, infoPosition));
I've checked the compiled code and it literally just puts the html element on the map as a GControl just the way you'd expect and as I said I've checked the DOM to make sure nothing looks funny.
to get ClickEvents I used to do this...
control.addClickListener(new ClickListener() {
public void onClick(Widget sender)
{
doTipOfTheDay();
}
});
which I changed to this in the 1.6.0 world,
control.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent ce)
{
doTipOfTheDay();
}
});
I've also tried explicitly sinking the click event with
control.sinkEvents(Event.ONCLICK);
but none of this works in GWT-1.6.0/1.7.0 and it all worked fabulously in 1.5.2
Can anyone shed some light on this? Has anyone else run into event issues w/ controls on GMaps with GWT 1.6 and above?
FYI with other Gmaps objects I have no problems. I'm getting mouse clicks on the map surface, on markers etc.
but controls, not so much

gwt fileupload

I would like to trigger a click on the browse button on a hidden FileUpload widget.
The following code works fine on IE 6+, but doesn't work in FireFox.
final FileUpload upload = new FileUpload();
upload.setVisible(false);
upload.setName("uploadFormElement");
panel.add(upload);
panel.add( new Button("Select File", new ClickListener()
{ public void onClick(Widget pSender)
{ jsClickUpload( upload.getElement() ); } }));
native void jsClickUpload( Element pElement ) /*-{ pElement.click(); }-*/;
How can I achieve the same in FireFox (and possibly other browsers)?
The solution can be read here:
http://www.quirksmode.org/dom/inputfile.html
in the last paragraph:
The click() method allows you to
simulate a click on a form field.
Checkboxes get toggled, radios
selected, and so on. Unfortunately
Mozilla and Opera haven't added this
method to file upload fields. I wonder
why, adding it is not really a
security risk since the worst that can
happen is that the file selection
window pops up.
have you tried calling the onClick() method directly?
The click method is currently in the process of being implemented in FF 4. It is being discussed what security rules will be implemented and it sounds like it will be similar to Window.open and must be the direct result of a user action and not a timer or load.