6 Replies Latest reply on Sep 20, 2008 9:19 PM by Pete Muir

    Simple Conversation example

    Paul Mander Newbie
      I'm trying to do a really basic conversation example with seam. I want to prove that I can integrate seam into existing applications. This is using Seam 1.2.1 under websphere 6.1. I'm just using seam in the webcontainer for now and so don't require any ejb3 stuff. I am also using trinidad...

      I have a bean that is described as follows:

      public class PageBean {

              public void create() {}

              @In(value = "customerService", required = true, create = true)
              private CustomerService service;

              @Out(required = false, scope = ScopeType.CONVERSATION, value="currentCustomer")
              private Customer currentCustomer;

              @In(value = "customerSearch", create = true)
              private CustomerSearch customerSearch;

              public String searchCustomer() throws CustomerException {
                      currentCustomer = service.getCustomer(customerSearch);
                      return null;

      My page is as follows:

                                      <tr:inputText label="Customer Number:"
                                              value="#{customerSearch.customerNumber}" />
                              <tr:commandButton text="Search For Customer"
                                      action="#{myBean.searchCustomer}" />
                              <tr:panelGroupLayout rendered="#{currentCustomer != null}">
                                              action="customer" text="#{currentCustomer.familyName}">

      So basically I search for a customer, a button with the customer's family name is displayed, I click on the button, this then navigates to another page. The other page then just outputs some of the customer's details by referencing #{currentCustomer}.

      Now current customer is not annotated or described as a component but I declare that it is outputted to conversation context. However, the customer page cannot get access to this object.

      What am I doing wrong here?
        • 1. Re: Simple Conversation example
          Andre Eugenio Newbie

          First, is there a reason to use v1.2.1 ? Why not just use the current v 2.0.2 SP1 ?

          Then you need to read a little bit more about how to start a Long Running Conversation and how to propagate them http://docs.jboss.com/seam/2.0.2.SP1/reference/en-US/html/conversations.html#d0e5229


          • 2. Re: Simple Conversation example
            Paul Mander Newbie

            Need to use 1.2.1 as I need to stay within JEE 1.4 and JSF 1.1 all under websphere 6.1. Bringing in 2.x requires a bigger uplight of existing application code. This should all work under 1.2 though...

            From the docs Any faces request (a JSF postback) will propagate the conversation context.. So I shouldn't have to do anything special. It also says that when it encounters a @Begin, any temporary conversations are promoted to long running ones. I still don't know what I'm doing wrong here.

            • 3. Re: Simple Conversation example
              Paul Mander Newbie

              I've changed my example slightly to remove the non-seam components from the mix. I have now got it to work as expected but only when I use an s:link rather than a tr:commandLink.

              Does this mean that I am limited to using s:link and s:button just to maintain a conversation. I am just trying to do simple jsf post back navigation here so I would think that s: components would not be required.

              I've tried tr:commandButton and h:commandButton but only s:button propagates the conversation correctly.

              • 4. Re: Simple Conversation example
                Paul Mander Newbie

                Ok, I've changed my environment to Jboss 4.2.2GA using eclipse and jboss tools. I've eliminated trinidad from stack and updated to seam 2.0.1GA...

                Here's my search page:

                          <h:inputText value="#{accountSearch.accountNumber}" />
                          <h:commandButton id="searchBtn" value="Search"
                               actionListener="#{accountSearch.searchAccount}" />
                          <h:commandButton rendered="#{currentAccount != null}"
                               value="#{currentAccount.number}" />
                          <s:link action="#{accountDetails.viewAccount}"
                               value="#{currentAccount.number}" rendered="#{currentAccount != null}">

                and here the bean that resolves to accountSearch

                public class AccountSearch {
                     @In(create = true)
                     private AccountService accountService;
                     private String accountNumber;
                     @Out(required=false, scope=ScopeType.CONVERSATION)
                     private Account currentAccount;
                     public void searchAccount(ActionEvent event) {
                          currentAccount = accountService.getAccount(accountNumber);
                     public String getAccountNumber() {
                          return accountNumber;
                     public void setAccountNumber(String accountNumber) {
                          this.accountNumber = accountNumber;
                     public Account getCurrentAccount() {
                          return currentAccount;
                     public void setCurrentAccount(Account currentAccount) {
                          this.currentAccount = currentAccount;

                Account details is:

                public class AccountDetails {
                     @In(required=true, value="currentAccount") @Out
                     private Account currentAccount;
                     public String viewAccount() {
                          return "/account.xhtml";

                and the markup is simply

                               <h:outputText value="#{currentAccount.number}" />
                               <h:outputText value="#{currentAccount.name}" />

                If I click on the s:link it works, but if I use the commonButton I get an error telling me that the AccountDetails.currentAccount is a required attribute and is null.

                I must not be getting it at some fundamental error. Are we saying that you can't propagate conversations with commandButtons? If someone can confirm this then I can go back to using flowscope in Trinidad...

                • 5. Re: Simple Conversation example
                  Paul Mander Newbie

                  Have I misunderstood the point of a conversation? In the booking example it states that:

                  Between the @Begin and @End methods, the user can do any number of things with the application (i.e., invoke any event handler method or use the BACK button etc.) and the hotelBooking maintains its state throughout the process.

                  Well hotelBooking maintains its state because it is Stateful - its annotated as @Stateful. It then goes on to explain how these are now linked to tabs etc.

                  I was under the impression that a conversation spanned a number of pages once it had begun. If I were to start a conversation, put an object into that conversation then it would be available for all subsequent pages in regular JSF navigation until the conversation ended.

                  Can someone please correct me...


                  • 6. Re: Simple Conversation example
                    Pete Muir Master

                    This works. See the seamdiscs example for conversations being propagated using <tr:commandButton />.