简体   繁体   中英

How to display success message after redirection to another JSF?

After a customer is successfully added in my JSF application on the page add_customer.jsf , the user is redirected to the page list_customers.jsf .

On this page I would like a success message to be shown. The message should only be shown if the user is really coming from the add_customer.jsf page.

How can I do this?

One approach is to add a message to The Flash in the action method that adds the customer.

You don't need to explicitly check that the user was coming from add_customer.jsf , if it's that page (or actually the code behind it) that sets the message. On the destination page you only need to have an <h:messages> component.

A co-worker of my posted an example CRUD app that does exactly this at: Sample CRUD application with JSF .

The relevant code is in the backing bean UserEdit and the page where the redirect happens to.

Note that if your JSF implementation is Mojarra, The Flash only works between pages in the same directory. If this bothers you, please consider voting for this issue: http://java.net/jira/browse/JAVASERVERFACES-2136

The best way to do it would be using a <h:message> tag with which you could bind a message which can be populated before you redirect to list_customer.jsf .

We have been using this approach for showing messages in our application from last 3-4 years and occasionally used partial triggers to refresh on the same page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM