Url PrettyFaces not Initializes @ PreDestroy JSF 2

Splash Forums PrettyFaces Users Url PrettyFaces not Initializes @ PreDestroy JSF 2

This topic contains 1 reply, has 2 voices, and was last updated by  Christian Kaltepoth 4 years, 7 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #18805

    I have a view scoped bean using the primefaces menu item by clicking on it does not boot using the @ PreDestroy pretty but when I use the menu item bean.Action he invokes the @ PreDestroy normally.

    <h:form id="menu" prependId="false">
    <p:menubar>
    <p:menuitem value="Sair" action="loginMB.doLogout" ajax="false" icon="ui-icon-close" />
    </p:menubar>
    </h:form>

    <h:form id="menu" prependId="false">
    <p:menubar>
    <p:menuitem value="Sair" action="pretty:user-test" ajax="false" icon="ui-icon-close" />
    </p:menubar>
    </h:form>

    <url-mapping id="user-test">
    <pattern value="/login" />
    <view-id value="/pages/login.jsf" />
    <action onPostback="false">#{loginMB.doLogout}</action>
    </url-mapping>

    public String doLogout(){
    sessionService.destroySession();
    //return "pretty:login";
    return "/pages/login.jsf";
    }

    #23116

    Your code is a bit confusing. I don’t get what you are trying to do here. You have a mapping for /login that invokes a method that logs the user out.

    And could you please the code where you placed the @PreDestroy?

    I’m also not really sure if it makes sense to call pretty:user-test in the menu item. If you invoke loginMB.doLogout directly, you browser will send a postback, call the logout code and then redirect to the login page. But if you have pretty:user-test in your action attribute, you will get a postback, then a redirect to the login page which invokes the logout method and then redirects to the login page again. That doesn’t make sense to me. :)

    In my applications I typically have two distinct mappings for login and logout. Something like this:

    <url-mapping id="login">
    <pattern value="/login" />
    <view-id value="/pages/login.jsf" />
    </url-mapping>

    <url-mapping id="logout">
    <pattern value="/logout" />
    <action onPostback="false">#{logoutBean.logout}</action>
    <view-id value="/pages/something.jsf" /> <!-- doesn't matter, because we will redirect anyway -->
    </url-mapping>

    public class LogoutBean {

    public String logout() {
    // TODO: process logout
    return "pretty:login";
    }

    }

    Please not that the view Id for the logout mapping actually isn’t important, because request to /logout will always be redirected by the action method.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Comments are closed.