You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jeff Andersen <ja...@posportal.com> on 2009/12/11 21:31:42 UTC

How to post form to new window using AjaxSubmitLink

I need to know how I can post a form to a new window using an AjaxSubmitLink.  I have a small page where a user can make a few setting changes and then either save those settings (using an AjaxButton) or preview those settings (using an AjaxSubmitLink) in a new window.  The problem is, I can't figure out how to make the preview button open in a new window.  Since there are no popup settings for an AjaxSubmitLink, I'm not sure what to do.

I've tried searching for a solution and the best I could find indicated that I should use a form target="_blank".  But that doesn't seem to change anything.  The call to setResponsePage always results in the preview page opening in the same browser window.

Below is the code for my submit and preview buttons:

        AjaxButton submit = new AjaxButton("websiteSetting-submit-button") {

            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
                super.onError(target, form);
                feedbackPanel.add(new AttributeModifier("style", true, new Model("color:red;")));
                target.addComponent(feedbackPanel);
                target.addComponent(form);
            }

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                processSubmission(target, form, false);
            }

            //Prepending the call to set the target to nothing for normal form submission.
            @Override
            protected IAjaxCallDecorator getAjaxCallDecorator() {
                return new AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public CharSequence preDecorateScript(CharSequence script) {
                        String sJs = "document.getElementById('" + form.getMarkupId() + "').target = '';";

                        return sJs + script;
                    }
                };
            }
        };

        AjaxSubmitLink preview = new AjaxSubmitLink("websiteSetting-preview-button") {

            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
                super.onError(target, form);
                feedbackPanel.add(new AttributeModifier("style", true, new Model("color:red;")));
                target.addComponent(feedbackPanel);
                target.addComponent(form);
            }

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                setResponsePage(HomePage.class);
            }

            //Prepending the call to set the target to "_blank" for preview submission to new window.
            @Override
            protected IAjaxCallDecorator getAjaxCallDecorator() {
                return new AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public CharSequence preDecorateScript(CharSequence script) {
                        String sJs = "document.getElementById('" + form.getMarkupId() + "').target = '_blank';alert(document.getElementById('" + form.getMarkupId() + "').target);";

                        return sJs + script;
                    }
                };
            }
        };

Thanks,
Jeff

* This e-mail and any files transmitted with it may contain confidential and/or privileged information and intended solely for the use of the individual or entity to whom they are addressed. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message.

Re: How to post form to new window using AjaxSubmitLink

Posted by Jeff Andersen <ja...@posportal.com>.
Thanks Igor and Zak, that worked for what I needed.  I'd still prefer to be
able to post the form data to the new window, but I'm able to get around
form post using the query string for now.

I also encountered the issue with the name for the window in IE.  Looks like
spaces also cause the problem.  I found that 'null' works or just an alpha
string with no spaces.

Thanks again for the help.


