I am trying to get validation going for my application and so far nothing works. I would like to use annotations. Here is what I try to do:
package ... import ...
@Results({ @Result(name = "success", value = "/jsp/hitlist.jsp"), // value = "hitlist.action", type = ServletActionRedirectResult.class), @Result(name = "error", value = "/jsp/index.jsp") }) @ParentPackage("default") @Validation() public class SearchAction extends ActionSupport { private SearchParam searchParam;
@Validations( expressions = {@(protected) = "searchParam.keywords ne null and searchParam.location ne null" message = "Wrong search parameters") } ) public String search() { // do search return SUCCESS; }
public SearchParam getSearchParam() { return searchParam; }
public void setSearchParam(SearchParam searchParam) { this.searchParam = searchParam; } }
SearchParam is class containing two properties keywords and location (with matching getter and setters). When I run the application without any annotation it works fine. What I mean is that the keywords and locations field get properly passed into action. The problem starts with validation.
Can anyone see what I am doing wrong? Is it actually possible to have validation on 'complex' datatypes as I am trying to do with SearchParam? Or do I need keywords and locations as simple String properties in the Action directly?
I also tried to apply the ExpressionValidator annotation directly on setSearchParam method, but then I got the following error message:
--------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@(protected) For additional commands, e-mail: user-help@(protected)