load HTML when click a button GWT - gwt

how to load the other HTML page when i click a button? i'm using GWT 2.0.3.
p.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
// is there a syntax to load other HTML?
}
});
thanks before, Rafael.

If you use GWT's history mechanism, then you want to look at History.newItem("newPage");
If you want to jump to a totally new URL (and navigate outside your application) then you can use Window.Location.replace("newURL");.
Finally, if you just want to change the page within your application but are not using history, then you probably want to do something like:
RootPanel.get().clear()
RootPanel.get().add( widgetForNewPage );

Related

how to dianmically add dialog to webpage in wicket?

I have write my own dialog and on my Index page have a AjaxLink
when AjaxLink is clicked. I will behave to open my dialog instance.
this is my code
add(new AjaxLink("open.working.date.dialog") {
#Override
public void onClick(AjaxRequestTarget target) {
WorkingDateDialog dialog = new WorkingDateDialog("working.date.dialog", getString("index.working.date.dialog.title"), true);
Index.this.add(dialog);
dialog.open(target);
}
});
of course, on my web page html markup I don't have reference component id working.date.dialog and it will throw exception.
but when I replace Index.this.add(dialog); by this.add(dialog); or by target.add(dialog); the dialog won't work.
There any other way to add dynamically dialog to page?
In jquery I can do that easily by just append dialog html to body then open it by jquery.
thanks for your all helpful!
One option is to add the dialog in the constructor of the page and hide it initially. Then later when clicking the link just mark it as visible and add it to the AjaxRequestTarget.
Another option is to add a dummy/empty WebMarkupContainer with the same component id and later replace it with the dialog in #onClick().
You are going against the wicket way of doing things here, which will cause you much pain. :-) First of all WorkingDateDialog needs to extend ModalWindow. Assuming it does, here are my suggestions.
Right above your ajax link add this code:
final WorkingDateDialog dialog = new WorkingDateDialog("working.date.dialog", getString("index.working.date.dialog.title"), true);
add(dialog);
Then your ajax link becomes:
add(new AjaxLink("open.working.date.dialog") {
#Override
public void onClick(AjaxRequestTarget target) {
dialog.show(target);
}
});
So you always add your ModalWindow instance to your page hierarchy. It' just not visible until someone clicks the link.
I hope this helps you. Please let me know if you have any questions.

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

How to make a button link to another html page?

How to make a button link to another html page?
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
//this code has to redirect to another page within the project
}
The question is tagged as GWT so based on that... to do it entirely on the client, you can use the com.google.gwt.user.client.Window class.
Window.open(linkURL, "_self", "");
Here's a link to the docs.
Look under gwt javadocs for the Window class.
There are some static members in the Window class.
The open function is the same as that in javascript:
Window.open(url, targetFrame, features )
In GWT, "_self" is the name of the current active display frame/window.
Location replace, just as in javascript:
Window.location.replace(url)
Display alert or confirm window:
Window.alert(msg)
Window.confirm(msg)
If you wanted a button but not in the script you can try this:
YOUR PAGE
Stack Overflow
No need to use JS. As of HTML5, buttons support the formaction attribute where you can specify the URL.
<form>
<button formaction="http://stackoverflow.com">Go to stackoverflow!</button>
</form>
Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-formaction

[GWT]Block the event of the browser in the case of link

I want to handle the event in the case of link by my own event listener.If we click on a link in browser, browser will open the address given in the link but i want to call my own event listener. I tried to do it in GWT by removing the attribute of the anchor tag which worked but it is not a clean solution.
So if you are having any idea how to block the browser from opening that link please reply.
In GWT 1.6 the correct code is:
ClickHandler foo = new ClickHandler() {
public void onClick(ClickEvent event) {
/// do your stuff
event.stopPropagation(); // stops the event from bubbling to parent
event.preventDefault(); // prevents the browsers default action,
// following a link, etc
}
}
This is roughly equivalent to:
Link
Isn't that what this widget does:
http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/user/client/ui/Hyperlink.html
eg: it looks like a normal hyperlink but lets you handle the onclick event?
You can just call event.cancel() (GWT 1.6) or
Event.getCurrentEvent().cancelBubble(true); // In 1.4 and earlier
DOM.eventCancelBubble(DOM.eventGetCurrentEvent(), true); // In 1.5
There is also a method to cancel an event from its instance within GWT 1.5, but I can't remember.

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.