0

I involved in JSF Login application. Here there are two methods call doLogin() that is include the login logic and doFilter() inside the LoginBean class. And in the index.xhtml there is an command button called login and here I used this. action="#{loginBean.doLogin}", So I can call doLogin().My problem is How can I call doFilter().

Chandra Sekhar
  • 16,256
  • 10
  • 67
  • 90
user1705260
  • 41
  • 2
  • 6
  • 10

1 Answers1

1

Assuming you have a managed bean like this:

@RequestScoped
@ManagedBean
public class Login {

    public Login() {
    }

    public String doLogin() {
    }

    public void doFilter() {
    }
}

If you need to call doFilter method inside doLogin, just add the call like in basic programming:

public String doLogin() {
    //some code here...
    doFilter();
    //more code over here...
}

Based in your last question: Primefaces Login Application, you're confusing the doFilter method that belongs to the Web Filter and the doLogin method that belongs to a managed bean:

  • The doLogin will be invoked by the FacesServlet when the user activate an event that it calls this method. For example, an UI command action:

    <h:form>
        <h:commandButton value="Click me!" action="#{loginBean.doLogin}" />
    </h:form>
    
  • The doFilter method will be invoked by the Web Filter. Note that a Filter will be executed before the (Faces)Servlet if and only if the request URL matches with the URLPattern declared in the Web Filter. This means:

    • We have a filter with URLPattern = "*.xhtml"
    • Everytime I make a request to <whatever>.xhtml, the Filter will be invoked.
    • When invoked, it will execute the doFilter method (default method).

More info:

As a side note: You really have to learn the basics on Java Web Development and the best practices.

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332