Thursday, January 27, 2011

Struts2 Select Box Error.

I believe you faced this error thats why you are here for the solution.
Instead of wasting our time straightly we will go to the solution.

struts.xml

  /jsp/selectBox.jsp  


SelectList.java
package com.demo.actions;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
public class SelectList extends ActionSupport{
private ArrayList dayList;
public String execute() throws Exception {
//instantiate the Arraylist here
dayList = new ArrayList();
dayList.add("monday");
dayList.add("tuesday");
...
dayList.add("sunday");
return SUCCESS;
}
//Make sure you have created the getter and setter method for ArrayList
public ArrayList getDayList() {
  return dayList;
 }
public void setDayList(ArrayList dayList) {
  this.dayList= dayList;
 }
}
selectBox.jsp
Thats it your code will work like a charm.
Do post your comments and for more java programming click this Link.