Im writing some java code and im hitting a wall, with FileUpload, i am trying to get a alternate button to activate the filebrowser from the FileUpload.
I tried to dispatch the event from one to another, tried to extend FileUpload to have a button that triggers some action but no luck.
Fileupload upload = new FileUpload();
Button b = new Button("Browse",new ClickHandler() {
// trigger upload Browser
});
Something like this.
You cannot do this due to security restrictions. The restriction is that untrusted code cannot trigger the File Browse dialog to open because it could then do so without user input, possibly tricking the user into thinking the dialog is from a different webapp or entirely different application.
Actually it is possible on IE6 and maybe IE7, all other prohibit this action.
Read my question and answer: gwt fileupload
You might give a shot to SWFUpload in combination with swfupload-gwt.
Related
I want to disable moving events from Vaadin Calendar
All of these handlers are automatically set when creating a new Calendar. If you wish to disable some of the default functionality, you can simply set the corresponding handler to null. This will prevent the functionality from ever appearing on the user interface. For example, if you set the EventMoveHandler to null, the user will be unable to move events in the browser. --> Book of Vaadin
I tried:
calendar.setHandler(null);
calendar.setHandler((EventMoveHandler) null);
calendar.setHandler((BaseEventMoveHandler) null);
EventMoveHandler handler = null;
calendar.setHandler(handler);
BaseEventMoveHandler baseHandler = null;
calendar.setHandler(baseHandler );
But nothing is working. Any suggestion....?
It really works for me with Vaadin 7.4.5:
calendar.setHandler((EventMoveHandler)null);
calendar.setHandler((EventResizeHandler)null);
If you want to disable all handlers and make the calendar completely read-only, this worked for me.
calendar.setReadOnly(true);
EDIT1:
This approach however doesn't disable resize pointers for the events. Thus, the best solution I see is to use it together with asmellado's answer :
calendar.setReadOnly(true);
calendar.setHandler((EventMoveHandler)null);
calendar.setHandler((EventResizeHandler)null);
Also, if I did not use the setReadOnly method, I was running in some strage client-side exceptions when I tried to move the event.
I have a Java applet that presents a JButton that allows users to navigate to another URL (which has a feedback form).
Problem: when I navigate to the form in Safari from the applet, typing into the form is garbled or impossible (only every 10th keystroke or so is actually entered).
Manually terminating the Java Web Plug-in for Safari fixes this immediately. I assume that I am somehow not releasing resources properly in my applet. I am aware that cleanup should be performed in the stop() method, but I'm not sure what resources I am failing to release that could cause this kind of behavior.
Here is the code that browses to the URL:
final JButton btnLaunch = new JButton("Go to survey");
final myJApplet mj = this;
btnLaunch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String url ="www.mywebform.example";
try {
getAppletContext().showDocument(new URL(url));
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
finally {
SwingUtilities.getWindowAncestor(btnLaunch).dispose();
mj.stop();
}
}
My best guess is that somehow Safari is mishandling resources by passing them to some Java ActionListener. However, including:
btnLaunch.removeActionListener(this);
in a finally block does not seem to help. I have other action listeners in my applet that I know are not explicitly destroyed, but I was under the assumption that generally this wasn't a problem as they are supposed to be disposed of automatically.
EDIT: Checking through my code, it seems I only have MouseListener or ActionListeners (on JButtons). So it is even more baffling that I'm having a keyboard issue. I tried manually removing them all in the stop method of the applet (which I manually call in the finally block), but it didn't help. MouseEvents and ActionEvents shouldn't continue to run upon navigating away from the page!
EDIT 2: Further information: having the applet open a new window which then contains a link to the final survey also does not work. However, making the link open in a new window (using html's target="_blank") seems to correct the problem. So for a work around, I have the applet direct users to a splash page which thanks them and then presents a link for the final survey. This is annoyingly kludgey, and doesn't answer the original question, but for now it seems like what I will be going with.
I maintain a GWT web application. Our users often upload screen shot image files via a standard file upload dialog. I'm trying to think of some slightly more user friendly approach. I was wondering if there might be any way to allow the users to "paste" the image data after clicking the print-screen button.
I read some other posts that said that GWT can't nativly copy anything to or read from the clipboard buffer, but what about if the user manually pastes the image via ctrl-V or right clicking and pasting.
If anybody knows how I can accomplish this in GWT or has any other ideas let me know.
There is an event for pasting:
com.google.gwt.user.client.Event.ONPASTE
I use this but only for pasting text (user must user Ctrl+V or right-click>Paste).
I guess there may be a way for you to use this.
To capture the event, I sink it to my Widget first:
sinkEvents(Event.ONPASTE | Event.ONKEYPRESS | Event.ONKEYDOWN | Event.ONFOCUS);
Then, I implement onBrowserEvent(Event):
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
switch (event.getTypeInt()) {
case Event.ONPASTE: paste(event);
}
}
Hope you can find a way to adapt this for images.
I am using GXT for UI development. I have used HTML5 for Dragging file from Desktop to my application and upload it. But now i am having reverse requirement. I want to drag files from browser to desktop which will download the file to desktop.
I know that is possible in Chrome only. And had checked the below demo:
http://www.thecssninja.com/javascript/gmail-dragout
I had tried to implement the above code in my GXT application, but the issue is that i am using Editable Grid which is supporting DnD to TreePanel. Now when i drag from grid to Desktop i think its not capturing the browser event (may be i am wrong here).
Any idea, how it should be done?
Thanks.
Below is the small piece of code which i call after the Data had been inserted in Grid. All records are having the CSS class name as ".icon". The problem is that when i start to drag, the "dragstart" is not being called. Any suggestion?
NOTE: This code is working when i create Buttons, Labels, etc and making them draggable=true with other required parameters.
public static native void test(String id)/*-{
var files = $doc.querySelectorAll('.icon');
for (var i = 0, file; file = files[i]; ++i) {
file.addEventListener("dragstart",function(evt){
$wnd.alert("Drag Event started.. ");
evt.dataTransfer.setData("DownloadURL",this.dataset.downloadurl);
},false);
}
}-*/;
I used this, and it successully performs, no you should check some other place in your code.
GWT FileUpload comes as a widget that produces so that one can upload a file during form submit (at least it's how I understand it :) ) What I want to do is to make it a better-looking and get rid of standard "Browse..." button.
Since I don't have good GWT experience (and no JavaScript), I looked for existing solutions and found quite a good project - gwtupload. It's good, but I realized I'd love to have my own miniature version (and also, I was curious about how it works). So I browsed through code and tried to extract the magic part. I realized that GWT FileInput is used, but it's not shown, and Button clicks are delegated to this FileInput. The code I tried to extract (only the part that delegates the click) after reviewing sources of gwtupload contains this tricky elem.click() JSNI:
class MyUpload extends Composite {
private static native void clickOnInputFile(Element elem) /*-{
elem.click();
}-*/;
public MyUpload() {
final FileUpload upload = new FileUpload();
AbsolutePanel container = new AbsolutePanel();
// container.add(upload);
Button btn = new Button("My Browse..");
btn.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
clickOnInputFile(upload.getElement());
}
});
container.add(btn);
initWidget(container);
}
}
But this seems not to work: clicking on 'My Browse..' results in no effect (just in case I also tried running with un-commented container.add(upload) line) . Could you please help me in understanding what's wrong/missing in this code sample?
Thank you in advance.
P.S. I know that I have to place it on the FormPanel, and I know the rest about how to perform the actual submit/handling in Servlet; the only thing I want to do is this kind of decoration.
Since I have not received any answers, I had to have more investigation of this issue, so I performed a deeper code analysis of gwtupload project in order to understand how GWT FileUpload (which gets transformed into ) can be decorated.
It turned out that element.click() will only work in browsers which support #click() method (IE, Chrome, Safari). Actually, Manuel Carrasco MoƱino - project author - mentions it within comments. There's second approach (for Firefox & Opera) that uses hack when FileInput is placed on transparent panel, which however is placed over some decorated button (using absolute positioning); comment by Manuel:
When the user puts his mouse over the button and clicks on it, what really happens is that the user clicks on the transparent file input showing the choose file dialog.
After that, the main work is correctly applying style attributes to elements.
Thus, there are two implementations of custom file upload component, and GWT deferred binding is used to instantiate them depending on Browser.
As for example I mention in my question, there're few fixes ("upload" has to be added to to the container, and it can be set to #setVisible(false)):
class MyUpload extends Composite {
private static native void clickOnInputFile(Element elem) /*-{
elem.click();
}-*/;
public MyUpload() {
final FileUploadWithMouseEvents upload = new FileUploadWithMouseEvents();
AbsolutePanel container = new AbsolutePanel();
container.add(upload);
upload.setVisible(false);
Button btn = new Button("My Browse..");
btn.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
clickOnInputFile(upload.getElement());
}
});
container.add(btn);
initWidget(container);
}
}
This example works fine in IE8.
P.S. Thanks to Manuel for his great library :)