You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Gregor Kaczor <gk...@gmx.de> on 2011/06/25 15:36:44 UTC
Open new Tab via form target
Hi!
I have a problem with opening a new tab via a form.
I am using Wicket 1.4.17 on Ubuntu 11.04 with java 1.6.0_24-b07 and
Tomcat 7.0.12
On a page I have a Download Button in a form with a Link to a file or an
image.
After clicking on that button a new Tab should be opened with that link.
Unfortunatelly the file opens in the working tab. Adding target="_blank"
to the form or the submit button does not change that behaviour.
Just for fun i removed the wicket-ajax.js from the html file and opening
a new tab via a form WORKED!
Here is my code. What do I have to do to open a new tab when the
AjaxFallbackButton is clicked?
<code>
Form<Void> form = new Form<Void>("downloadForm"){
@Override
protected void onComponentTag(ComponentTag tag) {
// TODO Auto-generated method stub
super.onComponentTag(tag);
tag.put("target","_blank");
}
};
final Model<String> buttonLabelModel = new
Model<String>("DOWNLOAD");
final Label label = new Label("downloadButtonLabel",
buttonLabelModel);
label.setOutputMarkupId(true);
label.setOutputMarkupPlaceholderTag(true);
final AjaxFallbackButton a = new
AjaxFallbackButton("downloadButton",
form) {
private static final long serialVersionUID =
5109029782741176146L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?>
form) {
String url =
solrDocument.getFieldValue("idadr").toString();
System.out.println(queryResultLine.toString() + "\tDL:
" + url
+ "\tPosition: " + positionCounter);
getRequestCycle().setRequestTarget(
new RedirectRequestTarget(url));
}
};
a.add(label);
form.add(a);
</code>
<code>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
...
<form
style="display: inline;"
wicket:id="downloadForm"
target="_blank"
>
<button target="_blank" wicket:id="downloadButton"><span
wicket:id="downloadButtonLabel"
/></button>
</form>
...
</code>
I am aware of the fact, that i am adding target=_blank twice over the
onComponent methid and in the html. I tested combinations without results.
Kind Regards
Greg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Open new Tab via form target
Posted by Igor Vaynberg <ig...@gmail.com>.
dont use an ajax button, they do not respect the target attribute.
-igor
On Sat, Jun 25, 2011 at 6:36 AM, Gregor Kaczor <gk...@gmx.de> wrote:
> Hi!
>
> I have a problem with opening a new tab via a form.
>
> I am using Wicket 1.4.17 on Ubuntu 11.04 with java 1.6.0_24-b07 and Tomcat
> 7.0.12
>
> On a page I have a Download Button in a form with a Link to a file or an
> image.
> After clicking on that button a new Tab should be opened with that link.
>
> Unfortunatelly the file opens in the working tab. Adding target="_blank" to
> the form or the submit button does not change that behaviour.
>
> Just for fun i removed the wicket-ajax.js from the html file and opening a
> new tab via a form WORKED!
>
> Here is my code. What do I have to do to open a new tab when the
> AjaxFallbackButton is clicked?
>
> <code>
> Form<Void> form = new Form<Void>("downloadForm"){
> @Override
> protected void onComponentTag(ComponentTag tag) {
> // TODO Auto-generated method stub
> super.onComponentTag(tag);
> tag.put("target","_blank");
> }
> };
> final Model<String> buttonLabelModel = new Model<String>("DOWNLOAD");
>
> final Label label = new Label("downloadButtonLabel",
> buttonLabelModel);
> label.setOutputMarkupId(true);
> label.setOutputMarkupPlaceholderTag(true);
>
> final AjaxFallbackButton a = new AjaxFallbackButton("downloadButton",
> form) {
>
> private static final long serialVersionUID =
> 5109029782741176146L;
>
> @Override
> protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
>
> String url = solrDocument.getFieldValue("idadr").toString();
> System.out.println(queryResultLine.toString() + "\tDL: " +
> url
> + "\tPosition: " + positionCounter);
>
> getRequestCycle().setRequestTarget(
> new RedirectRequestTarget(url));
>
> }
> };
>
> a.add(label);
> form.add(a);
> </code>
>
> <code>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> ...
> <form
> style="display: inline;"
> wicket:id="downloadForm"
> target="_blank"
>>
> <button target="_blank" wicket:id="downloadButton"><span
> wicket:id="downloadButtonLabel"
> /></button>
> </form>
> ...
> </code>
>
> I am aware of the fact, that i am adding target=_blank twice over the
> onComponent methid and in the html. I tested combinations without results.
>
> Kind Regards
>
> Greg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org