Question

hello i am using prettyfaces jsf2.0 i ve created a filter which is checking every request whether user is logged in or not

@WebFilter(urlPatterns= {"*.xhtml"} , dispatcherTypes = {DispatcherType.REQUEST})
public class Authentication implements Filter {

@Override
public void init(FilterConfig config) throws ServletException {
System.out.println("[Authentication Filter] : init Method");
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws         IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession(false);
PrettyContext context = PrettyContext.getCurrentInstance(request);      
if (!(context.getCurrentMapping().getId().equals("login")) && (session == null ||     session.getAttribute("username") == null)) {
{
response.sendRedirect(request.getContextPath()+"/login");
}
else {
chain.doFilter(req, res); // Logged-in user found, so just continue request.
}
@Override
public void destroy() {}
}

when i started tomcat server it load login.xhtml page URL is showing in address bar //localhost:8080/MyApp/login in login.xhtml i ve form with user name and password fields

when i submit form using

<p:commandButton ajax="false" value="Login" action="pretty:loggedin" />

and when i get values in action class, the values are null there and when i print system.out.println loggin in filter it looks like two URL are requesting 1. /login 2. /loggedin thats y values are getting null there. any solution please thanks in advance.

Was it helpful?

Solution

It doesn't look correct what you are doing. You are using pretty:loggedin as an action attribute in your login command button. This won't execute any action method but instead redirect to some other mapping without any chance to process the values the user entered.

You should instead reference an method in your action attribute which you use process the login attempt. If it was successful, the this method should return pretty:loggedin which will redirect the user to the new page.

I hope this helps a bit. If you have more problems, you should post on the PrettyFaces forums. That's a better place to help you if solving the problem takes multiple question/response cycles. :)

http://ocpsoft.org/support/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top