Re: [RDBO] Integration with Rose::HTML::Form
On 30 Jan 2007 at 17:00, John Siracusa wrote: id is in $session, which the form knows nothing about. But in most web app frameworks, there's usually some way to get at globally applicable data like the session, in which case it's reasonable for customer_from_form() to return you an object that's completely ready to be save()d, without any fiddling, and, ideally, without need for an explicit update = ... argument. This is a question I have for some time now: How to get your framework object into the depth of all the RDBO and RHTMLO objects (DB table/manager, HTML forms, special fields). I use CGI::Application as my framework and Template Toolkit as my templating engine and it is so helpful to have the CGI::Application object within the template as 'c'. So I can just say c.session.param('something'). Thanks Cees! Are there any similar solutions out there for the Rose family of Objects? E.g. I need something to list the dates of the currently logged in user. At the moment I have to explicitely pass the CGI::Application object (or the id of the user). It would be so helpful if it was already there somehow. Cheers, Michael - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object
Re: [RDBO] Integration with Rose::HTML::Form
On 1/31/07 5:11 AM, Michael Lackhoff wrote: This is a question I have for some time now: How to get your framework object into the depth of all the RDBO and RHTMLO objects (DB table/manager, HTML forms, special fields). I use CGI::Application as my framework and Template Toolkit as my templating engine and it is so helpful to have the CGI::Application object within the template as 'c'. So I can just say c.session.param('something'). Thanks Cees! Are there any similar solutions out there for the Rose family of Objects? E.g. I need something to list the dates of the currently logged in user. At the moment I have to explicitely pass the CGI::Application object (or the id of the user). It would be so helpful if it was already there somehow. I don't use CGI::Application, so maybe I'm misunderstanding how it works, but how about a class method that returns the current CGI::Application object? e.g., MyWebSite-current_app(). You'd set it at the beginning of each request. Then, in your common RDBO base class, just add a method: sub app { MyWebSite-current_app } and now you can get at it from any RDBO object. -John - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object
Re: [RDBO] Integration with Rose::HTML::Form
On 31 Jan 2007 at 8:52, John Siracusa wrote: I don't use CGI::Application, so maybe I'm misunderstanding how it works, but how about a class method that returns the current CGI::Application object? e.g., MyWebSite-current_app(). You'd set it at the beginning of each request. Then, in your common RDBO base class, just add a method: sub app { MyWebSite-current_app } and now you can get at it from any RDBO object. Yes, I will try this but I was hoping for some import hack that would do this for me by just 'use'-ing a plugin module. Then I wouldn't have to do it again for every app in every (base) class and I don't have base classes for everything yet. But anyway I think this is a good start. Thanks, Michael - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object
Re: [RDBO] Integration with Rose::HTML::Form
On 1/30/07, John Siracusa [EMAIL PROTECTED] wrote: I have db_object_from_form() and init_with_db_object() methods that will handle a tree of RDBO-derived objects that correspond to a tree of nested RHTMLO forms. The code is included at the end of this email, but it's still in progress and may be buggy. ...and it was. Below is an updated version of init_with_db_object(). -John --- sub init_with_db_object { my($self, $object) = @_; croak Missing required object argument unless($object); $self-clear(); my $selected_object; foreach my $field (sort { $a-name cmp $b-name } $self-fields) { my $name = $field-name; $selected_object = $object; if($name =~ /$FF_SEPARATOR_RE/o) { my $nibble = $name; my $tmp_obj = $selected_object; while($nibble =~ s/^([^$FF_SEPARATOR]+)$FF_SEPARATOR_RE//o) { my $related = $1; last unless($tmp_obj-can($related)); if(Rose::DB::Object::Util::has_loaded_related($tmp_obj, $related)) { $tmp_obj = $tmp_obj-$related() } else { my $new_obj; eval { $new_obj = $tmp_obj-$related() }; if($@ || !$new_obj) { # Restore failed segment $nibble = $related$FF_SEPARATOR$nibble; last; } $tmp_obj = $new_obj; } } if($nibble =~ /$FF_SEPARATOR_RE/o) { $name = $field-local_name; } else { $name = $nibble; $selected_object = $tmp_obj; } } else { $name = $field-local_name; } if($selected_object-can($name)) { #$Debug warn field($name) = $selected_object-$name = , $selected_object-$name(), \n; $field-input_value(scalar $selected_object-$name()); } } } - 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=lnkkid=120709bid=263057dat=121642 ___ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object
[RDBO] Integration with Rose::HTML::Form
Hello, I am using RDBO in conjunction with Rose::HTML::Form for the first time, and wonder if there are any guides or examples out there showing some conventional integration techniques. Specifically, how best to use RHF's objects returned by object_from_form() style methods to update database rows. Currently I have something like this: $form-init_with_customer($session-customer); # is a load()ed RDBO object if ($ENV{REQUEST_METHOD} eq 'POST') { $form-params(\%ARGS); $form-init_fields(); if ($form-validate) { my $c = $form-customer_from_form; # is RDBO::Customer-new() $c-id($session-customer_id); # avoid an insert $c-save(update = 1, changes_only = 1, cascade = 1); # force an update } } Which works, but seems like there is probably a more conventional way to do this. But my real problem comes when my form returns other objects as well, which are related to customer ($c) . . .for example if ($form-validate) { my $c = $form-customer_from_form; # is RDBO::Customer-new() $c-id($session-customer_id); # avoid an insert my $a = $form-address_from_form; # is RDBO::Address-new() $c-billing_address($a); # inserts a new RDBO::Address record, but unfortunately I want an update $c-save(update = 1, changes_only = 1, cascade = 1); } Is there a better way to use these two packages together? Thanks in advance, DW - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object