Stuart
There are a couple of problems in your code...
The big problem I see is that you are mapping your form to an object in
your template and then trying to access it with the DEFAULT_KEY in your
action class.
The second problem may be a misunderstanding in how to use intake. In
your screen class you pass a Customer object into the context. This
only makes sense if you are trying to populate the form with the values
of that object (for example if the form is to update a customer's info)
which your arent since the object is empty and you create a new object
in the action class. Since the purpose of the form seems to be to
populate new customer objects, then map the form to Default, remove the
code in your screen class that places the customer object in context,
and leave your action class the way it is.
To put it another way, i think you confused the purpose of mapTo( object
). This is not to map the elements of the form to fields of a class,
thats whats in intake.xml. This is to map the values of an existing
object to the elements of a form.
-b
On Sun, 2003-03-02 at 06:33, Stuart Townhill wrote:
> To anyone who can help,
>
> I know intake is the most talked about topic and that everyone may be
> fed up of the posts but I have read a lot and now going around in
> circles. If I get a very simple intake to work just using the tools
> supplied with TDK and working with my database (business object) I will
> attempt to write a very basic idiots guide on the wiki. Anyway not sure
> what to say is wrong with my code but have copied and pasted four
> cuttings from the relevant files. I have read the service document and
> how-to and are aware of it using Scarab and have seen many posts on
> various different issues but I believe using the screen class to
> populate the context rather than actions and the use of pull tools would
> be simpler for a beginning.
>
> Pretty sure intake.xml is fine.
>
> Think I have populated context correctly in screen class?
>
> In template when I map to object in context " #set ($customerGroup =
> $intake.Customerentry.mapTo($customer)) " my input field does not render
> correctly in browser and the if statement to catch " FirstName.isValid()
> " fails but they do create correctly with " #set ($customerGroup =
> $intake.Customerentry.Default) " but from my reading this statement is
> only to do with intake and NOT mapping to a business object.
>
> Not to sure about action yet since haven't managed to create form
> correctly but have written it.
>
>
> ---My Coding Attempt---
>
> ---Intake.xml---
>
> <input-data basePackage="soundideas.covert.om.">
> <group name="Customerentry" key="customerentry"
> mapToObject="customer">
> <field name="Firstname" key="f" type="String"
> mapToProperty="firstname">
> <rule name="minLength" value="1">Please enter first
> name</rule>
> </field>
> </group>
> </input-data>
>
>
> ---Screen Class---
>
> public class InsertCustomerIntake extends SecureScreen
> {
> public void doBuildTemplate(Context context)
> {
> Customer customer = new Customer();
> context.put("customer", customer);
> }
> }
>
>
> ---Template---
>
> <form action="$link.setPage("InsertCustomerIntake.vm")" method="post"
> name="customerentry">
>
> <input type="hidden" name="action" value="doInsertCustomer">
> #if ($data.Parameters.nextTemplate)
> <input type="hidden" name="nextTemplate"
> value="$data.Parameters.nextTemplate">
> #else
> <input type="hidden" name="nextTemplate" value="index.vm">
> #end
>
> #set ($customerGroup = $intake.Customerentry.mapTo($customer))
>
> #if ( !$customerGroup.Firstname.isValid() )
> $customerGroup.Firstname.Message<br>
> #end
>
> <input type="text" name="$customerGroup.Firstname.Key"
> value="!$customerGroup.Firstname ")>
>
> <input type="submit" name="eventSubmit_doInsert" value="Insert"/>
>
> $intake.declareGroups()
>
> </form>
>
>
> ---Action---
>
> public class doInsertCustomer extends SecureAction
> {
> public void doInsert(RunData data, Context context)
> throws Exception
> {
> IntakeTool intake = (IntakeTool) context.get("intake");
> Group group = intake.get("Group", IntakeTool.DEFAULT_KEY);
> if (group.isAllValid())
> {
> Customer customer = new Customer();
> group.getProperties(customer);
> customer.save();
>
> data.setScreenTemplate(data.getParameters().getString("nextTemplate"));
> }
> }
> }
>
> Regards,
>
> Stuart.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]