当没有要显示的错误时从错误页面重定向
如果没有要显示的错误消息(例如,如果用户为错误页面添加了书签),我希望我的 Seam 应用程序的错误页面重定向到主页。
我在pages.xml中有许多规则直接指向这样的错误页面:
<!-- pages.xml -->
<exception class="org.jboss.seam.framework.EntityNotFoundException"
log-level="warn">
<redirect view-id="/error.xhtml">
<message severity="warn">#{messages['jsf.RecordNotFound']}</message>
</redirect>
</exception>
在尝试了一些不成功的EL表达式来尝试检查没有消息之后,我添加了一个支持bean来执行检查:
<!-- pages.xml -->
<page view-id="/error.xhtml">
<action execute="#{facesMessagesUtil.getGlobalMessagesCount()}" />
<navigation>
<rule if-outcome="none">
<redirect view-id="/home.xhtml"/>
</rule>
</navigation>
</page>
。
//FacesMessagesUtil.java
import javax.faces.context.FacesContext;
import org.jboss.seam.faces.FacesMessages;
...
public String getGlobalMessagesCount()
{
log.info("currently {0} global facesMessages (seam)", FacesMessages.instance().getCurrentGlobalMessages().size());
log.info("found messages in faces context: {0}", FacesContext.getCurrentInstance().getMessages().hasNext());
log.info("got maximum severity: {0}", FacesContext.getCurrentInstance().getMaximumSeverity());
if (!FacesContext.getCurrentInstance().getMessages().hasNext())
{
return "none";
}
return "some";
}
当我手动生成错误时,会调用上述方法,但这会重定向到主页并显示错误消息。日志消息报告我正在使用的类似乎看不到正在显示的消息:
16:41:41,908 INFO [FacesMessagesUtil] currently 0 global facesMessages (seam)
16:41:41,908 INFO [FacesMessagesUtil] found messages in faces context: false
16:41:41,908 INFO [FacesMessagesUtil] got maximum severity: null
- seam 2 中是否有一个类允许我检查是否有任何消息?
- 是否有 EL 表达式可以在不需要额外 bean 的情况下执行此检查?
I want my error page of my seam application to redirect to the home page if there is no error message to display (such as if the user bookmarks the error page).
I have a number of rules in pages.xml that direct to an error page like this:
<!-- pages.xml -->
<exception class="org.jboss.seam.framework.EntityNotFoundException"
log-level="warn">
<redirect view-id="/error.xhtml">
<message severity="warn">#{messages['jsf.RecordNotFound']}</message>
</redirect>
</exception>
After trying some unsuccessful EL expressions to try to check for no messages, I added a backing bean to do the check:
<!-- pages.xml -->
<page view-id="/error.xhtml">
<action execute="#{facesMessagesUtil.getGlobalMessagesCount()}" />
<navigation>
<rule if-outcome="none">
<redirect view-id="/home.xhtml"/>
</rule>
</navigation>
</page>
.
//FacesMessagesUtil.java
import javax.faces.context.FacesContext;
import org.jboss.seam.faces.FacesMessages;
...
public String getGlobalMessagesCount()
{
log.info("currently {0} global facesMessages (seam)", FacesMessages.instance().getCurrentGlobalMessages().size());
log.info("found messages in faces context: {0}", FacesContext.getCurrentInstance().getMessages().hasNext());
log.info("got maximum severity: {0}", FacesContext.getCurrentInstance().getMaximumSeverity());
if (!FacesContext.getCurrentInstance().getMessages().hasNext())
{
return "none";
}
return "some";
}
The above method is invoked when I manually generate an error, but this redirects to home and shows the error message there. The log messages report that the classes I'm using don't seem to have any visibility of the message that is being displayed:
16:41:41,908 INFO [FacesMessagesUtil] currently 0 global facesMessages (seam)
16:41:41,908 INFO [FacesMessagesUtil] found messages in faces context: false
16:41:41,908 INFO [FacesMessagesUtil] got maximum severity: null
- Is there a class in seam 2 that will allow me to check if there are any messages?
- Is there an EL expression that can do this check without an extra bean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我到目前为止的调查所能推断出的,这里的问题是seam 如何将FacesMessages 从一个JSF 上下文转发到另一个JSF 上下文。本质上,在应用pages.xml规则时,消息似乎已被删除到其他一些seam组件,然后在页面渲染时返回。我现在已经通过显示“无错误”消息(请注意,页面渲染期间存在全局消息)来解决此问题:
并在我的一个 bean 中使用一些硬编码的重定向规则。
As best I can deduce with my investigations so far, the problem here is with how seam forwards FacesMessages from one JSF context to another. Essentially the messages appear to have been removed to some other seam component while pages.xml rules are being applied, then returned by the time the page is rendering. I have worked around this issue for now by showing a 'no errors' message (note that global messages are present during page render):
and with some hard-coded redirect rules in one of my beans.