What you describe is more or less typical... Some points on it:

(1) I don't know what your control looks like or how it is structured, but I'd ask if you really need the hidden inputs? If it's a fully graphical calendar (as mine typically are), then I can see the need, but if by chance you already have input elements that the user uses for instance, it may be redundant.

(2) The usual flow of events in Struts, at least the relevant part of it here, is that your ActionForm object is populated with the request parameters by calling setters that match up with the parameter names (i.e., <input type="hidden" name="year"> will call setYear() in your ActionForm) BEFORE the validate() method is called. Struts does this for you. So, you don't have to read them out of request yourself, just call the appropriate getters (or access the private members directly in validate(), whichever you prefer).

(3) Usually, in your Action Mappings in struts-config.xml, you specify an "input" parameter of a mapping. What happens is that if you return errors from validate(), the request will be sent back to the input page. If no errors are returned, the specifed Action is THEN called. This flow is, generally, what you'd want. Sounds like it would probably suit your needs fine too.

So, in short, what you describe is basically what you probably want to do, however... the validate() method is *usually* used to catch things like mandatory fields not filled in, or a from date falling after a to date, in simpler terms, things that aren't really consider "business rules". You didn't specify in what way you'd validate the entered M/D/Y, and technically you can do anything you want in validate(), even access a database if you want... but from an architectural standpoin, you probably want to think about what the validation is... if it's something you'd consider a "business rule" (i.e., entered M/D/Y cannot be before January, 2003 for company A, and not before December, 2004 for company B), then you most likely don't want to handle it in validate(), instead handle it in an Action and just have a <forward> element that returns to your input page (or a separate error page if more applicable).

Does that help Peter?

--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

Peter Wu wrote:
Hi,

I'm new to Struts and have been working on ASP.NET for a while.

I'm in the middle of creating my first tag, a Calendar tag, which provides a UI
for end users to pick up a date. This control works well in a JSP page.

I want the year, month and day selected by an end user to be posted back to the
server so that I can do some validation before the page is redirected to the
Action page.

Here is what I am thinking of doing now: 1. Have the tag create 3 hidden inputs in the HTML code 2. Submit the form
3. Read the values passed from the Request
4. Process the validation and return respective results


I think the above method is not a good approach.

I notice that in the validate() method of the ActionForm, we can validate the
inputs from various HTML inputs, like textbox, options, etc.


My question is: Can I code my Calendar control in such a way that I can use the
validate() method of the ActionForm class to validate the YEAR, MONTH and DAY
selected by an end user? If no, how can I validate the Calendar input?

Thanks in advance!
Peter


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]









---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to