How to show flash message when using ajax framework?

20 views
Skip to first unread message

Terry

unread,
Nov 1, 2012, 9:31:15 AM11/1/12
to scooter-...@googlegroups.com
Hi John,

As title, you know now we get the http response as html and show it in a div. But how we show the flash message correctly?

Here is a scenario, 
1.click "add" link and show the form.
2.submit the form to create a new entry with ajax,
3.in controller, save the entry, flash a message(such as "created successfully") then return to the page list view.
4.there is no flash message in the page
5.click the "show"(or page list) link, the flash message shows up.

Any suggestion?

John Chen

unread,
Nov 1, 2012, 10:44:07 PM11/1/12
to scooter-...@googlegroups.com
This is because you probably did not include flash handling code in your views. 

Here is a quick test:
1. Go to WEB-INF\views\layouts\includes directory and open file status.jsp. 
2. Copy the code in that file, including imports, to your add.jsp file
3. Add a flash notice like the following in your controller's add() method:
    public String add() {
        flashNotice("Just clicked add link");
        setViewData("entry", Entry.newRecord());
        return null;
    }
4. Now click on the add link and see the notice message appears in your browser.

I was able to test it with the AJAX example in scooter\examples\ajaxtodo

John

Terry

unread,
Nov 1, 2012, 11:24:57 PM11/1/12
to scooter-...@googlegroups.com
Thanks very much ! I'll test it later.
Reply all
Reply to author
Forward
0 new messages