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 8716323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:03:10+00:00 2026-06-13T06:03:10+00:00

I have implemented a login form using JSF and PrimeFaces. I used this example

  • 0

I have implemented a login form using JSF and PrimeFaces.
I used this example in the PrimeFaces showcase website.

I have a Facelets page to show a dataTable. Now I need to integrate the above login form with this table page. So I added few lines in to LoginBean.java to handle session attribute.

     if (username.equals(getUsername_db()) && password.equals(getPassword_db())) {//valid user and paward
        loggedIn = true;
        msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", getUsername_db());
        //new lines
        FacesContext context2 = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context2.getExternalContext().getSession(true);
        session.setAttribute("user", username);
        //end of new lines
        ...

I need to hide a column from the dataTable, if the user is not logged in.
Now my problem is, how can I access session attribute inside my Facelets page?

  • 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-13T06:03:11+00:00Added an answer on June 13, 2026 at 6:03 am

    You’ve stored the logged-in user as a session attribute with the name “user”.

    So it’s in EL available as follows:

    #{user}
    

    You can just use the empty keyword in EL to check if it’s present or not (i.e. if it’s logged-in or not) and you can use JSF component’s rendered attribute to instruct whether to generate HTML output or not.

    <h:panelGroup rendered="#{not empty user}">
        <p>Welcome #{user}, you have been logged in!</p>
    </h:panelGroup>
    

    In your specific case of hiding a table column, just use it as follows:

    <p:column rendered="#{not empty user}">
        ...
    </p:column>
    

    A nicer way to store a session attribute is using ExternalContext#getSessionMap(). This way your code is free of smelly javax.servlet.* imports.

    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("user", username);
    

    Unrelated to the concrete problem, why the following check?

    if (username.equals(getUsername_db()) && password.equals(getPassword_db())) {
    

    Why don’t you just do a SELECT ... FROM user WHERE username=? AND password=? in SQL? Or don’t you trust the DB that it returns the right row?

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

Sidebar

Related Questions

On a website I have implemented the login using OpenID (based on StackOverflow). But
I have implemented a registration/login/authentication system using this Django guide . But, how would
I have a login form on the home page of an ASP.NET 3.5 website
Symfony2 and FOS User Bundle issue... I have implemented my own login form in
I have implemented antiforgery token on my login page. Now I had one user
Is there any example on how to implement a simple login page/dialog? I have
I have an example where I am trying to create an AJAX login using
I'm using Spring to handle security in my JSF application. I have a login
I'm putting together a registration/login form in PHP using Netbeans. To implement this, I
I have this code for login validation using a Struts2 action class which calls

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.