struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Newton <newton.d...@yahoo.com>
Subject Re: RequiredString Validation doesn't work and AbstractValidationActionSupport is missing?
Date Mon, 25 May 2009 20:56:50 GMT
Niklas Johansson wrote:
> I want to use Requieredstring validator. The problem is that my
> application is not complaining if I do leave the input field empty.

Are you using the default interceptor stack?

> Can anyone tell me what is the problem?

I don't see anything immediately obvious, but I'm sleepy.

> Q: "why you're using ParameterAware" ... "it's generally cleaner to
> just use the action properties"
> 
> A: The reason is because I found the instructions on the struts
> homepage. Using the action properties, I assume I need to define those
> in the struts.xml, correct?

Define what in the struts.xml? The "struts homepage" doesn't have 
instructions for doing *anything*, so you'll have to be more specific as 
to what you were reading so we can correct it.

The probable answer to your question is "no". One of the main features 
(IMO) of S2 is that it eliminates a lot of back-and-forth between HTML 
forms and actions, meaning your code could be written follows, getters 
and setters elided. (And why make the action properties public if you 
have getters/setters for them?)

public class RegisterQAFormAction extends ActionSupport {

     private String message;
     private String heading;

     public String execute() throws Exception {
         System.out.println(heading);
         System.out.println(answer);

         // Don't know what this is trying to do, so ignoring.
         //QAHandler handleQA = new QAHandler();
         //handleQA.storeQA(param);

         setMessage("Ă„rende " + heading + " registrerat");
         if (getHeading() == null) {
             return ERROR;
         }

         return SUCCESS;
     }

}

Note that heading won't be null if the user doesn't enter a value--it 
will be an empty string, so in all probability this is a bug in your code.

> Q: "That class is part of the showcase app, not part of Struts itself."
> 
> A: So what is the solution? The instructions wasn't that clear about
> where the class came from on the instruction page:
> http://struts.apache.org/2.1.6/docs/using-field-validators.html

Solution to what problem? You don't need that class to use the 
validation as you've written it above.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message