how to dianmically add dialog to webpage in wicket? - 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.

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

How to open a href link in a FormToolkit of eclipse

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.

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 need to know how to connect to.. or go from one page to another

im new to GWT ive been working on it since recently..
i want to know how can i go from "entry point page" ie,ImageViewer.java..
ive been suggested to create the memory by calling constructor on a perticular button
Button button = new Button("New button");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event)
{
new LookupMaster(); //this is a composite
}
});
but this is not working.. i guess v can only call or get alert messages using this type..
can some one help me.
I'm not sure how to answer, since I have the feeling you're not understanding the basic concepts totally, but that's just my interpretation.
GWT is one html page that via JavaScript methods changes the content of that one page. When you want to display 'another' page you need to do this via methods that update the html dynamically. Since you are just starting with GWT, you might want to read this page on Build User Interfaces to understand the concepts and look at some examples provided with GWT.

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.