Jon and John,

I _think_ I understand what you guys are saying.  I've put together an 
example document which I will attach to this email.  Can you please tell 
me if Iam on the right track?


I am still fuzzy about the aliasing part of the intake specification.  
If you alias a field "NewLogin" to make too "Login" using the 
mapToObject attribute, then is it the case you will have the property 
'Login' set twice???

Take Care.
Jason Kary

Jon Stevens wrote:

> on 9/27/01 12:25 PM, "John McNally" <[EMAIL PROTECTED]> wrote:
> 
>> Jon Stevens wrote:
>> 
>>> on 9/27/01 10:54 AM, "J Kary" <[EMAIL PROTECTED]> wrote:
>>> 
>>>> Hi,
>>>> 
>>>> I've been reading through the Intake docs and I was wondering about the
>>>> 'mapToObject' attribute.
>>>> 
>>>> 1) When mapping a group to an object do all the fields have to map to
>>>> that object?
>>> 
>>> Yes. (keep reading)
>>> 
>> No.  The mapToObject attribute on <group> sets the default object for
>> all the fields in the group.  There is a mapToObject attribute on
>> <field> that can be used instead of or to override the one in group.  If
>> a particular field does not map to an object's property but you have
>> defined a default mapToObject for the group, you can turn off the
>> default behavior of assuming that object contains a property matching
>> the field name by using <field mapToProperty=""...
>> 
>> Using multiple objects per group is possible though not tested and there
>> may be some inconsistencies, as the behavior has not been completely
>> defined.
> 
> 
> John and I sit next to each other so we talked about this...
> 
> He says no, I say yes. Things are confusing. So, let me clarify:
> 
> All bean fields MUST map to intake fields within an intake group UNLESS you
> define the mapToProperty attribute within the intake field to map to a bean
> field. HOWEVER, you can set the mapToProperty="" which will allow you to not
> have the bean field and not get an error message in the log file.
> 
> I know it is confusing. I hope it makes more sense now.
> 
> -jon
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


Mapping Examples for Intake:
============================

The following document describes the three main ways you can use intake to map fields 
in form to properties in a bean.  

1) Map all fields directly to a bean:

   1.1) Intake.xml
       
    <group name="myGroup" key="myg" mapToObject="om.Person">
       <field name="Name" key="name">
         <rule name="minLength" value="1">Must have a name</rule>
       </field>
       <field name="Address" key="addr">
         <rule name="minLength" value="1">Must have an address</rule>
       </field>
       <field name="Phone" key="phone">
         <rule name="minLength" value="1">Must have a name</rule>
       </field>
    </group>


   1.2) Screen.vm
        #set ( $grp = $intake.MyGroup.Default )
        <form name="foo" action="$link.setAction("Action")">
           <input type="text" name="$grp.Name.Key" value="$!grp.Name" />
           <input type="text" name="$grp.Address.Key" value="$!grp.Address" />
           <input type="text" name="$grp.Phone.Key" value="$!grp.Phone" />
           <input type="submit" />
        </form>

   1.3) Action.java

        //In action method.
        IntakeTool intake = (IntakeTool) context.get( "intake" );
        Group grp = intake.get( "myGroup" );
        Person p = new Person();

        grp.setPropterties( p );


In this case all the fields defined must have the same property name in the bean 
Person.  This example is closest too the JSP style of setting properties.  Any 
property that is not included in the field list is ignored.

2) Map some fields to the bean
   2.1) Intake.xml
       
    <group name="myGroup" key="myg" mapObjectTo="om.Person">
       <field name="Name" key="name">
         <rule name="minLength" value="1">Must have a name</rule>
       </field>

       <!--## Do not map this intake field to the bean. ##-->
       <field name="Address" key="addr" mapToProperty="" >
         <rule name="minLength" value="1">Must have an address</rule>
       </field>

       <!--## Map this field to a different bean. BusinessObj.Phone -->
       <field name="Phone" key="phone"  mapToProperty="org.mycompany.om.BusinessObj" >
         <rule name="minLength" value="1">Must have a name</rule>
       </field>
    </group>


   2.2) Screen.vm
        #set ( $grp = $intake.MyGroup.Default )
        <form name="foo" action="$link.setAction("Action")">
           <input type="text" name="$grp.Name.Key" value="$!grp.Name" />
           <input type="text" name="$grp.Address.Key" value="$!grp.Address" />
           <input type="text" name="$grp.Phone.Key" value="$!grp.Phone" />
           <input type="submit" />
        </form>

   2.3) Action.java

        //In action method.
        IntakeTool intake = (IntakeTool) context.get( "intake" );
        Group grp = intake.get( "myGroup" );
        Person p = new Person();

        grp.setPropterties( p );

In this case, the field Address is specifically not set by the 'grp.setProperties' 
java command.  In addition the field Phone is also ignored by 'grp.setProperties'as it 
maps too a different java object.  The default mapping of the group still applies to 
any field without the mapToObject attribute.

If the mapToObject attribute was removed from the group field, then each field would 
use it's own mapToObject attribute to specify field to property relationships.  If no 
mapToObject attribute is specified in a field or the mapToObject attribute equals "" 
then the field does not map to a property.

3)  Aliasing?  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to