Re: Struts 2.0.6 and Validation
Now it works. Thanks a lot. > @ExpressionValidator(expression="(searchParam.keywords > != '') && (searchParam.location != '')", message="Need > keywords and location.") I think there were several problems. First of all my OGNL syntax. I believe the documentation regarding this topic is a little poor. I would like to see more real world examples. The other essential piece of information I was missing was : > If validation fails the framework will try to bring > you back to the "input" result. You don't appear to > have one; this will cause a problem. I was suspecting something like this, but did not know that the result in case of an validation error is "input". I think the onlines guides for annotations should definitely have examples for this. Anyway, thanks for the help. --Hardy - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts 2.0.6 and Validation
--- Hardy Ferentschik wrote: > @Validations( > expressions = { > @ExpressionValidator( > expression = > "searchParam.keywords ne null and > searchParam.location ne null" message > = "Wrong search parameters") > } Btw, I haven't tested this yet, but I suspect you wouldn't want 'null' anyway, because empty string params will come in as... well, empty strings, not null. @ExpressionValidator(expression="(searchParam.keywords != '') && (searchParam.location != '')", message="Need keywords and location.") worked for me. I still wouldn't do it this way, as it's adding an action-level msg (rather than highlighting the particular field that's missing), but that's a matter of preference and/or requirements. d. Food fight? Enjoy some healthy debate in the Yahoo! Answers Food & Drink Q&A. http://answers.yahoo.com/dir/?link=list&sid=396545367 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts 2.0.6 and Validation
--- Hardy Ferentschik wrote: > Currently I get the following error: > No result defined for action SearchAction and result > input If validation fails the framework will try to bring you back to the "input" result. You don't appear to have one; this will cause a problem. > 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? You can do what you're doing. In this case I'm not sure what you're gaining by using the SearchParam object, but without knowing why you've chosen that way, it's hard to say. > I also tried to apply the ExpressionValidator > annotation directly on setSearchParam method, > but then I got the following error message: > > >>> > caught OgnlException while setting property > 'methodName' [...] methodName? I'm not sure why that's happening; the actual annotation you used might be helpful. d. Get your own web address. Have a HUGE year through Yahoo! Small Business. http://smallbusiness.yahoo.com/domains/?p=BESTDEAL - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Struts 2.0.6 and Validation
Hi there, 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 = [EMAIL PROTECTED](expression = "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. Currently I get the following error: >>> No result defined for action SearchAction and result input No result defined for action SearchAction and result input at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:345) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at >>> 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: >>> caught OgnlException while setting property 'methodName' on type ' com.opensymphony.xwork2.validator.validators.ExpressionValidator'. ognl.NoSuchPropertyException: com.opensymphony.xwork2.validator.validators.ExpressionValidator.methodName >>> Any help is greatly appreciated. --Hardy - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]