You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ihmehlmenn <ih...@gmx.de> on 2015/04/24 17:10:12 UTC

Open non-bookmarkable page in popup on form submit

Hello,

I'm using Wicket 6.13 and I'm facing the requirement to open a
non-bookmarkable Page in a Popup once a form is succesfully submitted.

I came up with following solution which seems to work ... but it feels kind
of wrong to me and it wouldn't suprise me, if there are any downsides and
pitfalls with it.

So I wonder, if there is a more elegant way to do it.

Form<Void> wicketForm = new Form<Void>("form") {

    @Override
    protected void onSubmit() {
        super.onSubmit();

        ResultObject result = save(); // Saves data and generates the result
object for the popup page

        if (result != null) {
            Page page = new ShowResultObjectPage(result);
            page.render(); // without this I get a PageExpiredException in
the opened Popup
            final CharSequence url = getRequestCycle().urlFor(new
RenderPageRequestHandler(new PageProvider(page));
            
            add(new Behavior() {
                @Override
                public void renderHead(Component component, IHeaderResponse
response) {
                    PopupSettings popupSettings = new
PopupSettings(PopupSettings.SCROLLBARS | PopupSettings.RESIZABLE);
                    popupSettings.setWidth(500);
                    popupSettings.setHeight(400);
                    popupSettings.setTarget("'" + url + "'");
                   
response.render(OnDomReadyHeaderItem.forScript("(function() {" +
popupSettings.getPopupJavaScript() + "})();"));
                }

                @Override
                public boolean isTemporary(Component component) {
                    return true;
                }
            });
        }
    }
};
(code shortened)

I already considered these other options, but (for now) come to the
conclusion, that I should try the way mentioned above.

- Using a bookmarkable Page.
I would like to avoid that, since the data for the popup page is somewhat
complex and might not fit into the URL. Also it would probably mean, that a
millicious user could manipulate the data and I'd have to rerun the checks
in the popup page.

- Saving the ResultObject for the popup page in the users session and then
retrieving it again in the popup page itself.
Since the ShowResultObjectPage already has a constructor for providing the
ResultObject that is already used somewhere else in the code, I'd end up
writing this crutch only for this special case.

- Using an invisible Link which opens the popup, that gets "clicked" via
JavaScript
That one just makes me cringe ^^

So, is there any better way to achive what I'm trying to do?

Daniel

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Open-non-bookmarkable-page-in-popup-on-form-submit-tp4670499.html
Sent from the Users forum 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: Open non-bookmarkable page in popup on form submit

Posted by Ihmehlmenn <ih...@gmx.de>.
Thank you both for your reply. We haven't worked with ModalWindows yet but
I'll check if that would be an option for the future.

@Martin
Thanks for suggesting to use page.dirty() instead of page.render().
It didn't give me the expected result, but led me to further investigate
what's going on there. Turns out the Wicket version we use (6.13.0) has a
bug (WICKET-5499), which results in Wicket not storing newly created pages
in the page store.
After updating to 6.19.0 neither calling page.render() nor page.dirty() is
needed anymore. :)

Daniel

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Open-non-bookmarkable-page-in-popup-on-form-submit-tp4670499p4670512.html
Sent from the Users forum 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: Open non-bookmarkable page in popup on form submit

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Indeed this looks like a good candidate for ModalWindow, either with a Page
or a Panel.
For this you should use AjaxButton or AjaxSubmitLink.

If you can't use Ajax in this case for some reason then your solution
should be fine.

Instead of page.render() you can use page.dirty(), so that it is stored in
the http/disk stores and available in the next request(s).

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Sat, Apr 25, 2015 at 11:15 AM, kovaron <ko...@gmail.com> wrote:

> Does it have to be a Page instance?
> Isn't Panel a good choice for you?
> I'm asking because Panel extends can be easily embedded into a Modal window
> and you can simply pass a Model to it in constructor.
> And you can of course override it's close method to change the source Panel
> with AjaxRequestTarget.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Open-non-bookmarkable-page-in-popup-on-form-submit-tp4670499p4670500.html
> Sent from the Users forum 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: Open non-bookmarkable page in popup on form submit

Posted by kovaron <ko...@gmail.com>.
Does it have to be a Page instance?
Isn't Panel a good choice for you?
I'm asking because Panel extends can be easily embedded into a Modal window
and you can simply pass a Model to it in constructor.
And you can of course override it's close method to change the source Panel
with AjaxRequestTarget.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Open-non-bookmarkable-page-in-popup-on-form-submit-tp4670499p4670500.html
Sent from the Users forum 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