You need to separate the concepts of Facelets (view / template technology) and JSF (component-based MVC infrastructure). What you want is not possible with single Facelets, as Facelets ui tags are exclusively server-side and do not produce anything on the client side. You need to add the JSF component (which is generated at the end of the HTML), which can be hosted by client-side JS / Ajax.
template.xhtml
<h:panelGroup layout="block" id="content"> <ui:insert name="content_homepage">Box Content Here</ui:insert> </h:panelGroup>
( layout="block" makes it <div> instead of <span> )
Button index.html :
<h:commandButton value="Login" action="#{login.checkLogin}"> <f:ajax execute="@form" render=":content" /> </h:commandButton>
( :content refers to <h:panelGroup id="content"> , which is at the top level :
Definition of the content template index.html :
<ui:define name="content_homepage"> <h:panelGroup rendered="#{!login.loggedIn}"> User is not logged in. </h:panelGroup> <h:panelGroup rendered="#{login.loggedIn}"> User is logged in. </h:panelGroup> </ui:define>
Managed bean:
private String name; // Do NOT initialize with empty string! Poor practice. // ... public boolean isLoggedIn() { // Boolean getter methods should be prefixed with `is`. return name != null; // Do NOT add if/else verbosity for something which already returns boolean! Poor practice. }
Also, do not use spacing as labels. This is bad HTML semantics. Use <h:outputLabel> (or plain HTML <label> ).
source share