Dave, it sounds like you are trying to over complicate things some.
I am using the methodology where I create a bean and this becomes my model,
and this is extremely easy in ColdFusion 9 with the accessors annotation. So
to make it very clear I personally would be looking at either passing the
event into the service, or using the DI to get the RC. From here you can the
pull up your model (bean) and apply the validation using hyrule for your
form.
That has got to be the simplest approach.
As for radio buttons, if you follow the rule when retrieving this
information and use event.getValue('myRadioButton','') then this will make
it default to empty or whatever you want in the second argument.
Is this along the lines that you are thinking?
Regards,
Andrew Scott
http://www.andyscott.id.au/
From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Dave Merrill
Sent: Saturday, 11 September 2010 2:06 PM
To: ColdBox Platform
Subject: [coldbox:5746] Re: MVC and separation of concerns question
@John and Judah:
I think there's been a misunderstanding about my example. There is no
meeting involved here, or to the extent that there's anything like that,
it's
not what I was referring to that has a startDate and endDate. It's a
calendar
with user-selectable start and end dates, and other fields that filter the
events being displayed on the calendar.
The revelation for me was that it may well make sense to encapsulate the
state of those form fields as a bean, even though they _don't_ represent
an
actual business object like a meeting or a person, just UI state. I've
never
considered that possibility before, but it neatly handles both default
values
and custom formatting or other behaviors of those fields, and also
provides a
single collection that can be passed to a search form renderer. I've
actually
done something kind of similar in js now that I think about it, but not on
the
server side.
I'm pretty comfortable with this, at least as far as the ideas behind it;
I'll see
how I feel when I actually get time to code it up.
So here's my next level question: When the user submits the calendar form,
the controller will pass the appropriate rc fields into the service's
getCalendarSettings method, and the returned bean will contain formatted
versions of any fields that require processing. So far so good. However,
you
first access the calendar, those form fields aren't in rc, so the
controller will
blow up if it tries to access them to pass them to the service. It either
has to
detect that no form was submitted and pass nothing to the service (check
for
a hidden formWasSubmitted field maybe), or individually test for the
existence of each field it might pass, and only access and pass it if it
exists in
rc, pretty awkward.
I don't like either of those choices, and besides, (a) doesn't cover
checkboxes
or radio buttons, which might not exist in form/rc even if the form was
submitted. It seems like the only real-world options are
a) Pass rc into the service as a whole, so it can default any missing
values, or
b) Have the controller default the whole set of fields at least to empty
string,
so it can reference them safely.
(a) is unappealing because the service/model layer shouldn't know anything
about the request cycle, form fields, or rc, and because it should be
dealing
with object field names, not form field names. That last distinction gets
very
relevant if you have, say, a person record with any number of phone
numbers, additional fields for which get added via js. On the form, the
fields
might be phoneName_1, phoneNumber_1, phoneName_2, etc, but at the
service/model level, that should already have been translated into an
array
of PhoneNumber beans. The numeric suffixes, the maxPhoneCount field,
and other artifacts of the html form are completely gone.
Which leaves it up to the controller to be aware of form fields, at least
to the
extent of defaulting all fields so it can pass them into the service
whether
they're present in a submitted form or not. It's also probably what must
un-
flatten those suffixed phone number fields into an array of objects, even
though it doesn't know anything about the actual business rules for
PhoneNumber beans.
In a larger sense, it's actually the view that should deal with form
fields, but
that can't work unless some method of the view gets called
*before* the controller runs. I don't hear anyone suggesting that, and
anyway, as I understand it, views are cfms in ColdBox, not cfcs, so they
don't
have any methods at all. (Never got why that was so. I've been building
views in cfcs for a while now. It makes tons of sense to me that they
inherit
standard methods to render sets of html select options, radio buttons,
etc,
as well as domain-specific widget rendering methods, say renderUserPicker.
Don't mean to be critical, but view helpers seem like a baggier way of
accomplishing the same thing. Off track...)
Am I making sense here? Any other thoughts? I really resist getting the
controller involved with form field details, but I can't see any other way
to
approach it. You could use an interceptor or setupRequest method for the
same purpose I think, but those still live in controller-land, not that
much