Continue: Question about the flash message

11 views
Skip to first unread message

Terry

unread,
Nov 2, 2012, 1:06:59 AM11/2/12
to scooter-...@googlegroups.com
Hi John, 

Thanks for your reply of my previous post. 

My requirement is to show the "create entry successfully" message in the index page (or page_list page) after user submits the add . So look at following code in the ajaxtodo example,

    public String create() {
        ActiveRecord newEntry = null;
        try {
            newEntry = Entry.newRecord();
            newEntry.setData(params());
            newEntry.save();
            flash("notice", "Entry was successfully created.");
        }
        catch(Exception ex) {
            log.error("Error in create() caused by " + ex.getMessage());
            flash("error", "There was a problem creating the entry record.");
        }
        
        setViewData("entry", newEntry);
        setViewData("entries", Entry.findAll());
        return renderView("index");
    }

In my test, there is no message showed up. But if I change the return to  "return redirectTo("/entries");" , I can get it. (But there will be a refresh on the page, non ajax any more)

Any comments?

John Chen

unread,
Nov 3, 2012, 11:18:18 AM11/3/12
to scooter-...@googlegroups.com
Using redirect will be like sending a new non-ajax request.

The correct way to make it work is to put those AJAX-code in index.jsp file.  
Reply all
Reply to author
Forward
0 new messages