【问题标题】:WELD-000321 No conversation found to restore for id 3 when I refresh a pageWELD-000321 当我刷新页面时,找不到要恢复 id 3 的对话
【发布时间】:2013-04-25 21:30:06
【问题描述】:

刷新对话期间显示的页面时出现错误。如何避免这个错误?

情况:

我有 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”。这个支持 bean 有一个对话范围。

页面年龄.xhtml:

Your age: #{bean.age} years

getAge 方法:

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

一切正常,除非我刷新age.xhtml。然后我收到此错误消息: WELD-000321 找不到要恢复 id 3 的对话

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

问题出在最后的 cid=3 上。用户刷新age.xhtml时是否可以避免错误页面?

【问题讨论】:

    标签: jsf-2 conversation-scope


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2013-06-23
      • 2021-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 2020-01-06
      相关资源
      最近更新 更多