Seam不捕获ViewExpiredException

时间:2011-05-12 12:27:58

标签: java jsf jboss seam

我正在使用JSF 1.2 + Seam 2.2.1和JBossAS 4.0.4。

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

<exception>
    <end-conversation/>
    <redirect view-id="/facelets/error.xhtml"/>
</exception>

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

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)

值得注意的是,没有回复任何回复。

我已经尝试明确捕获异常捕获,但它不起作用。

有什么建议吗?

3 个答案:

答案 0 :(得分:0)

我在搜索Seam的错误处理时找到了这个

    <\!-\- 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这是我们用来写入当前页面的一段代码,但您可以重定向到您想要的任何位置。

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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

<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>