Mail archive

Re: [Acf] RFC: less lua - more html

From: Nathan Angelacos <>
Date: Sat, 14 Oct 2006 10:00:31 -0400


Thanks for your comments. I think you have very valid points.
Creating web pages in lua is stupid. ;-)

Here are a few comments to keep the discussion going:

> The problem with curent implementation is that you write a html page in
> lua.
> m = model.hostname
> return { type="form", action="hostname.cgi", value= {
> { type="formtext", value="Set the hostname with this form" },
> { type="text", name="hostname", value=m.get() },
> { type="submit", name="cmd", value="Set hostname" }
> }

This is because we are still writing for "generic" view, rather than
building views ourselves. "generic" is stupid. For example, the
network interfaces-list.view doesn't use this structure at all, and so
the controller list function doesn't have to build a "form" table.

> Compare that with:
> <? c = controller.hostname ?>
> <form action="hostname.cgi">
> <p>Set the hostname with this form</p>
> <input type="text" name="hostname" value="<? hostname.get() ?>"/>
> <input type="submit" name="cmd" value="Set hostname"/>
> </form>
> So basicly, the view is just moved over to the controller.
> Now the limit between the view and the controller is not so big since we
> are talking about html controllers here.

The current achitecture is:

        webconf (front controller - traffic cop) ->
        individual controller ->
        individual view

Right now, it is possible to replace "webconf" with something else as
the front controller, and have a CLI setup program.

Moving ALL of the controller code to the html page will break that


The view only does "get" requests - By the time the view is reached, any
changes that were requested are either made, or denied. Perhaps it
would be possible to code methods (functions) in the controllers/models
that the views could call to get the state of the system.


How would we handle the case where validation fails? Using your example

<? c = controller.hostname ?>
  <form action="hostname.cgi">
          <p>Set the hostname with this form</p>
          <input type="text" name="hostname" value="<? hostname.get() >"/>
          <input type="submit" name="cmd" value="Set hostname"/>

What happens when the user enters "This is an invalid hostname" for the
hostname? hostname.get() will return the name of the current hostname;
it would be the model that would report the failure, but by the time the
view is reached, how could the model tell the view that the hostname
REQUEST failed?

> Now, people tend to be more familiar with html than lua, so it would be
> better to try minimizing the lua code and replace it with html as much
> as possible.
> It is not desireable to write all html code again. Headers, footers
> menus and maybe even tabs can be generated. What is interesting is what
> is between <div id="content> and </div>.
> We could let the generic.view do what it does now, but if there is a
> file named foo.view.content, generic.view will do a haserl include
> <?include foo.view.content ?>

Or perhaps abandon the generic view entirely, and just say that you MUST
write a view for each view.

Unfortunately, the <?include in haserl binds at load time, not at
runtime, so you won't be able to have a generic view with an
"<?include <controllername>.view ?> " - each view would have to be
hand-coded. :-(

> This means that you dont need to write *all* the view, only the
> interesting part in html. (I looked earlier how this could be
> implemented and i think its possible)
> The foo.view.content could look something like:
> <? c = controller.hostname_form ?>
> <form name="hostname_form" action="hostname.cgi">
> <p>Set the hostname with this form</p>
> <? html.input( c.hostname ) ?>
> <? html.input( c.cmd ) ?>
> </form>

Another nit:

For security reasons, the views, controllers, and models are outside the
document tree; having an action to "hostname.cgi" means you have N

I think you still want the action to always be
/cgi-bin/webconf/controller/action/view - otherwise, you are suggesting
we effectively abandon mvc.

> Where controller.hostname_form earlier is set to:
> controller.hostname_form = Form:new()
> { type = "text", name="hostname", value=m.get() },
> { type ="submit", name="cmd", value="Set hostname" }
> }
> We could move things like labels and fromtext, from the controller to
> the view. People could make the page structure in html instead of in
> lua.

Perhaps the confusion is the assumption that everything has to be built
to use the "generic" view. If you write your own custom views, the
controller is free to pass to the view ANY data table.

In fact, thinking about it, if we don't use serialize, but use
string.dump in the controller, and and loadstring in the view, it might
be possible to pass entire *functions* to the view that it could use.

> PS. While writing this, I'm not sure if this is what we really want. If
> you do gui programming (qt, wxWigets, gtk) the labels are normally
> controllers too.
> Natanael Copa
> _______________________________________________
> acf mailing list
Received on Sat Oct 14 2006 - 10:00:31 UTC