title: Using <f:view> on the template page in JSF
body: <p>I have a DataTable (Primefaces 3.5, JSF 2.0) which is populated from a database. In the first column of this table, checkboxes are displayed (multiple row selection).</p>
  
  <p>After selecting row(s), when a button (<code>&lt;p:commandButton&gt;</code>) is pressed, the selected rows are expected to be deleted from the database.</p>
  
  <p>Before deleting row(s), a confirm message regarding the deletion of the selected row(s) is displayed in <code>&lt;p:confirmDialog&gt;</code> with two buttons <em>Yes</em> and <em>No</em> something like the following.</p>
  
  <p>Test.xhtml:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;ui:composition template="template/Template.xhtml"
                  xmlns="http://www.w3.org/1999/xhtml"
                  xmlns:h="http://java.sun.com/jsf/html"
                  xmlns:ui="http://java.sun.com/jsf/facelets"
                  xmlns:p="http://primefaces.org/ui"
                  xmlns:f="http://java.sun.com/jsf/core"
                  xmlns:c="http://java.sun.com/jsp/jstl/core"&gt;
  
      &lt;ui:define name="title"&gt;Test&lt;/ui:define&gt;
      &lt;ui:define name="content"&gt;
  
              &lt;h:form id="form"&gt;
                  &lt;p:dataTable id="dataTable" var="row" value="#{testManagedBean.list}"
                               selection="#{testManagedBean.selectedValues}"
                               rowKey="#{row.id}"
                               rowIndexVar="rowIndex"&gt;
  
                      &lt;p:column selectionMode="multiple" style="width:5%; text-align: center;"&gt;
                          &lt;f:facet name="footer"&gt;
  ----------------&gt;           &lt;p:commandButton actionListener="#{testManagedBean.deleteMultipleActionListener}" oncomplete="confirmDeleteMultiple.show()" update=":form:confirmDialogDeleteMultiple" process=":form:dataTable" icon="ui-icon ui-icon-close"/&gt;
                          &lt;/f:facet&gt;
                      &lt;/p:column&gt;                    
  
                      &lt;p:column headerText="Index"&gt;
                          &lt;h:outputText value="#{rowIndex+1}"/&gt;
                      &lt;/p:column&gt;
  
                      &lt;p:column id="id" headerText="Id"&gt;
                          &lt;h:outputText value="#{row.id}"/&gt;
                      &lt;/p:column&gt;
  
                      &lt;p:column id="countryName" headerText="Description"&gt;
                          &lt;h:outputText value="#{row.description}"/&gt;                        
                      &lt;/p:column&gt;                    
                  &lt;/p:dataTable&gt;                
  
  ---------------&gt;&lt;p:confirmDialog id="confirmDialogDeleteMultiple" widgetVar="confirmDeleteMultiple" appendToBody="true" message="Delete row(s)?" showEffect="true" hideEffect="true" header="Deletion of row." severity="alert" closeOnEscape="true" closable="true"&gt;
                      &lt;p:commandButton id="confirmDeleteMultiple" value="Yes" oncomplete="confirmDeleteMultiple.hide()" actionListener="#{testManagedBean.deleteMultiple}" process="@this dataTable" update="dataTable"/&gt;
                      &lt;p:commandButton id="declineDeleteMultiple" value="No" onclick="confirmDeleteMultiple.hide()" type="button" /&gt;
                  &lt;/p:confirmDialog&gt;
              &lt;/h:form&gt;
          &lt;/ui:define&gt;
  &lt;/ui:composition&gt;
  </code></pre>
  
  <p>The managed bean:</p>
  
  <pre><code>@ManagedBean
  @ViewScoped
  public final class TestManagedBean implements Serializable
  {
      @EJB(mappedName="ejb/JNDI")
      private TestService testService;
      private List&lt;Test&gt; list;
      private List&lt;Test&gt;selectedValues;
  
      public TestManagedBean(){}
  
      @PostConstruct
      public void init()
      {
          list=testService.getList();
      }
  
      public List&lt;Test&gt; getList() {
          return list;
      }
  
      public List&lt;Test&gt; getSelectedValues() {
          return selectedValues;
      }
  
      public void setSelectedValues(List&lt;Test&gt; selectedValues) {
          this.selectedValues = selectedValues;
      }
  
      public void deleteMultipleActionListener(ActionEvent actionEvent)
      {
          //Just show a warning message, when the delete button is pressed.
  
          for(Test test:selectedValues)
          {
              System.out.println(test.getId()+" : "+test.getDescription());
          }//Displays the list.
      }
  
      public void deleteMultiple(ActionEvent actionEvent)
      {
          System.out.println("multiple");
          for(Test test:selectedValues)
          {
              System.out.println(test.getId()+" : "+test.getDescription());
          }//The list is not null and empty.
      }
  }
  </code></pre>
  
  <p>When the button (indicated by an arrow in XHTML) is pressed, the <code>deleteMultipleActionListener()</code> method in the managed bean is invoked where it simply displays the list which is populated by <strong>the selected rows</strong> and the confirm dialog as shown in XHTML appears afterwards. (This is just to show a warning message before deletion. The loop in this method is just for the demonstration).</p>
  
  <p>When the <em>Yes</em> button on the confirm dialog is pressed, the <code>deleteMultiple()</code> method is invoked which is responsible for actual deletion of rows (<code>actionListioner</code> in <code>&lt;p:commandButton&gt;</code> inside <code>&lt;p:confirmDialog&gt;</code>) and the deletion of rows should be performed but here the list of the selected rows retrieved here is empty (not null). </p>
  
  <hr>
  
  <p>The resulting list inside the <code>deleteMultiple()</code> method is empty because of <code>&lt;f:view&gt;</code> on the template page. The template page is shown below.</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html lang="#{localeBean.language}"
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:f="http://java.sun.com/jsf/core"&gt;
  
  ---------&gt;
      &lt;f:view locale="#{localeBean.locale}" encoding="UTF-8" contentType="text/html"&gt;
          &lt;f:loadBundle basename="messages.ResourceBundle" var="messages"/&gt;
  
          &lt;h:head&gt;&lt;title&gt;&lt;ui:insert name="title"&gt;Default Title&lt;/ui:insert&gt;&lt;/title&gt;&lt;/h:head&gt;
  
      &lt;h:body&gt;
          &lt;p:layout fullPage="true"&gt;
              &lt;p:layoutUnit position="north" size="135" collapsed="false" resizable="false" closable="false" collapsible="false" gutter="6"&gt;
  
                  &lt;h:form&gt;
                      &lt;h:selectOneMenu id="languages" value="#{localeBean.language}" onchange="submit();" style="position: absolute; right: 0; top: 50px;"&gt;
                          &lt;f:selectItem itemValue="en" itemLabel="English" /&gt;
                          &lt;f:selectItem itemValue="hi" itemLabel="Hindi" /&gt;
                      &lt;/h:selectOneMenu&gt;
                  &lt;/h:form&gt;
              &lt;/p:layoutUnit&gt;
  
              &lt;p:layoutUnit position="west" id="leftPanel" size="225" header="Menu Item" resizable="false" closable="false" collapsible="true" gutter="6"&gt;
  
              &lt;/p:layoutUnit&gt;
  
              &lt;p:layoutUnit position="center" size="2500" maxSize="2500"&gt;
                      &lt;ui:insert name="content"&gt;Put default content here, if any.&lt;/ui:insert&gt;
                  &lt;/p:layoutUnit&gt;
              &lt;/p:layout&gt;
  
          &lt;/h:body&gt;
      &lt;/f:view&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I remove this template from the above <code>Test.xhtml</code> page and <strong>use this <code>&lt;f:view&gt;</code> tag on the <code>Test.xhtml</code> page itself</strong>, everything works fine and the list of the selected rows inside the <code>deleteMultiple()</code> method is obtained correctly.</p>
  
  <p>So, what is going wrong? Why does the list become empty when the <em>Yes</em> button is pressed, if the template page is enclosed by <code>&lt;f:view&gt;</code>? Is it wrong? How to accomplish this? (<code>&lt;f:view&gt;</code> is used for the localization of the application as it can be imagined).</p>