<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"> <h:head> <title>CDI Injection</title> <style type="text/css"> .property { width: 15em; text-align: right; font-style: italic; } .value { width: 2em; text-align: right; color: blue; } </style> </h:head> <h:body> <h2>CDI Injection</h2> <h:panelGrid columns="2" columnClasses="property,value"> <h:outputText value="applicationData.counter"/> <h:outputText value="#{applicationData.counter}"/> <h:outputText value="conversationData.counter"/> <h:outputText value="#{conversationData.counter}"/> </h:panelGrid> <p/> <h:form> <h:commandButton value="Increment" action="#{conversationData.increment()}"/> <p> The scope of conversationData##{conversationData.beanID} is #{conversationData.elevated ? 'conversation' : 'request'}. </p> <h:commandButton value="Begin Conversation" rendered="#{!conversationData.elevated}" action="#{conversationData.beginConversation()}"/> <h:commandButton value="End Conversation" rendered="#{conversationData.elevated}" action="#{conversationData.endConversation()}"/> </h:form> </h:body> </html>
The h:panelGrid tag in index.xhtml displays the values of the counter properties of the applicationData and the current conversationData beans. It provides a command button for incrementing the counter properties.
In addition, index.xhtml provides command buttons for controlling the current conversationData bean. Only one of these buttons is shown at a time. Above these buttons, the state of the current conversationData bean is shown. If the current beans has not been elevated to conversation scope then it will be replaced by a new bean in the next request. To distinguish the beans, an automatically incremented identifier is obtained from the applicationData bean.