jstl验证c:如果在超时时导致异常

时间:2013-02-19 10:02:40

标签: jsp jsf jstl

我有一个使用RichFaces和jsf的页面,我添加了一些jstl代码来验证bean中的内容,这个代码在会话超时时被验证,这会触发一些异常,代码是:

<c:if test="#{ViewerController.viewerBean.canCountMessages}" >
    <td>
        <a4j:commandButton value="count" action="#{ViewerController.doCount}" />
    </td>
</c:if>

因此,此代码得到验证,并引发以下异常:

/pages/viewer/index.xhtml @43,67 test="#{ViewerController.viewerBean.canCountMessages}" An error occurred performing resource injection on managed bean ViewerController

是否有办法阻止在会话无效时验证c:if标记

注意:ViewerController类是SessionScoped。

1 个答案:

答案 0 :(得分:1)

我能够得到一个解决方法,它可以帮助有类似问题的人,

好吧,我在用户登录后在会话中保存了一些变量,并查询了这个变量是否确实存在于c:if语句中,如:

在Web应用程序中记录用户时:

 FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("SessionValid",true); 

并在ViewerController类中添加了此方法:

boolean isSessionValid(){
    return FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("SessionValid") !=  null ;
}

我的代码就像:

<c:if test="#{ViewerController.sessionValid and ViewerController.viewerBean.canCountMessages}" >
    <td>
        <a4j:commandButton value="count" action="#{ViewerController.doCount}" />
    </td>
</c:if>