Pergunta

using wicket I want to open a new tab when a button or link is clicked, how can I achieve it?

what I have managed to do is to open it in a pop up like this:

 PopupSettings popupSettings = new  PopupSettings("popuppagemap").setLeft(0).setHeight(500).setWidth(500).setHeight(0);

    // Popup example
final Link<Void> setPopupSettings = new BookmarkablePageLink<Void>("searchBtn", HomePage.class)
   .setPopupSettings(popupSettings);

but this opens it in a new window.

Foi útil?

Solução

no problem to open a link in a new tab: just add 'target="_blank"' to the link.

final Link<Void> link = new BookmarkablePageLink<Void>("link", HomePage.class){
    @Override
    protected void onComponentTag(ComponentTag tag) {
        super.onComponentTag(tag);
        tag.put("target", "_blank");
    }
};
add(link);

Outras dicas

If you want a button instead of a link that opens a new tab you can use:

html:

<a wicket:id="tabFormViewEmpBut"><button type="button">Click Me!</button></a>

And

Java wicket:

final Link<Void> link = new BookmarkablePageLink<Void>("tabFormViewEmpBut", HomePage.class) {
   @Override
   protected void onComponentTag(ComponentTag tag) {
     super.onComponentTag(tag);
     tag.put("target", "_blank");
   }
};
add(link);

This is not a function of Wicket but of your browser and HTML in general.

simply add a target tag to your link:

<a href="#" target="_blank" wicket:id="myCoolLink">My Cool Link</a>

What actually happens when the link is clicked will depend on the browser. Before browsers had tabs, this would have opened a new window, now most browsers will open a new tab by default, however, you can't depend on that happening because the feature is optional.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top