|
public static class NameBean extends FormData
{
private String name;
private String type;
public void setType(String type)
{
this.type = type;
}
public String getType()
{
return this.type;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return this.name;
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
{
ActionErrorserrors = new ActionErrors();
if (name == null || name.equals("")) {
errors.add("nameError",
new ActionError("NullNameError"));
}
else {
if (!Character.isUpperCase(name.charAt(0))) {
errors.add("nameError",
new ActionError("UpperCaseNameError",name));
}
}
if (type == null || (!type.equals("bar") &&
!type.equals("foo"))) {
errors.add("typeError",
new ActionError("TypeError",type));
}
if (!errors.empty()) {
request.setAttribute("errorNotSet",new Boolean(false));
}
return errors;
}
} |