Zak Johnson-2 wrote:
> 
> I had a similar need and did as Igor suggested. Here is an example:
> 
> add(new AjaxButton("ajax-button"){
>     public void onSubmit(AjaxRequestTarget target, Form form) {
>         ...create result page, get the url path to it...
>         target.appendJavascript("window.open('http://page_path_goes_here
> ','window_name');");
>     }
> });
> 
> Something funny i'm working through in testing (and this a javascript
> issue,
> not wicket) is that IE won't open the window unless the window name is
> strictly alpha-numeric. FF works fine though.
> 
> Zak
> 
> On Fri, Dec 11, 2009 at 2:50 PM, Igor Vaynberg
> <ig...@gmail.com>wrote:
> 
>> you can output some javascript using the ajaxrequesttarget that does
>> window.open
>>
>> -igor
>>
>> On Fri, Dec 11, 2009 at 12:31 PM, Jeff Andersen <ja...@posportal.com>
>> wrote:
>> > I need to know how I can post a form to a new window using an
>> AjaxSubmitLink.  I have a small page where a user can make a few setting
>> changes and then either save those settings (using an AjaxButton) or
>> preview
>> those settings (using an AjaxSubmitLink) in a new window.  The problem
>> is, I
>> can't figure out how to make the preview button open in a new window. 
>> Since
>> there are no popup settings for an AjaxSubmitLink, I'm not sure what to
>> do.
>> >
>> > I've tried searching for a solution and the best I could find indicated
>> that I should use a form target="_blank".  But that doesn't seem to
>> change
>> anything.  The call to setResponsePage always results in the preview page
>> opening in the same browser window.
>> >
>> > Below is the code for my submit and preview buttons:
>> >
>> >        AjaxButton submit = new
>> AjaxButton("websiteSetting-submit-button")
>> {
>> >
>> >            @Override
>> >            protected void onError(AjaxRequestTarget target, Form<?>
>> form)
>> {
>> >                super.onError(target, form);
>> >                feedbackPanel.add(new AttributeModifier("style", true,
>> new
>> Model("color:red;")));
>> >                target.addComponent(feedbackPanel);
>> >                target.addComponent(form);
>> >            }
>> >
>> >            @Override
>> >            protected void onSubmit(AjaxRequestTarget target, Form<?>
>> form) {
>> >                processSubmission(target, form, false);
>> >            }
>> >
>> >            //Prepending the call to set the target to nothing for
>> normal
>> form submission.
>> >            @Override
>> >            protected IAjaxCallDecorator getAjaxCallDecorator() {
>> >                return new
>> AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) {
>> >
>> >                    private static final long serialVersionUID = 1L;
>> >
>> >                    @Override
>> >                    public CharSequence preDecorateScript(CharSequence
>> script) {
>> >                        String sJs = "document.getElementById('" +
>> form.getMarkupId() + "').target = '';";
>> >
>> >                        return sJs + script;
>> >                    }
>> >                };
>> >            }
>> >        };
>> >
>> >        AjaxSubmitLink preview = new
>> AjaxSubmitLink("websiteSetting-preview-button") {
>> >
>> >            @Override
>> >            protected void onError(AjaxRequestTarget target, Form<?>
>> form)
>> {
>> >                super.onError(target, form);
>> >                feedbackPanel.add(new AttributeModifier("style", true,
>> new
>> Model("color:red;")));
>> >                target.addComponent(feedbackPanel);
>> >                target.addComponent(form);
>> >            }
>> >
>> >            @Override
>> >            protected void onSubmit(AjaxRequestTarget target, Form<?>
>> form) {
>> >                setResponsePage(HomePage.class);
>> >            }
>> >
>> >            //Prepending the call to set the target to "_blank" for
>> preview submission to new window.
>> >            @Override
>> >            protected IAjaxCallDecorator getAjaxCallDecorator() {
>> >                return new
>> AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) {
>> >
>> >                    private static final long serialVersionUID = 1L;
>> >
>> >                    @Override
>> >                    public CharSequence preDecorateScript(CharSequence
>> script) {
>> >                        String sJs = "document.getElementById('" +
>> form.getMarkupId() + "').target =
>> '_blank';alert(document.getElementById('"
>> + form.getMarkupId() + "').target);";
>> >
>> >                        return sJs + script;
>> >                    }
>> >                };
>> >            }
>> >        };
>> >
>> > Thanks,
>> > Jeff
>> >
>> > * This e-mail and any files transmitted with it may contain
>> confidential
>> and/or privileged information and intended solely for the use of the
>> individual or entity to whom they are addressed. If you are not the
>> addressee or authorized to receive this for the addressee, you must not
>> use,
>> copy, disclose, or take any action based on this message or any
>> information
>> herein. If you have received this message in error, please advise the
>> sender
>> immediately by reply e-mail and delete this message.
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-post-form-to-new-window-using-AjaxSubmitLink-tp26751055p26907457.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to post form to new window using AjaxSubmitLink

Posted by Zak Johnson <za...@gmail.com>.
I had a similar need and did as Igor suggested. Here is an example:

add(new AjaxButton("ajax-button"){
    public void onSubmit(AjaxRequestTarget target, Form form) {
        ...create result page, get the url path to it...
        target.appendJavascript("window.open('http://page_path_goes_here
','window_name');");
    }
});

Something funny i'm working through in testing (and this a javascript issue,
not wicket) is that IE won't open the window unless the window name is
strictly alpha-numeric. FF works fine though.

Zak

On Fri, Dec 11, 2009 at 2:50 PM, Igor Vaynberg <ig...@gmail.com>wrote:

> you can output some javascript using the ajaxrequesttarget that does
> window.open
>
> -igor
>
> On Fri, Dec 11, 2009 at 12:31 PM, Jeff Andersen <ja...@posportal.com>
> wrote:
> > I need to know how I can post a form to a new window using an
> AjaxSubmitLink.  I have a small page where a user can make a few setting
> changes and then either save those settings (using an AjaxButton) or preview
> those settings (using an AjaxSubmitLink) in a new window.  The problem is, I
> can't figure out how to make the preview button open in a new window.  Since
> there are no popup settings for an AjaxSubmitLink, I'm not sure what to do.
> >
> > I've tried searching for a solution and the best I could find indicated
> that I should use a form target="_blank".  But that doesn't seem to change
> anything.  The call to setResponsePage always results in the preview page
> opening in the same browser window.
> >
> > Below is the code for my submit and preview buttons:
> >
> >        AjaxButton submit = new AjaxButton("websiteSetting-submit-button")
> {
> >
> >            @Override
> >            protected void onError(AjaxRequestTarget target, Form<?> form)
> {
> >                super.onError(target, form);
> >                feedbackPanel.add(new AttributeModifier("style", true, new
> Model("color:red;")));
> >                target.addComponent(feedbackPanel);
> >                target.addComponent(form);
> >            }
> >
> >            @Override
> >            protected void onSubmit(AjaxRequestTarget target, Form<?>
> form) {
> >                processSubmission(target, form, false);
> >            }
> >
> >            //Prepending the call to set the target to nothing for normal
> form submission.
> >            @Override
> >            protected IAjaxCallDecorator getAjaxCallDecorator() {
> >                return new
> AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) {
> >
> >                    private static final long serialVersionUID = 1L;
> >
> >                    @Override
> >                    public CharSequence preDecorateScript(CharSequence
> script) {
> >                        String sJs = "document.getElementById('" +
> form.getMarkupId() + "').target = '';";
> >
> >                        return sJs + script;
> >                    }
> >                };
> >            }
> >        };
> >
> >        AjaxSubmitLink preview = new
> AjaxSubmitLink("websiteSetting-preview-button") {
> >
> >            @Override
> >            protected void onError(AjaxRequestTarget target, Form<?> form)
> {
> >                super.onError(target, form);
> >                feedbackPanel.add(new AttributeModifier("style", true, new
> Model("color:red;")));
> >                target.addComponent(feedbackPanel);
> >                target.addComponent(form);
> >            }
> >
> >            @Override
> >            protected void onSubmit(AjaxRequestTarget target, Form<?>
> form) {
> >                setResponsePage(HomePage.class);
> >            }
> >
> >            //Prepending the call to set the target to "_blank" for
> preview submission to new window.
> >            @Override
> >            protected IAjaxCallDecorator getAjaxCallDecorator() {
> >                return new
> AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) {
> >
> >                    private static final long serialVersionUID = 1L;
> >
> >                    @Override
> >                    public CharSequence preDecorateScript(CharSequence
> script) {
> >                        String sJs = "document.getElementById('" +
> form.getMarkupId() + "').target = '_blank';alert(document.getElementById('"
> + form.getMarkupId() + "').target);";
> >
> >                        return sJs + script;
> >                    }
> >                };
> >            }
> >        };
> >
> > Thanks,
> > Jeff
> >
> > * This e-mail and any files transmitted with it may contain confidential
> and/or privileged information and intended solely for the use of the
> individual or entity to whom they are addressed. If you are not the
> addressee or authorized to receive this for the addressee, you must not use,
> copy, disclose, or take any action based on this message or any information
> herein. If you have received this message in error, please advise the sender
> immediately by reply e-mail and delete this message.
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to post form to new window using AjaxSubmitLink

