How do I logout in JSF ?

Hey up,
I'm doing an app in JSF, and I dont know how logout lol !
I have the following:
my managedBean:
public class Login {
    private String nome;
    private String senha;
    private boolean logged;
//getters and setters
    public  String validateLogin(){
        if(nome!=null && senha!=null && !nome.equalsIgnoreCase(senha)){
            logged = true;
            return "main";
        }else
            return "login";
    public boolean isLogged() {
        //HERE I'D LIKE SOMETHING TO CHECK AND DO LOGOUT IF ITS FALSE
        return logged;
    public String doLogout(){
        logged = false;
        //WHAT DO I PUT HERE ?
        return "login";
    }this is my faces config
    <managed-bean>
        <managed-bean-name>Login</managed-bean-name>
        <managed-bean-class>Main.Login</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
        <from-view-id>/welcomeJSF.jsp</from-view-id>
        <navigation-case>
            <from-outcome>login</from-outcome>
            <to-view-id>/welcomeJSF.jsp</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>main</from-outcome>
            <to-view-id>/jlogin.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>
    <navigation-rule>
        <from-view-id>/jlogin.jsp</from-view-id>
        <navigation-case>
            <from-outcome>login</from-outcome>
            <to-view-id>/welcomeJSF.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>so... I dont know how do logout! does someone can help me out on this ?
thanks
Rafael Broz

I have make a jar of following class
package jsfnocache;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.servlet.http.HttpServletResponse;
public class CacheControlPhaseListener implements PhaseListener {
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
public void afterPhase(PhaseEvent event) {}
public void beforePhase(PhaseEvent event) {
FacesContext facesContext = event.getFacesContext();
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-cache");
response.addHeader("Cache-Control", "must-revalidate");
response.addHeader("Expires", "Mon, 8 Aug 2006 10:00:00 GMT"); // some date in the past
}then in faces-config.xml i have added following entry
<lifecycle>
        <phase-listener>jsfnocache.CacheControlPhaseListener</phase-listener>
    </lifecycle>now in my application page flow is somethiing like this:
when user loggin one session bean gets created and it holds info. to show this user is logeed in..
when user clicks on sign out link all info will be destroyed and user will be redirected to the home page again to login..
BUT AFTER DOING ABOVE MENTIONED IMPLEMENTATION WHEN USER PRESSES BACK BUTTON HE GETS THE PAGES BACK AGAIN>>IS THERE ANY ADDITIONAL CONF. REQUIRED?

Similar Messages

  • How to get the current JSF phase in backing bean?

    How to get the current JSF phase in backing bean?
    Edited by: jimmy6 on Nov 27, 2007 7:27 AM

    I am using phasetracker to trace it also.I want to know whether it is it render response phase. I know FacesContext.getCurrentInstance().getRenderResponse() work for normal jsf component but it will not work for qiupukit datatable. FacesContext.getCurrentInstance().getRenderResponse() will not return true in the following phase. Why?
    [ INFO] 27-11-07 16:20:21 : BEFORE RENDER_RESPONSE(6) (http-80-Processor23)
    I want the 'get' method of datatable being called in response phase to reduce the number of calling because i put the query in 'get' method there. Actually i still straggling with the best practice to code the datatable...

  • How to invoke "j_security_check" in jsf page

    Hi,
    with ADF security configure in Jdeveloper11.1.1.2, it automatically generate login.html and error.html for form authentication.
    I found in login.html, the action for form is "j_security_check", and I try to customize login page with jsf page, but don't know how to invoke "j_security_check" in jsf page, there is no more action attribute within af:form and I cannot find the "j_security_check" in commandButton action Expression Build.
    Thanks in advanced.
    Best Regards,
    Bill

    Hi,
    you will have to add the login form to the JSf page wrapped in f:verbatim so it shows as part ofthe JSF page. In JSF 1.2 using f:verbatim shoucl not be require, but by experience, better is.
    If you develop and deploy on WLS, then chapter 30 of the Fusion Developer Guide has a god solution for you to build a login form in JSF completely
    http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/adding_security.htm#BABDEICH
    This does not require j_security_check at all
    Frank

  • What does the scriptcollector do and how does it related to jsf lifecycle?

    hi,
    i want to know what does the scriptcollector do and how does it related to jsf lifecycle? and also in the scriptcollector if i call this,
    preRender=#{myBean.onPageLoadBegin}
    postRender=#{myBean.onPageLoadEnd}
    how my page will react?

    The hx:scriptCollector is part of the IBM Faces Client Framework and has nothing to do with Sun JSF RI.
    Lot of the hx components require specific Javascript and those hx components should be placed inside a single hx:scriptCollector which on its turn checks the nested hx components and renders the desired Javascript for it at the end of the tag. Check the HTML source for that Javascript.

  • How to write logout method

    hi
    how to write logout method..... i am new to programming
    protected void logOut(){
    asap

    When I posted my first reply, I was thinking of writing to an output log. Do you mean "logout" like in web applications???
    You don't need to write any special code for that. At the most, you would want to clean up the resources like connections, sockets,... created by the application. If you have some mechanism which retains some "login" information, you might reset it to some default value.
    Why don't you be specific with your question instead of writing in such a vague manner?

  • How to access af:table JSF EL variable in scriptlet?

    Hi,
    I have an <af:table> tag that iterates over a collection like this:
    <af:table emptyText="No items were found"
    value="#{viewUsersHandler.users}"
    var="user" rows="20" banding="row"
    bandingInterval="1">
    <% User user=pageContext.getAttribute("user"); //RETURNS NULL!
    %>
    </af:table>
    How can I access the JSF EL variable, "user" in my scriptlet?
    pageContext.getAttribute("user") returns me a null

    Found that the solution doesn't really work in my context after all:
    <c:set var="user2" value="${user}" scope="page"/>
    seems to be only executed once, not every iteration, therefore only the very first row of the table is set as "user2" in pageContext
    Does anyone know how I can get <c:set var="user2" value="${user}" scope="page"/> to be executed again every iteration? I tried it in <af:table> and <af:forEach> but both don't work.
    Oops, I found out the solution:
    use <c:set var="user" value="${user}" scope="page"/>
    to make it accessible via PageContext
    Hi,
    I have an <af:table> tag that iterates over a
    collection like this:
    <af:table emptyText="No items were found"
    alue="#{viewUsersHandler.users}"
    var="user" rows="20"
    banding="row"
    bandingInterval="1">
    /RETURNS NULL!
    /af:table>
    How can I access the JSF EL variable, "user" in my
    scriptlet?
    pageContext.getAttribute("user") returns me a null

  • How to add fragment in jsf page using include tag in jdeveloper

    Hi all
    Can you tell me wat is syntax of using include tag .or how to add fragment in jsf page ..
    Edited by: 947228 on Jul 18, 2012 5:01 AM

    Hi,
    Why do you want to do that?
    Check [url https://blogs.oracle.com/jheadstart/entry/avoid_use_of_jspinclude_where]this out before proceeding further.
    Btw, always mention your JDev version, clear usecase to get help.
    -Arun

  • How can i logout of find my iphone on a old device I ain't got

    How can i logout of find my iphone on a old device I ain't got

    Welcome to the Apple community.
        1.    Sign in to their iCloud account at www.icloud.com/find.
        2.    Select the device from their Find My iPhone device list by clicking All Devices at the top of the screen.
        3.    Erase the device by clicking the Erase button. This will erase all content and settings from the device. When prompted, do not enter a phone number or message. Click Next until the device is erased.
        4.    When the erase is complete, click "Remove from Account" to remove the device from the account.

  • How do I logout from icloud so that my wife can login?

    How do I logout from icloud so that my wife can login?

    You don't, unless you want to remove all your iCloud content from your phone.
    Why does your wife want to log in to iCloud on your phone? If it is to check her email, you'd need to setup her email account as a secondary one in Settings > Mail, Contacts, Calendars.

  • How to make a login and logout in jsf  2.0 ?

    Hello all, i am developing an web application have login and logout component. I want to check whenever end user try to open admin/index.xhtml, it will be redirected to login.xhtml. And when end user click on log out button, i will be destroy session and redirect end user to login.xhtml. But i am not sure about session in JSF 2.0. I am using netbean 6.9.1 to develop. First time, when i run my web application, i can get session back. But another time, i can't get session in my bean. Do i can use filter with JSF 2.0 to make a validate login user ? And any suggestion for my issue ? Thanks in advance!
    Here is my filter with doFilter method:
    RequestWrapper wrappedRequest = new RequestWrapper((HttpServletRequest) request);
    ResponseWrapper wrappedResponse = new ResponseWrapper((HttpServletResponse) response);
    if (wrappedRequest.getSession().getAttribute("isValidUser") != null) {
    chain.doFilter(request, response);
    } else {
    goPage(wrappedRequest, wrappedResponse, "/faces/enduser/index.xhtml");
    And here is my bean with login and log out method:
    public String validUser() {
    try {
    if (iAccBO != null) {
    Utilities utilities = new Utilities();
    Account account = new Account();
    account.setAccName(getAccName());
    account.setPassword(utilities.encode(getPassword()));
    if (iAccBO.validUser(account)) {
    setAccName("");
    setPassword("");
    return "/admin/index";
    } else {
    FacesContext fc = FacesContext.getCurrentInstance();
    fc.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "invalid username or password", ""));
    return "login";
    } catch (Exception ex) {
    ex.printStackTrace();
    Logger.getLogger(AccountBean.class.getName()).log(Level.SEVERE, null, ex);
    return null;
    public String Logout() {
    try {
    servletRequest.getSession().invalidate();
    return "../login";
    } catch (Exception e) {
    e.printStackTrace();
    return "";
    Best Regards,
    Coy.

    I looked up it but it seem not work with me. Almost example which i found is run on Glass Fish. But I am running on TomCat server of Netbeans 6.9.1. Can someone give me another suggestion ?
    Thanks in advance!
    Best Regards,
    Coy.

  • How to get logout to work for partner applications

    Hi
    I have configured the demo partner application of the ssosdk 3.07
    And login / logout works.
    My problem is that the sample logout code, only clears the
    cookie of the partner application, so the code redirects the
    appliation to the login server which reauthenticates the partner
    application.
    So shall the logout code clear the portal30_sso cookie.
    My other problem is the other way around, when I log out of
    Portal, I also need to be logged out of the partner application,
    have anybody have any success with that.
    Jakob

    FOR ASSISTANCE WITH ORDERS - iTUNES STORE CUSTOMER SERVICE
    For assistance with billing questions or other order inquiries, please refer to our online support page by clicking here: http://www.apple.com/support/itunes/store/. If you cannot find the answers you are seeking in our robust knowledge base, you can contact us by visiting the following URL http://www.apple.com/support/itunes/store/, clicking on the appropriate Customer Service topic, then using the contact button or email form at the bottom of the page. Responses to emails will be provided as soon as possible.
    Phone: 800-275-2273 How to reach a live person: Press 0 four times
    Hours of Operation: Mon-Fri: 9am-5pm ET
    Email: [email protected]
    How to report an issue with Your iTunes Store purchase
    http://support.apple.com/kb/HT1933
    iTunes Purchase Problems: How to Report a Problem to iTunes Support
    http://tinyurl.com/7tscpa7
    How to Get a Refund from the App Store
    http://gizmodo.com/5886683/how-to-get-a-refund-from-the-app-store
    Getting Refunds for your iTunes Store Purchases
    http://www.labnol.org/software/itunes-app-store-refunds/13838/
    Canceling a Digital Subscription
    http://gadgetwise.blogs.nytimes.com/2011/10/14/qa-canceling-a-digital-subscripti on/
     Cheers, Tom

  • How can I test a JSF application?

    Hi all,
    I'm beginner in JSF applications.
    I'd like to know how could I to do a little project using JSF.
    Does anyone send me a link with that steps?
    So, for example, I tried this: http://myfaces.apache.org/risamples.html
    But it does not run!
    I got this error: "HTTP Status 503 - Servlet Faces Servlet is currently unavailable"
    I'd like to config an application with:
    - myfaces-tobago
    - or tomahawk
    But I don't know where I must to place each jar files in order to the application can work fine. That is the big issue:
    Where MUST I to place EACH jar file in order to application does not complain!
    is there any template with a bit project pre-configured?
    I will be very pleased with any help!
    Regards!
    PS:
    I'm using:
    - Eclipse with Exadel plugin
    - Tomcat Tomcat 5.5
    - Windows

    Hi!
    I solved that problems!
    Related the JSF, It was about the correct <managed-property> .
    Now would be only about the following:
    - myfaces-tobago
    - or tomahawk
    thanks anyway

  • How can I set a JSF page to accept requests from outside

    I have a file upload page in my application(JSF and MyFaces). It works fine when I navigate to page and select the file to upload and submit. Do I need to make any changes to this page to post from an external system?
    I created a perl script to send a file to this page. When I called the URL for this page, it returned the page content. How can I submit from the perl script?
    <h:form id="apppostform" name="apppostform" enctype="multipart/form-data" >
              <h:panelGrid styleClass="mbformdata" columns="2" border="0" cellspacing="25" cellpadding="0">
              <h:outputText value="#{appmsg.prompt_upload_file}"/>
              <t:inputFileUpload id="fileupload"
              value="#{fileUploadForm.upFile}"
              storage="file"
              styleClass="fileUploadInput"
              />
                   <h:commandButton type="submit" value="submit" action="#{fileUploadForm.uploadFile}"/>
                   </h:panelGrid>
    </h:form>
    Thanks,
    rm

    I created uploadservlet. I specified in web.xml:
    <servlet>
    <servlet-name>uploadservlet</servlet-name>
    <display-name>UploadServlet</display-name>
    <servlet-class>servlet.UploadServlet</servlet-class>
    </servlet>
    When I try to access uploadservlet, I am getting 404 error.
    I have few questions:
    How does it know about uploadservlet if it is not inherited from facesservlet while using JSF?
    Do I need to add any info about this in faces-config.xml?
    Please help!
    Thanks

  • How to implement logout functionlity in portlet .

    Hi all ,
    I have created a portlet on webcenter .
    This portlet contains two button Accept and Deny .
    On accept user is redircted to other page and on deny user sud be logged out from current session .
    Can anyone tell me how can i implement logout functionality in my portlet .
    Thanks ,
    Arun.

    If your portlet only contains that functionality i suggest you convert it to a taskflow instead of portlet.
    The issue with portlets is that it gets the context from its portal but it can not invalidate the session of its consumer.
    Maybe it's possible but it's not that straight forward. When you create a taskflow, you stay in the same context as the portal and you can easily do a regular logout.
    A logout link should have following destination:
    /adfAuthentication?logout=true&end_url=/faces/PublicPage
    the /faces/PublicPage can be changed so people will be redirected to that page.
    When you add a link to a portlet with that destination it will not work. When you add it to a taskflow, it will work.

  • How to use javascript for jsf containg t:htmlTags instead of panel grids

    Hi,
    i tried out validation in the following manner:
    function valid(form){
    alert(" 1:Entered valid function ");
    var varCritical1=document.form["form:critical1"].checked;
    var varHigh1=document.form["form:high1"].checked;
    if (varHigh1&&varCritical1){
    alert("Select only one option");
    document.form["form:critical1"].focus();
    document.form["form:high1"].focus();
    return false;
    return true;
    ====== the jsf code for the above is:
    <t:htmlTag value="td" style="border: 1px solid;">
    <h:commandButton id="commit" value="Commit all Changes" action="commit" styleClass="submit-button"
                                  onClick="return valid(this.form)" />
    </t:htmlTag>
    ======
    could anyone suggest me how to do this validation..
    faster reply is appreciated
    -Thanks,
    Soumya Desu

    When writing JS and you're new to JSF (so new that you don't know out of head which HTML a JSF component generate), you need to base the JS code on the generated HTML output, not on the JSF source code.
    For problems and/or support with writing JS code, please consult a JS forum. There are ones at webdeveloper.com and dynamicdrive.com. Please keep in mind that JSF source code is completely irrelevant for the JS forum users (and actually also for you), concentrate on and share the generated HTML output.

Maybe you are looking for