made a hyperlink but it is not opening any webpage.
toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createScrolledForm(parent);
form.setText("Hello, Abhishek Eclipse Form");
GridLayout layout = new GridLayout();
form.getBody().setLayout(layout);
final Hyperlink link = toolkit.createHyperlink(form.getBody(),
"Click here.", SWT.WRAP);
link.setHref("http://www.google.com");
As per the above piece of code,how should I open the webPage in the FormToolkit view
The Hyperlink widget isn't like a browser link. It doesn't by itself know how to handle links. You work with it like a button, in that you listen for the click event and then do what you need to.
You can find examples on how to work with forms here:
http://www.eclipse.org/articles/Article-Forms/article.html
Here is how you listen for link activation:
link.addHyperlinkListener(new HyperlinkAdapter() {
public void linkActivated(HyperlinkEvent e) {
System.out.println("Link activated!");
}
To actually replace the contents of the view with a web page is quite a bit more complicated. You would have to dispose of all widgets currently in the view (such as the hyperlink), then you would create a Browser widget and point it at the appropriate URL.
Related
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.
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
Is there anyway i can get the hyperlink click in webview to my c# with Hyperlink value in Metro?. I am using WebView..NavigateToString() to generate the content?.
You can call InvokeScript with some of your own Javascript to set up a listener for when the user navigates away from your page. This would look something like the following in C#:
var navigationListenerString = #"
(function() {
function leavingPage() {
window.external.notify("LEAVING PAGE");
}
window.onbeforeunload = leavingPage;
})()";
webView.InvokeScript("eval", new string[] { navigationListenerString });
Then you can use ScriptNotify to listen for your particular message to determine that the page is unloading and the user is leaving. Unfortunately you cannot detect where a user is going. Also, if the hyperlink opens in a new window and the webview does not unload, you cannot detect that either.
Since WebView in windows 8 doesn't support Navigating() events like the Silverlight WebBrowser control, thus it is not possible to get hyperlink or cancel navigation.
But since you're using NavigateToString() method, you can write some manual javascript code and achieve same with the help of WebView.ScriptNotify() event.
I have a modal dialog in Wicket that contains a link. I need to open an external web page (for example, http://www.google.com) by clicking on the link. The target of the link is set dynamically. How can I do this?
I think that my question hasn't been so clear(I apologize for that). I need to open Web page from modal dialog. Actually, I can explain the problem in the example of modal dialog that #Don Roby has proposed me (wicketstuff.org/wicket14/ajax/modal-window.0). If we click the "Show modal dialog with a page" link in the example, there will be shown the modal dialog with another link called "Open another modal dialog". By clicking on that link, I want to open Web page (for example: www.google.com). My question is: how to open a Web page in this situation?
You can use a PageCreator (instead of setContent()), and return a RedirectPage:
ModalWindow modal = new ModalWindow("modal");
modal.setPageCreator(new ModalWindow.PageCreator() {
#Override
public Page createPage() {
return new RedirectPage("http://www.google.com");
}
});
add(modal);
I understand what you mean.
I have found the solution here :
http://apache-wicket.1842946.n4.nabble.com/How-to-redirect-from-a-ModalWindow-td1889646.html
onClick( AjaxRequestTarget target ){
target.appendJavascript( "Wicket.Window.unloadConfirmation = false;" );
modal.show( target);
}
It sounds like you already know how to deal with the modal, but there's an example of doing it here. Opening an external link is not difficult, and there's an example of doing it here.
how do you create your link ?
did you tried with an externalLink ?
new ExternalLink("applicationLink","http://www.google.com");
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