2013-05-01 21 views
3

刷新对话期间显示的页面时出现错误。如何避免这个错误?WELD-000321刷新页面时未发现要恢复id 3的对话

的情况:

我有2个JSF页面,和的index.xhtml age.xhtml。

index.xhtml包含一个表单,用户输入出生日期(支持bean“bean”的属性)。当用户提交表单时,age.xhtml根据出生日期显示年龄。

提交表单与重定向:

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

computeAge方法:

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

同样支持bean “豆” 用于由两个页面。这个支持bean有一个对话范围。

页age.xhtml:

Your age: #{bean.age} years 

getAge方法:

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

一切正常,除非我刷新age.xhtml。然后我收到此错误信息: WELD-000321未找到要还原ID谈话3

前和后刷新浏览器中显示的网址: http://localhost:8080/tpjsf1/faces/age.xhtml?cid=3

的问题来自CID = 3的结束。当用户刷新age.xhtml时可以避免错误页面吗?

回答

0

当您在getAge方法中结束对话时发生错误。在你的情况下,当你回到索引页面时,对话应该结束。为了处理不存在的会话异常,请将以下标记添加到Web xml中。这会将异常重定向到所提到的页面。

<error-page> 
    <exception-type>org.jboss.weld.context.NonexistentConversationException</exception-type> 
    <location>/my-foo-bar-exception-page.xhtml</location> 
</error-page>