title: JSF EL condition
body: <p>This is my fragment:</p>
  
  <pre><code>&lt;ui:fragment rendered="#{}"&gt;
      &lt;ui:include src="../includes/top.xhtml"/&gt;
  &lt;/ui:fragment&gt;
  </code></pre>
  
  <p>My <strong>LoginController</strong> will redirect to the page <strong>home.html</strong> that extends <strong>MainController</strong> that have a boolean method <code>showComponent</code> so when I try to call this <code>mainController.showComponent()</code> I get a <code>nullPointerException</code> because, as I notice, Java loads the html first to see if it is calling any Java Class so when I try to access <code>mainController</code>(that is extended from HomeController, that was not yet called) I get this null pointer</p>
  
  <p>. How to I check inside the fragment if the maisController is set?</p>
  
  <p>Here is what I've tried so far</p>
  
  <p><code>&lt;ui:fragment rendered="#{not empty mainController ? true : false}"&gt;</code></p>
  
  <p>It always returns <code>true</code>.</p>
  
  <p>Here is my MainController class:</p>
  
  <pre><code>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();
      }
  }
  </code></pre>
  
  <p>My method <code>showComponent()</code> is returning a session object property from <code>loginController</code></p>