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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:05:35+00:00 2026-06-02T17:05:35+00:00

This is my fragment: <ui:fragment rendered=#{}> <ui:include src=../includes/top.xhtml/> </ui:fragment> My LoginController will redirect to

  • 0

This is my fragment:

<ui:fragment rendered="#{}">
    <ui:include src="../includes/top.xhtml"/>
</ui:fragment>

My LoginController will redirect to the page home.html that extends MainController that have a boolean method showComponent so when I try to call this mainController.showComponent() I get a nullPointerException because, as I notice, Java loads the html first to see if it is calling any Java Class so when I try to access mainController(that is extended from HomeController, that was not yet called) I get this null pointer

. How to I check inside the fragment if the maisController is set?

Here is what I’ve tried so far

<ui:fragment rendered="#{not empty mainController ? true : false}">

It always returns true.

Here is my MainController class:

package com.erp3.gui.controllers;

import java.io.IOException;
import javax.faces.bean.ManagedBean;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

@ManagedBean
public class MainController {

    public LoginController loginController;
    public ExternalContext ec;

    public void checkUserSession() throws IOException {
        ec = FacesContext.getCurrentInstance().getExternalContext();
        loginController = (LoginController) ec.getSessionMap().get("loginController");
        loginController = (LoginController) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("loginController");
        if (loginController == null || !loginController.getIsLoggedIn()) {
            ec.redirect(ec.getRequestContextPath() + "/views/login.html");
        }
    }

    public Boolean showComponent() {
        return this.loginController.getIsLoggedIn();
    }
}

My method showComponent() is returning a session object property from loginController

  • 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-02T17:05:36+00:00Added an answer on June 2, 2026 at 5:05 pm

    It throws NullPointerException because loginController is apparently null. If it’s another @ManagedBean, then you need to inject it as a manged property. This way you don’t need to manually grab it from the session map. Also, you should give your MainController a valid bean scope. Without a scope, a new one will be created on every single EL expression #{mainController}.

    @ManagedBean
    @RequestScoped
    public class MainController {
    
        @ManagedProperty("#{loginController}") // +getter+setter
        public LoginController loginController;
    
        @PostConstruct // Will be invoked directly after construction and managed property injection.
        public void checkUserSession() throws IOException {
            ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
            if (!loginController.getIsLoggedIn()) {
                ec.redirect(ec.getRequestContextPath() + "/views/login.html");
            }
        }
    
        public boolean isShowComponent() {
            return loginController.getIsLoggedIn();
        }
    
    }
    

    Then you can use it:

    <ui:fragment rendered="#{mainController.showComponent}">
    

    But why don’t you just access #{loginController} directly?

    <ui:fragment rendered="#{loginController.isLoggedIn}">
    

    As to your question why #{not empty mainController ? true : false} always evaluates true is because JSF @ManagedBeans are never null. If one doesn’t exist in EL scope, JSF will autocreate one.

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

Sidebar

Related Questions

I have this fragment that demonstrates the problem: <html> <head> <title>height query demo</title> <script
Say I have this HTML fragment <td width=25% style=text-align:right; > <span style=font-family: Arial; font-size:
so this is a fragment of a procedure that exports a dataset from access
Using this sample : I have make my own Fragment that holds tabhost and
I have this HTML code fragment (in a valid document using strict doctype): <p>Without
There is a webpage containing this fragment of HTML: <div class=a b></div><div class=a></div> .
i'm having a very strange behaviour with this piece of code: <ui:fragment rendered=#{price.guestIdTrue}> <b>PRICE_GUEST_ID_TRUE
I'm trying to make this fragment work: Version History --------------- These are the versions
I have an xml layout for a Fragment (android.support.v4.app.Fragment). When this Fragment is added
In this code fragment, which constructor is actually called? Vector v = getVector(); Vector

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.