Re: [RDBO] Integration with Rose::HTML::Form

2007-01-31 Thread Michael Lackhoff
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

2007-01-31 Thread John Siracusa
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] New find method type for one-to-many relationships

2007-01-31 Thread Ted Zlatanov
On 30 Jan 2007, [EMAIL PROTECTED] wrote:

 In SVN, I've just added a new method type to one-to-many relationships
 (no docs yet).  Right now, I'm calling it find.  It's for fetching
 related objects using ad-hoc queries instead of being constrained to
 the mapping defined in the relationship metadata itself.  It has no
 ability to set related objects; it just returns them.
...
 So, does this method type seem useful?  If so, what do you think of
 the method type name (find) and the default method name format
 (find_relationship-name)?  Finally, should this method type be
 created by default for all one-to-many relationships, or should it
 have to be manually requested in the relationship setup?

It's exactly right.  It should be created by default for all
relationships.  It will save me, at least, many lines of code.

I would also ask for a load_speculative() method, which simply calls
load with (speculative=1).  I know about default_load_speculative,
this is a local override.  Yes, it pollutes the namespace--I think
it's worthwhile.

Ted

-
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

2007-01-31 Thread Michael Lackhoff
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


[RDBO] Rose::HTML::Form-validate()

2007-01-31 Thread Derek Watson

I see that as of 0.546, form validate() calls get passed to sub-forms by
default,

   * Added a cascade parameter to validate(), which defaults to true.
 (Suggested by Guillermo Roditi)

Which is great - exactly what I needed! But there is an order-of-operations
problem for me, because validate() calls the sub-form validation before it
calls the per-field validation. If my form validation routine says

$self-field('password')-error('Password and confirm do not match');

then it will be overwritten immediately after by the per-field validation,
which unconditionally sets

$self-error(undef);

on every call.  Is it possible to a) Perform the field validation before the
form validation or b) avoid wiping out existing field errors on every call
to field-validate()?

I do know that form-level validation in practice should (by convention) be
writing errors on the form level, not the field level, but the field-level
errors give me flexibility in my layout template so that I can display
errors relatively close to their respective fields.

I have added this to my base-class, but it seems like a nasty workaround

sub validate {

 my($self, %args) = @_;

 my $ok = $self-SUPER::validate(%args);

 unless ($ok) {
   $args{form_only} = 1;
   $self-SUPER::validate(%args);
 }

 return $ok;
}


Cheers,
DW
-
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


Re: [RDBO] Rose::HTML::Form-validate()

2007-01-31 Thread John Siracusa
On 1/31/07, Derek Watson [EMAIL PROTECTED] wrote:
 I see that as of 0.546, form validate() calls get passed to sub-forms by
 default,
  * Added a cascade parameter to validate(), which defaults to true.
  (Suggested by Guillermo Roditi)
 Which is great - exactly what I needed! But there is an order-of-operations
 problem for me, because validate() calls the sub-form validation before it
 calls the per-field validation. If my form validation routine says

 $self-field('password')-error('Password and confirm do
 not match');

 then it will be overwritten immediately after by the per-field validation,
 which unconditionally sets

 $self-error(undef);

 on every call.  Is it possible to a) Perform the field validation before the
 form validation or b) avoid wiping out existing field errors on every call
 to field-validate()?

I'm aware of this issue (it's bitten me too).  Here's what's
happening, in a bit more detail.  Consider a form A with fields a1 and
a2.  Calling validate() on that form does the following:

1. Validate field a1: $form-field('a1')-validate()
2. Validate field a2: $form-field('a2')-validate()

Now say there's a form B with fields b1 and b2 and a nested form A
with fiends a1 and a2.  Calling validate() on that form currently does
the following:

1. Validate sub-form A:
1.1. Validate field a1: $sub_form-field('a1')-validate()
1.2. Validate field a2: $sub_form-field('a2')-validate()
2. Validate field a1: $form-field('A.a1')-validate()
3. Validate field a2: $form-field('A.a2')-validate()
4. Validate field b1: $form-field('b1')-validate()
5. Validate field b2: $form-field('b2')-validate()

The problem is that the fields in the nested form are validated twice:
first as part of the validation of sub-form A, and again as part of
the flattened list of all fields in the entire form.

I think the solution is pretty simple: don't re-validate fields in
sub-forms when the cascade option is on (which it is, by default).
I plan to include this change in the next release.

-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=lnkkid=120709bid=263057dat=121642
___
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object


Re: [RDBO] Rose::HTML::Form-validate()

2007-01-31 Thread John Siracusa
On 1/31/07, John Siracusa [EMAIL PROTECTED] wrote:
 I think the solution is pretty simple: don't re-validate fields in
 sub-forms when the cascade option is on (which it is, by default).
 I plan to include this change in the next release.

...and this change is in SVN, if you want to give it a try.

-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=lnkkid=120709bid=263057dat=121642
___
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

2007-01-31 Thread John Siracusa
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