3

I get an error when I refresh a page displayed during a conversation. How to avoid this error?

The situation:

I have 2 JSF pages, index.xhtml and age.xhtml.

index.xhtml contains a form where the user enter a birthdate (a property of the backing bean "bean"). When the user submits the form, age.xhtml displays the age according to the birthdate.

The form is submitted with a redirection:

<h:commandButton value="Submit" action="#{bean.computeAge()}" />

computeAge method:

conversation.begin();
return "age?faces-redirect=true";

The same backing bean "bean" is used by both pages. This backing bean has a conversation scope.

Page age.xhtml:

Your age: #{bean.age} years

getAge method:

if (!conversation.isTransient()) {
  conversation.end();
}
return ejb.computeAge(birthdate);

All is OK, except when I refresh age.xhtml. Then I receive this error message: WELD-000321 No conversation found to restore for id 3

The URL displayed by the browser before and after the refresh: http://localhost:8080/tpjsf1/faces/age.xhtml?cid=3

The problem comes from cid=3 at the end. Is it possible to avoid the error page when the user refreshes age.xhtml?

user1643352
  • 2,635
  • 2
  • 19
  • 25

1 Answers1

0

The error occurs as you are ending the conversation in the getAge method. In your case the conversation should end when you navigate back to the index page. In order to handle the non existent conversation exception, add the below tags to the web xml. This will redirect the exception to the mentioned page.

<error-page>   
    <exception-type>org.jboss.weld.context.NonexistentConversationException</exception-type>   
    <location>/my-foo-bar-exception-page.xhtml</location>   
</error-page>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Adwin
  • 105
  • 1
  • 2
  • 9