title: How to call action after selecting values from dynamically created dropdown list using struts2
body: <p>Here I have created dynamic dropdown list using this <a href="http://www.ibm.com/developerworks/library/wa-dynamicstruts/" rel="nofollow noreferrer">link</a>, but when I select some value from available list it should be called in action class.
  The dropdown list which can be seen in the image ,here the values are loaded dynamically from the database and now what I want is when I select any value from that two dropdown list that values (I mean text value) should be sent to the action class and there I will execute one JDBC select query on the basis of this two values and will display in the table shown in the image but everything should be on load.Action should be on selecting values from dropdown list not on any button click .With static values I am able to call value from dropdown list into action class with <code>name</code> attribute.But in this case I cannot :(<br>
  I hope I am clear now .  </p>
  
  <p><a href="https://i.stack.imgur.com/ySgr8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ySgr8.png" alt="Screenshot"></a></p>
  
  <p>I have tried calling select tag using listkey,name and id but none of them worked .<br>
  Below is my JSP code:  </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;div&gt;
      &lt;div class="invoicetext1"&gt;Event Name :&lt;/div&gt;
          &amp;nbsp;&amp;nbsp;
          &lt;s:select name="dp.eventState" 
                    list="%{state}" 
                   class="billlistbox1" 
                      id="eventName" /&gt;   
          &lt;div&gt;
              &lt;s:select name="dp.companyState" 
                       class="billlistbox2"
                     listKey="companyState" 
                        list="%{status}"&gt;
              &lt;/s:select&gt;
          &lt;/div&gt;
          &lt;div class="invoicetext2"&gt;Company Name :&lt;/div&gt;
          &lt;div class="clear"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;s:form action="ActionSelect"&gt;
          &lt;s:submit value=" Click Here"/&gt;
      &lt;/s:form&gt;
  &lt;div&gt;
  </code></pre>
  
  <p>Action class for loading dynamic dropdown list :  </p>
  
  <pre><code>package com.ca.actions;
  
  import java.sql.Connection;
  import java.sql.ResultSet;
  import java.util.ArrayList;
  import java.util.List;
  
  import com.ca.database.Database;
  import com.ca.pojo.Event;
  import java.sql.PreparedStatement;
  import com.opensymphony.xwork2.ActionSupport;
  
  public class RetrieveEvNaCoNaAction extends ActionSupport {
  
      private static final long serialVersionUID = -5418233715172672477L;
      List&lt;Event&gt; dataForBillsJspList;
      private List state = new ArrayList();
      private List status = new ArrayList();
      String eventName;
  
  
      public String getEventName() {
          return eventName;
      }
  
      public void setEventName(String eventName) {
          this.eventName = eventName;
      }
  
      public RetrieveEvNaCoNaAction() {
          // TODO Auto-generated constructor stub
      }
  
      public List&lt;Event&gt; getDataForBillsJspList() {
          return dataForBillsJspList;
      }
  
      public void setDataForBillsJspList(List&lt;Event&gt; dataForBillsJspList) {
          this.dataForBillsJspList = dataForBillsJspList;
      }
  
  
      public List getStatus() {
          return status;
      }
  
      public void setStatus(List status) {
          try {
              Database database = new Database();
              Connection con = database.Get_Connection();
  
              PreparedStatement ps = con
                      .prepareStatement("SELECT EVENT_NAME,COMPANY_NAME,date_format(FROM_DATE,'%d/%m/%Y') as dateAsFrom,date_format(TO_DATE,'%d/%m/%Y') as dateAsTo FROM EVENT");
              ResultSet rs = ps.executeQuery();
              //dataForBillsJspList = new ArrayList&lt;Event&gt;();
              while (rs.next()) {
                  /*dataForBillsJspList.add(new Event(rs.getString("EVENT_NAME"),
                          rs.getString("COMPANY_NAME"), rs
                                  .getString("dateAsFrom"), rs
                                  .getString("dateAsTo")));
                  System.out.println(rs.getString("EVENT_NAME"));*/
                  status.add(rs.getString("COMPANY_NAME")); 
  
              }
              System.out.println("Data Collected ...");
          }catch(Exception e)
          {
              e.printStackTrace();
          }
  
      }
  
      public List getState() {
          return state;
      }
  
      @Override
      public String execute() throws Exception {
          // TODO Auto-generated method stub
                      setState(this.state);
                      setStatus(this.status);
          return "success";
      }
      public String showEventDetails(){
          System.out.println("Hi.."+eventName);
          return SUCCESS;
      }
      public void setState(List state) {
          //implement the application specific logic to 
          try {
              Database database = new Database();
              Connection con = database.Get_Connection();
  
              PreparedStatement ps = con
                      .prepareStatement("SELECT EVENT_ID,EVENT_NAME,COMPANY_NAME,CONTACT_PERSON,CONTACT_NO,EMAIL_ID,EVENT_VENUE,date_format(FROM_DATE,'%d/%m/%Y') as dateAsFrom,date_format(TO_DATE,'%d/%m/%Y') as dateAsTo ,EVENT_TIME FROM EVENT");
              ResultSet rs = ps.executeQuery();
              dataForBillsJspList = new ArrayList&lt;Event&gt;();
              while (rs.next()) {
                  dataForBillsJspList.add(new Event(rs.getString("EVENT_ID"),rs.getString("EVENT_NAME"),
                          rs.getString("COMPANY_NAME"),rs.getString("CONTACT_PERSON"),rs.getString("CONTACT_NO"),rs.getString("EMAIL_ID"),rs.getString("EVENT_VENUE"), rs
                                  .getString("dateAsFrom"), rs
                                  .getString("dateAsTo"),rs.getString("EVENT_TIME")));
                  //System.out.println(rs.getString("EVENT_NAME"));
                  state.add(rs.getString("EVENT_NAME")); 
                  System.out.println(rs.getString("EVENT_ID"));
              }
              System.out.println("Data Collected ...");
          }catch(Exception e)
          {
              e.printStackTrace();
          }
          //Here for displaying the data on UI, we are using few hardcoded values//
                  }
  }
  </code></pre>
  
  <p>After loading dynamic dropdown list now i am trying to call selected value in action class by S.O.P but it gives null pointer exception. Below is my POJO class:  </p>
  
  <pre><code>package com.ca.pojo;
  
  public class Dropdown 
  {
      private String eventState;
      private String companyState;
      public Dropdown() {
          // TODO Auto-generated constructor stub
      }
      public String getEventState() {
          return eventState;
      }
      public void setEventState(String eventState) {
          this.eventState = eventState;
      }
      public String getCompanyState() {
          return companyState;
      }
      public void setCompanyState(String companyState) {
          this.companyState = companyState;
      }
  
  
  }  
  </code></pre>
  
  <p>and below is action class where I am trying to call that selected value by using name attribute :  </p>
  
  <pre><code>package com.ca.actions;
  
  import com.ca.pojo.Dropdown;
  import com.opensymphony.xwork2.ActionSupport;
  
  public class DropdownAction extends ActionSupport 
  {
      Dropdown dp;
      public DropdownAction() {
          // TODO Auto-generated constructor stub
      }
      public Dropdown getDp() {
          return dp;
      }
      public void setDp(Dropdown dp) {
          this.dp = dp;
      }
      @Override
      public String execute() throws Exception {
          // TODO Auto-generated method stub
          System.out.println(dp.getEventState());
          return "success";
      }
  
  
  }  
  </code></pre>
  
  <p>struts.xml is properly configured. Now after selecting two values I want to display data in the below table accordingly without any button click but in jsp i have created button just to see whether i am getting the selected value in action class but in actual i want it without any button click.</p>