Separation of Concerns

4 views
Skip to first unread message

Ryan Montgomery

unread,
Sep 10, 2009, 9:13:36 PM9/10/09
to web2py-users
I am new to web2py and I have some questions. The first one being:

Does the ability to creating Forms with html tables in the controller
violate the principal of "Separation of Concerns"? Shouldn't this
"view logic" be handled in the view and not in the controller?

Please reference example #28 http://www.web2py.com/examples/default/examples#form_examples

mdipierro

unread,
Sep 11, 2009, 12:54:18 AM9/11/09
to web2py-users
Yes. The fact that you can do it, does not man you should do it.

Sometime need to build HTML programmatically, for this reason web2py
provides a OOP server side representation of the DOM so that you never
have to manipulate strings in the controllers.

You can use this to build forms but you do not have to.

Often it is better to use

form=SQLFORM.factory(Field(...), Field(...), Field(...))

and then customize the form in the view.

Massimo

Ryan Montgomery

unread,
Sep 12, 2009, 12:26:40 PM9/12/09
to web2py-users
Thanks for the response. I guess my question was more about why it's
even possible with a web framework that is said to be designed for
best practices, and more so, uses it in the only forms example in the
documentation.

I'm new to web2py so I am trying to understand the "right" ways to do
things, but this was a red flag that I figured had to have some
explanation.

Ryan

On Sep 11, 12:54 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> Yes. The fact that you can do it, does not man you should do it.
>
> Sometime need to build HTML programmatically, for this reason web2py
> provides a OOP server side representation of the DOM so that you never
> have to manipulate strings in the controllers.
>
> You can use this to build forms but you do not have to.
>
> Often it is better to use
>
> form=SQLFORM.factory(Field(...), Field(...), Field(...))
>
> and then customize the form in the view.
>
> Massimo
>
> On Sep 10, 8:13 pm, Ryan Montgomery <rmontgomery...@gmail.com> wrote:
>
> > I am new to web2py and I have some questions. The first one being:
>
> > Does the ability to creating Forms with html tables in the controller
> > violate the principal of "Separationof Concerns"? Shouldn't this

Iceberg

unread,
Sep 12, 2009, 12:51:20 PM9/12/09
to web2py-users
I think Massimo already give clear answer in his post.

And I try to give my $0.02 on this from another aspect. Let's say you
create form in your view rather than controller, don't you still need
to somehow describe this form in the controller again, in order to
make your controller capable to "understand" the form data sent from
browser? If so, how would you describe its data structure, in your
controller? There are 2 conventions in web2py to do that, one is the
example #28 Ryan mentioned, the other is SQLFORM.factory(Field(...),
Field(...)) Massimo mentioned. It just happened that the "description"
in controller, has a default appearance even without a view, which
could make MVC-believer confused. Hope my explanation make some sense.

By the way, I remember there was a deep discussion on this MVC topic
in this mail list, but I just did not dig it out, yet.

Regards,
Iceberg
Reply all
Reply to author
Forward
0 new messages