title: Ajax Call get null value in backing bean in jsf
body: <p>I have two SelectoneMenu and one inputText. within inputText I called one Ajax event(blur). But this ajax method does not get selected value from SelectoneMenu. But I called the same method using CommandButton it will get selected values and worked fine.</p>
  
  <p>Here is My Code:</p>
  
  <pre><code>&lt;h:form id=HarvestRateForm&gt;
  &lt;table width="670px;"&gt;
                          &lt;tr&gt;
                              &lt;td width="100px;"&gt;&lt;p:outputLabel value="Crushing Season" for="crushingSeason"/&gt;&lt;/td&gt;
                              &lt;td width="80px;"&gt;
                                  &lt;p:selectOneMenu id="crushingSeason" style="width: 110px;" value="#{harvestRateBean.selectedSeason}"&gt;
                                      &lt;f:selectItem itemValue="#{null}" itemLabel="Select"/&gt;
                                      &lt;f:selectItems value="#{harvestRateBean.seasons}"/&gt;
                                  &lt;/p:selectOneMenu&gt;&lt;p:growl for="crushingSeason"/&gt;
                              &lt;/td&gt;
                              &lt;td width="60px;" align="right"&gt;&lt;p:outputLabel value="Plant" for="plant"/&gt;&lt;/td&gt;
                              &lt;td width="80px;"&gt;&lt;p:selectOneMenu id="plant" style="width: 85px;" value="#{harvestRateBean.selectedPlant}"&gt;
                                      &lt;f:selectItem itemValue="#{null}" itemLabel="Select"/&gt;
                                      &lt;f:selectItems value="#{harvestRateBean.plants}"/&gt;
                                  &lt;/p:selectOneMenu&gt;&lt;p:growl for="plant"/&gt;&lt;/td&gt;
                              &lt;td width="60px;" align="right"&gt;&lt;p:outputLabel value="Plot No" for="plotNo"/&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;p:inputText id="plotNo" value="#{harvestRateBean.sapPlotNo}" size="16"&gt; 
                                      &lt;p:ajax event="blur" listener="#{harvestRateBean.loadPlotDetails}"
                                              update="HarvestRateForm:plotNo HarvestRateForm:ryotCode"/&gt;
                                  &lt;/p:inputText&gt;
                                  &lt;p:growl for="plotNo"/&gt;
                              &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
                              &lt;td&gt;&lt;p:outputLabel value="Ryot No" for="ryotCode"/&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;p:inputText value="#{harvestRateBean.ryotNo}" size="15" id="ryotCode" readonly="true" style="background: transparent;background-color: #cccccc"/&gt;&lt;/td&gt;
  </code></pre>
  
  <p></p>
  
  <p></p>
  
  <p>My Bean Class:</p>
  
  <pre><code>public class HarvestRateBean implements Serializable {
  
  private Map&lt;String, String&gt; seasons;
  private Map&lt;String, String&gt; plants;
  private String selectedPlant;
  private String selectedSeason;
  private String sapPlotNo;
  private String ryotNo;
  
  public HarvestRateBean() {
      seasons = new HashMap&lt;String, String&gt;();
      plants = new HashMap&lt;String, String&gt;();
  }
  public Map&lt;String, String&gt; getSeasons() {
      List&lt;Season&gt; season_list = loadSeason();
      for (Iterator&lt;Season&gt; it = season_list.iterator(); it.hasNext();) {
  
          Season season1 = it.next();
  
          seasons.put(season1.getSeason(), season1.getSeason());
      }
      return seasons;
  }
  
  public void setSeasons(Map&lt;String, String&gt; seasons) {
      this.seasons = seasons;
  }
  public List&lt;Season&gt; loadSeason() {
      Session session = HibernateUtil.getSessionFactory().openSession();
      List&lt;Season&gt; seasonlist = null;
      try {
          seasonlist = session.createCriteria(Season.class).list();
      } catch (Exception ex) {
          ex.printStackTrace();
      } finally {
          session.close();
          HibernateUtil.getSessionFactory().close();
      }
      return seasonlist;
  }
  
  public Map&lt;String, String&gt; getPlants() {
      List&lt;Plant&gt; plant_list = loadPlants();
      for (Iterator&lt;Plant&gt; it = plant_list.iterator(); it.hasNext();) {
  
          Plant plant = it.next();
  
          plants.put(plant.getId().getPlant(), plant.getId().getPlant());
      }
      return plants;
  }
  
  public void setPlants(Map&lt;String, String&gt; plants) {
      this.plants = plants;
  }
  
  public List&lt;Plant&gt; loadPlants() {
      Session session = HibernateUtil.getSessionFactory().openSession();
      List&lt;Plant&gt; plantlist = null;
      try {
          plantlist = session.createCriteria(Plant.class).list();
      } catch (Exception ex) {
          ex.printStackTrace();
      } finally {
          session.close();
      }
      return plantlist;
  }
  public String getSelectedPlant() {
      return selectedPlant;
  }
  
  public void setSelectedPlant(String selectedPlant) {
      this.selectedPlant = selectedPlant;
  }
  
  public String getSelectedSeason() {
      return selectedSeason;
  }
  
  public void setSelectedSeason(String selectedSeason) {
      this.selectedSeason = selectedSeason;
  }
  
  public String getSapPlotNo() {
      return sapPlotNo;
  }
  
  public void setSapPlotNo(String sapPlotNo) {
      this.sapPlotNo = sapPlotNo;
  }
  
  public String getRyotNo() {
      return ryotNo;
  }
  
  public void setRyotNo(String ryotNo) {
      this.ryotNo = ryotNo;
  }   
  public void loadPlotDetails {
      Session session = HibernateUtil.getSessionFactory().openSession();
      List&lt;HarvesterRate&gt; rateList = null;
      FacesContext context = FacesContext.getCurrentInstance();
      try {
          if (getSelectedSeason() == null || getSelectedSeason().isEmpty()) {
              context.addMessage(null, new FacesMessage("Season is required", ""));
          } else if (getSelectedPlant() == null || getSelectedPlant().isEmpty()) {
              context.addMessage(null, new FacesMessage("Plant is required", ""));
          } else if (getSapPlotNo() == null || getSapPlotNo().isEmpty()) {
              context.addMessage(null, new FacesMessage("Plot No is required", ""));
          } else {
              rateList = session.createCriteria(HarvesterRate.class).add(Restrictions.eq("id.season", getSelectedSeason())).add(Restrictions.eq("id.plant", getSelectedPlant())).add(Restrictions.eq("id.plotNo", getSapPlotNo())).list();
  
              if (rateList.size() &gt; 0) {
                  for (Iterator&lt;HarvesterRate&gt; it = rateList.iterator(); it.hasNext();) {
                      HarvesterRate harvesterRate = it.next();
          setSapPlotNo(harvestRate.getPlotNo());
          setRyotNo(harvestRate.getVendorCode());
                  }
              }
          }
      } catch (Exception ex) {
          ex.printStackTrace();
      }
  }
  </code></pre>
  
  <p><code>getSelectedSeason()</code> and <code>getSelectedPlant()</code> always return null in <code>ajax</code> Call but I Called same method using <code>CommandButton</code> it return Selected value and everything works fine.</p>