I have an application with 2 xhtml pages each with a managed bean. The first bean is session scoped and the second is request scoped.
When I click a button on my first page it saves some selections in a database and calls the second page. The second page constructor reads the saved records and the content is displayed in a table on the page.

If I press the backward button in my browser I get back to my first page where I can do a new selection which will be added to my first selection and displayed on my second page. So far it works fine and as expected.

Now, if I press the refresh button in my browser when the second page is displayed it will run all code that is run when I press the button on my first page. I.e. the last selection I made on the first page will be duplicated in my database.

I run my application on a tomcat server and I use Eclipse Juno to develop my app.

Can anyone explain why and what I can do to avoid this. When I press the refresh button I only want the constructor for my second page to execute.

First of all: don't use the constructor, use a @PostConstruct annotated method to initialize a bean. Otherwise you will get into problems when you start to use the JSF/JEE features more fully.

JSF uses POST requests by default, even for navigation unless you use specialized JSF 2 components. The way I work around that is to make excessive use of post-get redirects, which in the context of JSF means that after I handle a post back I do this:

That way you end up with a GET request in the end of the chain and the page url is correct too. When the user presses refresh, he/she refreshes that GET request and not the POST request that triggered the doSomeButtonAction().

Be aware that you can only properly use JSF when you really know how it ticks under the hood. I would advise you to do some reading around about it, especially such topics as the stateful nature of JSF and the 6 lifecycle phases.

I have read the Java EE6 tutorial from top to bottom, but it is hard to remember everything written on 1000+ pages.

I'm not sure I understand how to use

return "outcome?faces-redirect=true";

but now I know what to look for so I will search the internet for more information

Thanks again
Lars

I would get a copy of the JSF reference book if I were you (digitally if you must). The tutorial must really suck badly if you didn't pick up on a simple and core concept such as outcomes. Its the cornerstone of JSF navigation :s