> ## what do these lines do really?
> #set ( $attributeValue = $issue.AttributeValue("URL") )
> #set ( $group = $intake.AttributeValue.mapTo($attributeValue) )
Okay, forget, #set ( $attributeValue = $issue.AttributeValue("URL") ), it is
scarab-specific and is going to confuse more than help you (I think it
already has ;).
Here is a (hopefully) more straight-forward example.
Suppose I have a instance of an object, Product, in my Velocity context. I
assume you are familiar with how to get an object into Velocity's context
whilst using Turbine.
Product object looks like this (signatures-only, for the sake of brevity):
public class Product implements Retrievable
{
// It is important the your property
// getters and setters use
// Javabean compliant in syntax i.e. prefixed with
// get and set and are in camel-case.
public void setProductId(int Id);
public int getProductId();
public void setProductName(String name);
public String getProductName();
/**
* Required by Retrievable should uniquely
* id this object. Usually the PK of the
* of the object in the DB but does not
* have to be.
*/
public String getQueryKey();
/** @see getQueryKey() */
public void setQueryKey(String key);
}
intake.xml has something in that looks like this:
<group key="product" name="Product" mapToObject="Product">
<field key="pid" name="ProductId" type="int" mapToProperty="ProductId"/>
<field key="pname" name="ProductName" type="String"
mapToProperty="ProductName" />
</group>
Notice that I am explicitly mapping my properties, you really don't need to
do this if
the "name" attribute matches the objects property, I do it anyway.
Our template HTML looks like this:
#*
* We will populate the $product here to
* make things easier to understand.
* More than likely, your $product
* object will already have values
* coming into the template.
* #
$product.setProductId(1)
$product.setProductName("Widget")
$product.setQueryKey("1234")
#*
* This creates a intake group instance
* of the "Product" group with the values mapped
* from $product. $product, is assumed
* to be an instance of a
* Product object that is
* available within the current
* templates context.
*#
$p_group = $intake.Product.mapTo($product)
<form>
<input type="text" name="$p_group.ProductId.Key"
value="$p_group.ProductId.Value">
<input type="text" name="$p_group.ProductName.Key"
value="$p_group.ProductName.Value">
</form>
Here is what the above craziness actually does (it's actually quite simple
AFTER you
figure it out)
$p_group.ProductId.Key and $p_group.ProductName.Key will be generated by
combining:
{intake_group_key}{the result of $product.getQueryKey()}{intake_field_key}
$p_group.ProductId.Key = product1234pid
$p_group.ProductName.Key = product1234pname
$p_group.ProductId.Value and $p_group.ProductName.Value reflect the values
returned by $product.getProductId() and $product.getProductName()
respectively.
So,
$p_group.ProductId.Value = 1
$p_group.ProductName.Value = "Widget"
I hope this clears up things a little better.
Scott
> -----Original Message-----
> From: Dan K. [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 08, 2002 2:45 PM
> To: Turbine Users List
> Subject: RE: intake's mapTo usage?
>
>
>
> Hi Scott,
>
> cool thanks, yes that helped (I appreciate your response!)
> However, my main problem is what do I need to do in the
> template files?
> According to the intake-service doc, under the "Attribute
> Value example"
> section, I am suppose to have the following 2 lines (as well as others
> but I don't quite understand these 2 lines):
>
> ## what do these lines do really?
> #set ( $attributeValue = $issue.AttributeValue("URL") )
> #set ( $group = $intake.AttributeValue.mapTo($attributeValue) )
>
> I don't use scarab and the first line references something from it.
> I believe John McNally (?) or someone else here is an expert on scarab
> and I was hoping s/he might able to enlighten me...but s/he has yet to
> respond unfortunately. Do you know what these lines are
> about, or what I
> need to put in the template to get this all working?
>
> Many thanks again Scott!
>
> Regards,
> Dan
>
> On Mon, 8 Apr 2002, Weaver, Scott wrote:
>
> > > How does one use the "mapTo" feature of intake to map form data to
> > > business objects (manually created, not by torque)? Here are
> > > the steps
> > > I think I need to get it done so far...
> >
> > For your business objects to be intake-compatible they must
> implement the
> > org.apache.turbine.om.Retrievable interface or if you are using the
> > decoupled fulcrum Intake service,
> org.apache.fulcrum.intake.Retrievable.
> >
> > Intake uses introspection to set the values of your B/O's
> from HTML form
> > fields and vice-versa. The fields defined within a group
> need to be able to
> > be mapped into your B/O. In most cases you will set "name"
> attribute to
> > match the property within your B/O. If you want the field
> name to be
> > something other than the B/O's property's name it maps to,
> you will need to
> > supply the "mapToProperty" attribute of that field to be
> the same as the
> > property in your B/O.
> >
> >
> > hth,
> > Scott
> >
> >
> >
> >
> > > -----Original Message-----
> > > From: Dan K. [mailto:[EMAIL PROTECTED]]
> > > Sent: Friday, April 05, 2002 6:30 PM
> > > To: [EMAIL PROTECTED]
> > > Subject: intake's mapTo usage?
> > >
> > >
> > >
> > > Hi,
> > >
> > > I've read up the intake-service documentation but it's quite
> > > confusing and
> > > the mail archive doesn't really address my newbie intake question:
> > >
> > > How does one use the "mapTo" feature of intake to map form data to
> > > business objects (manually created, not by torque)? Here are
> > > the steps
> > > I think I need to get it done so far...
> > >
> > > In the intake.xml file:
> > > - there must be a group tag with the "name", "key", and
> "mapToObject"
> > > attribute set, similar to:
> > > <group name="MyGroup" key="MyGroupKey"
> mapToObject="MyBusinessObject">
> > >
> > > - the mapToObject="MyBusinessObject" has a corresponding
> > > MyBusinessObject.java with appropriate get/set methods for
> > > the attributes
> > > in question. Is this right?
> > >
> > > - add in some fields to the group (with their rules), similar to:
> > > <field name="Username" key="Username" type="String">
> > > <rule name="required" value="true">Username is
> required</rule>
> > > ...some more rules if desired...
> > > </field>
> > >
> > > In the corresponding "Action" class:
> > > - get an instance of the intake object from the context,
> and set the
> > > business object with the corresponding group field values
> from intake,
> > > similar to:
> > > IntakeTool intake = (IntakeTool)context.get("intake");
> > > Group group = intake.get("MyGroup", IntakeTool.DEFAULT_KEY);
> > > MyBusinessObject myBO = new MyBusinessObject();
> > > if (group.isAllValid()) {
> > > group.setProperties(myBO);
> > > }
> > > // at this point, myBO should be populated with the
> > > correct attribute
> > > // values, right? So I can print it out like this:
> > > System.out.println("myBO = "+myBO.toString());
> > >
> > > In the template file (.vm file):
> > > - include this in a <form> tag:
> > > $intake.declareGroups()
> > > - and then what?
> > >
> > > I noticed in the intake-service doc it says to do something
> > > similar to:
> > > #set ( $attributeValue = $issue.AttributeValue("URL") )
> > > #set ( $group = $intake.AttributeValue.mapTo($attributeValue) )
> > >
> > > But that's something from scarab, of which I have no clue
> > > about...especially the first #set statement.
> > >
> > > If someone can detail this out, then I'd appreciate it
> very much! TIA.
> > > I'm sure it'll be useful as a basis for an "intake quick
> start how-to"
> > > as well.
> > >
> > > Regards,
> > > Dan
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > > <mailto:[EMAIL PROTECTED]>
> > > For additional commands, e-mail:
> > > <mailto:[EMAIL PROTECTED]>
> > >
> >
>
>
>
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>