We are now going to add code to the morecomponents.xhtml
page, which allows us to switch themes without using the ThemeSwitcher component. We are going to add them at the end because the code needs to be explained so that you have a clear understanding of how this is done. I chose commandButton
for the task, but we just as easily could have used other components that support the action
attribute and have the ability to cause the page to be requested in full or allow us to update the entire page using an AJAX request.
Here is the code that we need to add immediately after the form
tag with id="mainform"
:
<p:panelGrid columns="3"> <p:column> <p:commandButton ajax="false" value="Switch to Aristo" actionListener="#{currentTheme.setTheme('aristo')}"/> </p:column> <p:column> <p:commandButton ajax="false" value="Switch to Afterwork" actionListener="#{currentTheme.setTheme('afterwork')}...