I recently started working on JSP, and I was going through the tutorials on creating simple tag handlers for validating custom tags. I came across this code snippet and when I tried to run it, I am getting the same error over and over again. I asks me to change the return type first, and then it tell that the new return type is incompatible with the method being overridden. Thing is, I just copied the code from docs.oracle.com
http://docs.oracle.com/javaee/5/tutorial/doc/bnann.html
Can anyone tell what's wrong here ?
EDIT : I have now added the imports and the error message.
import javax.servlet.jsp.tagext.TagData;
import javax.servlet.jsp.tagext.TagExtraInfo;
import javax.servlet.jsp.tagext.ValidationMessage;
public class TwaTEI extends TagExtraInfo {
public ValidationMessage[] validate(TagData data) {
Object o = data.getAttribute("attr1");
if (o != null && o != TagData.REQUEST_TIME_VALUE) {
if (((String)o).toLowerCase().equals("true") ||
((String)o).toLowerCase().equals("false") )
return null;
else
return new ValidationMessage(data.getId(),
"Invalid boolean value.");
}
else
return null;
}
}
ERROR
Type mismatch: cannot convert from ValidationMessage to ValidationMessage[].
This part is invalid, you should return an array of ValidationMessage objects:
return new ValidationMessage(data.getId(),
"Invalid boolean value.");
Like this:
return new ValidationMessage[]{new ValidationMessage(data.getId(),
"Invalid boolean value.")};