首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Seam不会捕获ViewExpiredException

Seam不会捕获ViewExpiredException
EN

Stack Overflow用户
提问于 2011-05-12 20:27:58
回答 3查看 1.3K关注 0票数 0

我使用的是JSF1.2+ Seam 2.2.1和JBossAS 4.0.4。

我在文件pages.xml中有以下条目:

代码语言:javascript
复制
<exception>
    <end-conversation/>
    <redirect view-id="/facelets/error.xhtml"/>
</exception>

但是,如果我在会话到期后单击commandLink和commandButton,服务器会抛出以下异常:

代码语言:javascript
复制
12:19:09,671 WARN  [lifecycle] executePhase(RESTORE_VIEW 1,com.sun.faces.context.FacesContextImpl@1d7187f) threw exception
javax.faces.application.ViewExpiredException: viewId:/facelets/login.xhtml - View /facelets/login.xhtml could not be restored.
  at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:187)

同样值得注意的是,任何响应都不会返回。

我已经尝试过显式地捕获异常,但它不起作用。

有什么建议吗?

EN

回答 3

Stack Overflow用户

发布于 2011-05-12 22:15:54

我在搜索Seam的错误处理时发现了这一点

代码语言:javascript
复制
    <\!-\- Now we specify the super class of all Exceptions: java.lang.Exception.  This will catch all exceptions. \-->
    <\!-\- But it will give us access to the Exception to retrieve its contents for display to the screen.         \--> 
  <exception class="java.lang.Exception">
      <\!-\- still a good idea to end the "conversation" rather than leaving it open ended. \-->
      <end-conversation/>
        <\!-\- now we redirect to the current page. The code for this is in the next example. \-->
      <redirect view-id="#{viewId.currentValue}">
        <\!-\- specify the message severity as error.  Also the expression language used below allows us to "grab"-->      
        <\!-\- the exception that was captured above and then pass it to the h:message tag for display to the end \-->    
        <\!-\- user.  Much nicer than a debug screen.                                                             \-->     
        <message severity="error">
          #{org.jboss.seam.handledException.message}
        </message>
      </redirect>
  </exception>

有了这个,你实际上应该能够捕捉到所有的东西,并公开它的真实面目。viewId.currentValue是我们用来写到当前页面的一段代码,但是你可以重定向到你想要的任何地方。

票数 0
EN

Stack Overflow用户

发布于 2011-05-13 20:51:43

我在Seam's community site上找到了这个链接,他们正在讨论一个类似的问题。也许你的答案就在那里?它们涵盖了几种不同的解决方案,这取决于问题的根源。

票数 0
EN

Stack Overflow用户

发布于 2011-07-21 04:29:31

尝试在pages.xml中使用以下内容:

代码语言:javascript
复制
<exception class="javax.faces.application.ViewExpiredException">
    <redirect view-id="/pages/login.xhtml">
        <message severity="error">Your session has timed out, please Log-In again</message>
    </redirect>
</exception>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5977968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档