On 8/15/06 6:54 AM, Sean Davis wrote: > On 8/14/06 10:32 PM, "Danial Pearce" <[EMAIL PROTECTED]> wrote: >> I could spend the best part of 3-4 hours writing crappy templates, div >> this, textarea that, for all my fields. But there already exists a >> whole bunch of helper scripts to dig through your model and html up >> some forms for you. I would much rather spend that time writing an >> RDBO helper if other people would benefit. [...]
> [...] if you haven't looked at Rose::HTML::Object, you might want to do so. > Combined with RDBO and a good template engine, it might satisfy some of your > needs. That's exactly what I was going to say. The glue code required to create an HTML form "on the fly" for an RDBO object is pretty trivial. It's basically just this: $form = Rose::HTML::Form->new; foreach my $column (My::DB::Thingie->meta->columns) { $form->add_field($column->name => make_field_for_column($column)); } ... sub make_field_for_column { my $column = shift; my $type = $column->type; if($type = 'varchar') { return Rose::HTML::Form::Field::Text->new( name => $column->name, size => 15, maxlength => $column->length, default => $column->default); } elsif($type eq ...) { ... } ...and so on... } Then pass $form to your templating engine, which does something like this (Mason example): <% $form->start_html %> % foreach my $field ($form->fields) % { <% $field->xhtml_label %> <% $field->xhtml %> <br/> % } <% $form->end_html %> only perhaps a bit fancier :) It all boils down to policy decisions. For each column type, what kind of field should be created? You can do it in a big elsif chain (as shown above) or you can delegate to different methods or whatever. Make it as complex or as simple as you want. I eventually plan to create a module that implements this glue with a bunch of reasonable defaults, but I suspect most users will want to customize it in some way. If anyone else wants to take a crack at an "RDBO to/from Rose::HTML::Form" module, I'd be glad to help hash out design ideas. It's simple code, but careful API design. It has to be flexible enough for the user to change anything, but also come with nice defaults and a simple API for users that don't want to customize. For more info on Rose::HTML::Objects, check the docs: http://search.cpan.org/dist/Rose-HTML-Objects/ There's also a mailing list if you have any RHTMLO-specific questions: http://lists.sourceforge.net/mailman/listinfo/rose-html-objects -John ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object