title: JSF/Spring multiple sessions from one page - multi-tab interface
body: <p>I am trying to add multiple-tabs capability to my JSF(facelets)/Spring/ application, something like OpenBravo already has (<a href="http://wiki.openbravo.com/w/images/9/9c/WIK_PartsOfScreen.png" rel="nofollow">http://wiki.openbravo.com/w/images/9/9c/WIK_PartsOfScreen.png</a>, but their app is using different technologies - I guess - pure JavaScript for GUI): each document or report can be opened in separate JavaScript tabs.</p>
  
  <p>Bascially it is simple - each document or report is separate JSF region and only one of them is made visible. Tabs are only visual effect.</p>
  
  <p>The problem is communication with JSF backing beans (or Spring beans that sometimes can be employed in this role). E.e. is is simple for one tab interface: one can create the following bean:</p>
  
  <pre><code>class BankDocumentServiceBean {
      BankDocument selectedDocument;
      Long id;
  
      void setId(Long id) {
          if (selectedDocument.id!=id) {
              setupBankDocument(id);
          }
      }
      void setupBankDocument(Long id) {...}
      BankDocument getBankDocument() {...}
      ...
  }
  </code></pre>
  
  <p>And BankDocument JSF page can be something like this:</p>
  
  <pre><code>...
  &lt;f:metadata&gt; &lt;!-- page is called with parameter id and this code calls setId(...) --&gt;
      &lt;f:viewParam name="id" value="#{bankDocumentServiceBean.id}"/&gt;  
  &lt;/f:metadata&gt;
  
  &lt;h:body&gt;
  ...
      &lt;!-- p for Primefaces --&gt;
      &lt;p:inputText id="amountTxt" 
          value="#{bankDocumentServiceBean.selectedDocument.amount}" 
          required="true" label="amountLbl"/&gt;  
      &lt;p:message for="amountTxt" /&gt;  
      ...
  </code></pre>
  
  <p>Is this approach generally good?</p>
  
  <p>The main question is - how this single-document approach can be extended to multiple tabes. JSF code can be included in the page dynamically, but the service bean remains the problem. Use of additional parameters in each call can be solution - e.g. BankDocumentServiceBean can contain not single BankDocument but List of BankDocuments and each opearation (e.g. getBankDocument) can have additional identifier for selection the right bean from the collection, i.e., the bean that is relevant for the tab with which the user interacts.</p>
  
  <p>But maybe there is some better approach. E.g. maybe one page can be multiple instances of the old good single-document BankDocumentServiceBean. Maybe there are less coarse scopes (JSF scopes and Spring scopes) that are good for tabs, some kind of conversation scope? </p>
  
  <p>Each tab is sitting in its own general panel (div) with its distinct id. Maybe JSF/Spring application can detect that request is coming from distinct panel/div and select instance of BankDocumentServiceBean accordingly?</p>
  
  <p>I guess - solution with List and parameters will work, but maybe there is better architecture for this? Thanks!</p>