Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8279451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:20:58+00:00 2026-06-08T09:20:58+00:00

Here is my code: <h:form> <h:messages errorClass=errorMessage infoClass=infoMessage warnClass=warnMessage></h:messages> <h:panelGroup id=login layout=block rendered=#{!securityBean.authorized}> <h:outputText

  • 0

Here is my code:

<h:form>
    <h:messages errorClass="errorMessage" infoClass="infoMessage"
                warnClass="warnMessage"></h:messages>
    <h:panelGroup id="login" layout="block" rendered="#{!securityBean.authorized}">
        <h:outputText value="login:"/>
        <h:inputText id="username" value="#{securityBean.username}"/>
        <h:outputText value="password:"/>
        <h:inputSecret id="password" value="#{securityBean.password}"/>
        <h:commandButton value="login" action="#{securityBean.login}"/>
    </h:panelGroup>

    <h:panelGroup id="logout" layout="block" rendered="#{securityBean.authorized}">
        <h:graphicImage id="img" library="img" name="login_success.jpg"/>
        <h:commandButton value="logout" action="#{securityBean.logout}"/>
    </h:panelGroup>
</h:form>

here is backing bean methods

    public Object login() throws ServletException {
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        try {
            request.login(username, password);
        } catch (ServletException e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "An Error Occured: Login failed", null));
            e.printStackTrace();
        }
        return null;
    }

    public Object logout(){
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        if(session != null){
            session.invalidate();
        }
        return null;
    }
    public boolean isAuthorized() {
        return FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal() != null &&
                FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName() != null &&
                !FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName().isEmpty();
    }

After login, logout button appears, but it works only on the second click. As you can see no ajax is used here, so this http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentWhichContainsAnotherForm can’t help me..
How can I make it work correct? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:21:03+00:00Added an answer on June 8, 2026 at 9:21 am

    I think you have that problem because you need a redirection (using an outcome, not null) to a home page or something after logout. I had that problem, and I solved like this:

    public String logout(){
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        if(session != null){
            session.invalidate();
        }
        return "redirectToHomePageAfterLogout";
    }
    

    Hope this helps! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a code form a PHP+MySQL book I am reading and I am
I'm not sure what the problem is here, I've inherited some code form Zend
Here is code my jqgrid editing through form. $(#DataEnergy).jqGrid('navGrid', '#pagergrid', {}, //options {editdata: {
Here is the input form code <tr valign=top> <td align=right class=innertablestyle><font class=normal><strong>Homepage</strong></font></td> <td>&nbsp;</td> <td>
Here's my code: if Request.Form(authorize) <> and request.form(delete) <> true then post_ids = Request.form(authorize)
i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
Here is some code on the javascript side for form-based uploads: iframe.setAttribute('src', 'javascript:false;'); I'm
Here is my code: <form id=form1 style=height: 800px; width:1000px > <table style=width: 90%; height:
Here is a code I use : request.jsf <h:form> <!-- form inputs ... -->
Here is my code: <body onload=ccform.submit();> <form id=ccform name=ccform method=post action=https://www.XXXX.com runat=server> <input type=hidden

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.