开发者

How to redirect to error page in JSF when FacesContext session attribute is not found

开发者 https://www.devze.com 2023-04-13 03:26 出处:网络
I am developing a mobile webapp using JSF and Apache myFac开发者_Python百科es 1.2.9. During authentication i am calling a servlet which will do the authentication and then set some attribute in the s

I am developing a mobile webapp using JSF and Apache myFac开发者_Python百科es 1.2.9.

During authentication i am calling a servlet which will do the authentication and then set some attribute in the session.

And in every managed bean constructor i am checking for this session attribute and accordingly i am setting a boolean value.That boolean value i am setting as a value for rendered attribute of tr:document.Something like this

<tr:document title="someid" rendered="#{controller.render}">
//SOME PAGE CONTENTS
</tr:document>

Based on the session attribute,the page may render or not.I want to handle this issue more gracefully.

I came through this question in SO which tells the usage of filters.I used the filter as shown here.

I changed the webFilter urlPattern to /faces/jsp/* as i want to check the session attribute for each jsp.

In doFilter() method i am checking for session attribute like this and if it is null i am redirecting to invalid user page.

System.out.println("In doFilter");
            HttpServletRequest request = (HttpServletRequest) req;
            HttpServletResponse response = (HttpServletResponse) res;
            HttpSession session = request.getSession(false);

            if (session.getAttribute("myattribute") == null) {
       response.sendRedirect(properties.getProperty(INVALID_USER_REDIRECTURL, true));  // No attribute found, so redirect to Invalid user page.
            } else {
                chain.doFilter(req, res); // attribute found, so just continue request.
            }

But i don't see my filter getting fired as i don't see any debug statements which i kept in my filter init(),doFilter() methods.

Any help?

EDIT:I just came through this filter mapping in my web.xml

<filter>
    <filter-name>trinidad</filter-name>
    <filter-class>org.apache.myfaces.trinidad.webapp.TrinidadFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>trinidad</filter-name>
    <servlet-name>faces</servlet-name>
  </filter-mapping>

I suppose myfaces has some filter.Can i have another one of mine?


Map the filter to URL pattern where your FacesServlet is mapped.

0

精彩评论

暂无评论...
验证码 换一张
取 消