Posted by Igor Vaynberg <ig...@gmail.com>.
you can output some javascript using the ajaxrequesttarget that does window.open

-igor

On Fri, Dec 11, 2009 at 12:31 PM, Jeff Andersen <ja...@posportal.com> wrote:
> I need to know how I can post a form to a new window using an AjaxSubmitLink.  I have a small page where a user can make a few setting changes and then either save those settings (using an AjaxButton) or preview those settings (using an AjaxSubmitLink) in a new window.  The problem is, I can't figure out how to make the preview button open in a new window.  Since there are no popup settings for an AjaxSubmitLink, I'm not sure what to do.
>
> I've tried searching for a solution and the best I could find indicated that I should use a form target="_blank".  But that doesn't seem to change anything.  The call to setResponsePage always results in the preview page opening in the same browser window.
>
> Below is the code for my submit and preview buttons:
>
>        AjaxButton submit = new AjaxButton("websiteSetting-submit-button") {
>
>            @Override
>            protected void onError(AjaxRequestTarget target, Form<?> form) {
>                super.onError(target, form);
>                feedbackPanel.add(new AttributeModifier("style", true, new Model("color:red;")));
>                target.addComponent(feedbackPanel);
>                target.addComponent(form);
>            }
>
>            @Override
>            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
>                processSubmission(target, form, false);
>            }
>
>            //Prepending the call to set the target to nothing for normal form submission.
>            @Override
>            protected IAjaxCallDecorator getAjaxCallDecorator() {
>                return new AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) {
>
>                    private static final long serialVersionUID = 1L;
>
>                    @Override
>                    public CharSequence preDecorateScript(CharSequence script) {
>                        String sJs = "document.getElementById('" + form.getMarkupId() + "').target = '';";
>
>                        return sJs + script;
>                    }
>                };
>            }
>        };
>
>        AjaxSubmitLink preview = new AjaxSubmitLink("websiteSetting-preview-button") {
>
>            @Override
>            protected void onError(AjaxRequestTarget target, Form<?> form) {
>                super.onError(target, form);
>                feedbackPanel.add(new AttributeModifier("style", true, new Model("color:red;")));
>                target.addComponent(feedbackPanel);
>                target.addComponent(form);
>            }
>
>            @Override
>            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
>                setResponsePage(HomePage.class);
>            }
>
>            //Prepending the call to set the target to "_blank" for preview submission to new window.
>            @Override
>            protected IAjaxCallDecorator getAjaxCallDecorator() {
>                return new AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) {
>
>                    private static final long serialVersionUID = 1L;
>
>                    @Override
>                    public CharSequence preDecorateScript(CharSequence script) {
>                        String sJs = "document.getElementById('" + form.getMarkupId() + "').target = '_blank';alert(document.getElementById('" + form.getMarkupId() + "').target);";
>
>                        return sJs + script;
>                    }
>                };
>            }
>        };
>
> Thanks,
> Jeff
>
> * This e-mail and any files transmitted with it may contain confidential and/or privileged information and intended solely for the use of the individual or entity to whom they are addressed. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org