title: Resetting <f:selectItems/>
body: <p>In my JSF application I have h:selectOneMenu and h:selectOneListBox tags that work perfectly correctly, but I do not know how to reset them back to the first entry, which is the default.</p>
  
  <p>One example of my xhtml code is as follows:</p>
  
  <pre><code>&lt;h:selectOneMenu id="physmenu" value="#{index.physics}" style="height:25px; width:180px;"&gt;   
      &lt;f:selectItems value="#{index.physicsMap}"/&gt;   
  &lt;/h:selectOneMenu&gt;
  </code></pre>
  
  <p>and part of the corresponding bean is:</p>
  
  <pre><code>@ManagedBean(name="index")   
  @SessionScoped  
  public class MyIndexBean implements Serializable {   
      // Other private variables   
      private String itemValue;   
      private String itemLabel;   
      private String physics;   
  
      Map&lt;String,String&gt; physicsMap = new LinkedHashMap&lt;String,String&gt;();
  
      private void initPhysics() {   
          // Loop through data read from an input file   
          // Get itemValue and itemLabel for each line of input read   
  
          physicsMap.put(itemLabel, itemValue); // Store these in physicsMap each time in the loop   
  
          // Other code   
  
          }    
      }   
  
      public Map&lt;String,String&gt; getPhysicsMap() {   
          return physicsMap;   
      }   
  
      // ----- Getter and setter for physics for the index page -----   
  
      public String getPhysics() {   
          return physics;   
      }   
  
      public void setPhysics(String physics) {   
          this.physics = physics;   
      }   
  
      public void resetPhysics(ActionEvent event) {   
          physicsMap.clear();   
      }   
  }  
  </code></pre>
  
  <p>Likewise in a similar way for h:selectOneListBox, and in a couple of places in my Java code I have an array of objects that I created rather than a LinkedHashMap.</p>
  
  <p>As I read in data from a file, I want to keep it in memory and somehow reset the pointer that JSF uses to specify which is the selected item, but I don't know how to access that pointer.  The ActionEvent method at the end just clears the Map, so is of little use.</p>
  
  <p>When a page is first visited the first menu item is displayed, exactly as I want, but if it is changed then the submit button is clicked, then when I revisit the page the new selected value is still displayed and I cannot see how to reset it to the first menu item.  How does JSF keep track of the index pointing to the selected value in the Map displayed on the page, and how do I reset it, or if I so wish, set it to another value programmatically?</p>
  
  <p>This is an issue that has bugged me for some time, and I cannot find a solution.  Many thanks for any help</p>