You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by rolandpeng <ro...@cht.com.tw> on 2011/01/20 09:42:28 UTC

How to do setResponsePage after alert message pressed ok?

Hi,
   After doing insert or update,I'd like to show some alert message,such as
"insert succeed. or update succeed.",and then do setResponsePage() to data
listing page.
   But I wonder how to do it under wicket. Would anyone give me some hint?
Thank you!

use case: insert or update-->alert message-->auto redirect to data listing
page.

Roland.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-do-setResponsePage-after-alert-message-pressed-ok-tp3225482p3225482.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: How to do setResponsePage after alert message pressed ok?

Posted by rolandpeng <ro...@cht.com.tw>.
This is what I have done and that works fine.Thank you for your hint!

new AjaxCallDecorator() {
       @Override
       public CharSequence decorateScript(CharSequence script) {
		return "if(!confirm('確定返回嗎?')){return false;};"
			+ script;
	}

	@Override
	public CharSequence decorateOnSuccessScript(CharSequence script) {
		return script + "alert('返回成功!');"
			+ "window.location.href='"
		        + RequestCycle.get().urlFor(getBackPage())+ "';";
	}
};

//getBackPage() is customized method by myself.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-do-setResponsePage-after-alert-message-pressed-ok-tp3225482p3248008.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: How to do setResponsePage after alert message pressed ok?

Posted by rolandpeng <ro...@cht.com.tw>.
reply by myself. 
I use target.appendJavascript to solve my problem.

	@Override
	protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
		onConfirm(target, form);
		target.appendJavascript("alert('" + responseMessage_ + "');");
		if (redirectPage() != null) {
			target.appendJavascript("window.location.href='"
					+ RequestCycle.get().urlFor(redirectPage()) + "';");
		}
	}

//redirectPage() is my customized method.

Roland.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-do-setResponsePage-after-alert-message-pressed-ok-tp3225482p3257458.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: How to do setResponsePage after alert message pressed ok?

Posted by rolandpeng <ro...@cht.com.tw>.
Excuse me,I have one more question.

After I press ajax onsubmit, decorateOnSuccessScript is always executed if
no exception occurred.

how do I stop and not to run decorateOnSuccessScript if the validator finds
some components validate failed?
(The onsubmit action will not be executed while validate error found,so
"insert successfully" alertion should not poped up.)

        //how to skip this function while the validator found error?
        @Override 
        public CharSequence decorateOnSuccessScript(CharSequence script) { 
                return script + "alert('insert successfully');" 
                        + "window.location.href='" 
                        + RequestCycle.get().urlFor(getBackPage())+ "';"; 
        } 

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-do-setResponsePage-after-alert-message-pressed-ok-tp3225482p3256856.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: How to do setResponsePage after alert message pressed ok?

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Thu, Jan 20, 2011 at 2:42 AM, rolandpeng <ro...@cht.com.tw> wrote:

>
> Hi,
>   After doing insert or update,I'd like to show some alert message,such as
> "insert succeed. or update succeed.",and then do setResponsePage() to data
> listing page.
>   But I wonder how to do it under wicket. Would anyone give me some hint?
> Thank you!
>
> use case: insert or update-->alert message-->auto redirect to data listing
> page.
>
> Roland.
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-do-setResponsePage-after-alert-message-pressed-ok-tp3225482p3225482.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
>
>
An alert is client side.  A setResponsePage is server side.  So, you can:

1 - create a response that is JS - it alerts, then does a client side
redirect
2 - not use an alert (which is generally a bad UI decision), and instead use
a feedback panel to show the message on the next page.  As a tip, you can
add a feedback panel to the top of your base page so that it automatically
is present in all pages.  then use getSession().info("Your foo was
completed") and call setResponsePage(YourNextPageClass.class) and it will
appear in the FBP

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*