I have a two components: TabSet and Tab. TabSet retrieves the user who is currently logged in (if the user has logged in) from acegi, does some processing and makes it available to nested components via the environmental service:
void beginRender() { if (loggedUser == null) return; // process user environment.push(User.class, loggedUser); } void afterRender() { if (environment.peek(User.class) != null) environment.pop(User.class); } The Tab uses this value to work out whether it should render itself: @Environmental private User loggedUser; boolean setupRender() { if (loggedUser != null) // check if the user should see this tab } This all works nicely assuming the user has logged in, but if there is no User object on the environment stack it all falls over. The line if (loggedUser != null) causes T5 to throw an exception because no User object is on the stack. So my question is what is the best way to handle a situation in which an Environmental object could be null? I was thinking I may have to inject the environment service into the Tab component and peek at the stack like I do in TabSet.afterRender() but this seems a little messy. Thanks Toby