Version 2

    Contextual conversations

     

    Seam can maintain multiple conversations with the same user. Each conversation has its own set of states and is independent of other conversations. In this sample application, you can use the "New Workspace" link to create a new contextual conversation. As you move between conversations, you can see that Seam remembers the state for each one.

     

    As we have seen before, the hotel search action (find() method) starts the conversation in the stateful HotelBookingAction bean.

     @Stateful
     @Name("hotelBooking")
     @Interceptor(SeamInterceptor.class)
     @Conversational(ifNotBegunOutcome="main")
     @LoggedIn
     public class HotelBookingAction implements HotelBooking, Serializable {
     
      // ... ...
      
      @Begin
      public String find() {
        // ... ...
      }
     }
    

    To start another conversation, you simply load the main.xhtml page, which invokes the above code. You can load main.xhtml either in the current window or in a new browser window / tab. The result is that a new conversation is initiated and all the available conversations are stored in a Seam built-in component named . You can retrieve information about each workspace, including the link to make it current, from entries in the component. The code snippet in the conversations.xhtml file, which displays all available conversations for this user, is as follows.

     <h:dataTable value="#{conversationList}" var="entry">
      <h:column>
        <h:commandLink action="#{entry.select}" value="#{entry.description}"></h:commandLink>
         
        <h:outputText value="[current]" rendered="#{entry.current}"></h:outputText>
      </h:column>
      <h:column>
        <h:outputText value="#{entry.startDatetime}">
          <f:convertDateTime type="time" pattern="hh:mm"></f:convertDateTime>
        </h:outputText>
        -
        <h:outputText value="#{entry.lastDatetime}">
          <f:convertDateTime type="time" pattern="hh:mm"></f:convertDateTime>
        </h:outputText>
      </h:column>
     </h:dataTable>
    

    However, for the above code to work, you have to specify the {entry.description} for each page in the conversation. This is done in the pages.xml file in the WEB-INF directory in the .war archive. Below is the pages.xml for the booking example.

     <pages>
      <page view-id="/main.xhtml" timeout="300000">
        Search hotels: #{hotelBooking.searchString}
      </page>
      <page view-id="/hotel.xhtml" timeout="300000">
        View hotel: #{hotel.name}
      </page>
      <page view-id="/book.xhtml" timeout="600000">
        Book hotel: #{hotel.name}
      </page>
      <page view-id="/confirm.xhtml" timeout="600000">
        Confirm: #{booking.description}
      </page>
     </pages>
    

    Note that you do not need the pages.xml file if you do not provide workspace switching functionalities in your application.