this may not be exactly what you were asking for, but one option is to 
separate the record retrieval logic and the form display so that you end 
up with something like this

my-form.html
<%init>
   my %form_args;
   if ( $this_an_existing_record ) {
     %form_args = My::DB::Module::retrieve_record( %db_args );
   } else {
     %form_args = My::DB::Module::set_defaults();
   }
   $m->comp( 'form-display-component', %form_args );
</%init>

now whatever you have populated %form_args with gets passed "naturally" 
into your form. you could even integrate the logic for determining 
whether this is an existing record into the method that you call to 
populate %form_args, leaving you with

<%init>
   my %form_args = My::DB::Module::retrieve_record( %db_args );
   $m->comp( 'form-display-component', %form_args );
</%init>

the bottom line is that by separating the data retrieval and the form 
display allow you to leverage the mason code for setting the local 
variables. the problem is that this code happens before <%init> (look in 
the obj files sometime) so mangling %ARGS doesn't change the values for 
the already-set local variables. you could just ref to your variables 
directly as $ARGS{field1}, $ARGS{field2}, etc. but that's  a little 
cumbersome code-wise.

good luck


Louis-David Mitterrand wrote:
> Hi,
> 
> I have a component containing a form used for creation and modification. 
> When called for modification this component first queries the database 
> to populate the form elements.
> 
> Ideally what I'd like to do is avoid putting '-default=>$database_value' 
> on all form inputs and simply populate them as if the component had been 
> called with %ARGS containing the data with the expected effect on all 
> <%args> variables. 
> 
>  From the <%init> of a component is there a way to inject data so that 
> all <%args> variables are instantiated?
> 
> Thanks,
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Mason-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mason-users

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to