1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| package pack1;
import java.util.Iterator;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.ws.Response;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
public class AddLeagueForm extends ActionForm {
private String season = null;
private String title = null;
private String yearStr = null;
private int year;
public int getYear() {
return year;
}
public String getSeason() {
return season;
}
public void setSeason(String season) {
this.season = season;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getYearStr() {
return yearStr;
}
public void setYearStr(String yearStr) {
this.yearStr = yearStr;
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();
try {
year = Integer.parseInt(yearStr);
} catch (NumberFormatException nfe) {
errors.add("yearStr", new ActionMessage("error.yearField.required"));
}
if ( (year != -1) && ((year < 2000) || (year > 2010)) ) {
errors.add("yearStr", new ActionMessage("error.yearField.range"));
}
if ( season.equals("unknown") ) {
errors.add("season", new ActionMessage("error.seasonField.range"));
}
if ( title.length() == 0 ) {
errors.add("title", new ActionMessage("error.titleField.required"));
}
return errors;
}
} |