2

I have a WebPage in Wicket with PageParameters so that it could be used via BookMarkablePageLink.

I can open it also giving:

 setResponsePage(MyPage.class, params);

, but what I cannot do is open it similar way as a new tab.

I use a form and there in onSubmit() -method I want to call the page and place it to tab. I cannot figure out how I could

a) validate form
b) open the page on successful validation
c) page appearing in a new tab.

How to make the part c? I know how to validate and open page, please help me about the opening to a tab.

For the form I give target="_blank", but did not help, maybe due the fact of using the setResponsePage() method.

EDIT:

This is not a duplicate of Open new Tab when button is clicked because none of solutions worked.

Page is opened in AjaxSubmitLink's onSubmit() method with setReponsePage(). I have to validate form before sending, thus direct Bookmarkable link or form is not a case. Adding to tag target="_blank" works if you directly open after click. I have to validate first and then I try to set the response page like stated above.

Community
  • 1
  • 1
mico
  • 12,730
  • 12
  • 59
  • 99
  • Possible duplicate of [wicket ,how to open new tab when button is clickd](http://stackoverflow.com/questions/18121236/wicket-how-to-open-new-tab-when-button-is-clickd) – thg Feb 02 '16 at 11:42
  • @thg: Actually, not. Look my answer. – mico Feb 02 '16 at 12:39

2 Answers2

4

I found solution from a list in other Q&A. [1]

It states:

dont use an ajax button, they do not respect the target attribute.

I will try to submit the form with ajaxlink. My validations work with ajax, but I can use

RequestCycle.get().find(AjaxRequestTarget.class)

to get the needed AjaxTarget. [2]

Sources:

[1] http://apache-wicket.1842946.n4.nabble.com/Open-new-Tab-via-form-target-td3624578.html

[2] How to get the AjaxRequestTarget inside Wicket's onBeforeRender() method of a component?

Community
  • 1
  • 1
mico
  • 12,730
  • 12
  • 59
  • 99
  • My fellow worker fixed the issue for me before I found the answer. He stayed with ajaxForm, but opened link with a `target.appendJavaScript("window.open('"+ url +"');return false;");` call. Same solution almost, just not to relying on `ajaxLink`'s functionality. – mico Feb 03 '16 at 07:44
3

This 'onclick' html attribute works for me (at least in IE, Firefox and Chrome):

<input onclick="target='_blank';return true;" type="submit" value="text on button"/>

Okay, i don't know how this exactly works but i find it much smarter than doing some complex stuff in your java code.

chris
  • 1,685
  • 3
  • 18
  • 28