I need to understand a little bit more what you have now... When you have your <calendar> tag in the JSP, it of course renders HTML on the browser (or are you rendering a link to an ActiveX control or something?).

Where you say:

> Those pure HTML controls work very well with this approach. But how can my custom control work like this?

That makes it sound like to me that you actually are dealing with an ActiveX control. Could you clarify that for me before I try and help any further? I have an answer either way, just want to make sure I'm giving the appropriate one :)

Also, in anticipation of your answer... when the user clicks a date, is your thinking that the page they see should change, i.e., they should move on to another screen, or are you thinking you just want an error message (or no error message if it's a valid date) on the SAME screen?

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


Peter Wu wrote:
Frank W. Zammetti <fzlists <at> omnytex.com> writes:


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.


The Calendar is a GUI one. It displays all the days of a month in a table so
that a user can simply click to select one.


(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).


What I put in the JSP page is like this:

<calendar property="myCalendar" />

I want the Calendar control to collect the selected date and send this
information back to the server.


(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.


Those pure HTML controls work very well with this approach. But how can my
custom control work like this?


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).


The validation for now is just to validate that the user selects a day within
the current week.



Does that help Peter?

Thanks for your quick reply.


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