V2.0 Integration

From Frevvodocs

Jump to: navigation, search

Contents

  • 1.2 Email Integration
  • 1.3 Integrating with your database
  • 1.4 Integrating with web services
  • 1.5 Multi page forms
  • Integration

    Integrating with REST applications

    From the point of view of the user interface, most web applications can be thought of simply as CRUD (Create, Retrieve, Update & Delete) operations on documents. In the diagram below, the form is being used to initially display a Customer and Order and then to update them. If you think in REST terms, the form is a View Resource that composes multiple Entity Resources (in this case a Customer Resource and an Order Resource), displays their current state and allows you to update them. Image:Compose_Documents.jpg

    frevvo provides a very flexible and powerful mechanism for interacting with documents (and the web in general). You can download source code and forms for the discussion below. We strongly recommend that you download the example, study it and use it as a template for integrating with your own web applications.

    Document URIs

    For each Document Type that you add to your form, frevvo permits you to assign

    • a document URI Template resolved either using query parameters or form fields.
    • a Read method and
    • a Write method.

    This is best described using several examples. Consider the example above. Here are the interactions a Customer Resource supports:

    Resource Method Description Returns
    Customer List GET List of customers (may be criteria based) XML list of customers
    Customer List POST Create new customer URI of newly created customer
    Customer GET Get customer data XML representation of cutsomer
    Customer PUT Update customer
    Customer DELETE Remove customer
    Updating a document

    Consider the case where a form is used to update a particular customer. To create the form:

    1. Upload your customer schema to the designer, add the customer element to the document types for the form and add the customer to the form (which automatically generates controls). See the section on Adding Controls from Schema for further details.
    2. Drag/drop, change labels etc. directly in the browser
    3. Specify URI template .../customers/{customer}, choose Read Method GET and Write Method PUT
    4. Specify a Form Action URI if desired (we'll get to this later).

    That's it. As usual, you access the form using its URI. When the form is used (instantiated), you may specify one or more query parameters along with the URI. For this example, we might use a URI and query parameter: .../form/1234?customer=02. frevvo will resolve the URI template above to: .../customers/02, GET the customer, and display the initialized form. When the form is submitted, frevvo will automatically PUT the customer document to the same URI thereby updating the customer. The diagram below shows the interactions. Image:Update_Customer.jpg Here's an example form that uses the Customer entity described above. In the example:

    1. We instantiate the form with a parameter customer=02. This causes the form to resolve the URI template and GET the customer data from: http://[server]/customers/02. The resulting XML document provides the initial state of the Customer and is used to initialize the form.
    2. Modify a value and click Submit. The form will automatically PUT to the correct resource and update the customer information.
    3. Finally, frevvo will store the generated document set and assign it a unique URI. The document set and the documents therein can be accessed at this URI.
    Creating a new document

    Consider the case where a form is used to create a new customer. Follow the same steps above, except use the appropriate URI template .../customers and change the Read method to POST. That's it. As usual, you access the form using its URI. When the form is used (instantiated), frevvo will perform the POST and create the customer. It will then follow the server redirect (to the URI of the newly customer) and display the form. When the user enters customer information and submits the form, frevvo will automatically PUT the resulting XML document to the URI of the newly created customer resource thereby updating it. The diagram below shows the interactions:

    Image:Create_Customer.jpg

    Here is an example form that creates a new customer using this method.


    Dynamic documents

    A document URI template can also be linked to a form control. To do this, use the Control Type ID. Consider the Updating a document example above and the sample form therein.

    The form has a Customer document and we have specified URI template .../customers/{customer} and Read method GET. In this form, there is a control which has Type ID 'customer' as shown in the figure below.

    Image:docUri_typeId.png

    If you enter a value in this control, frevvo will automatically resolve the URI template using the new value and attempt to GET a new document. If it succeeds, the form will be initialized with the new document and all relevant control values will automatically update. In the example above, try changing the value to 03 or 04. Notice how the customer information fields change to reflect the new document that is being edited by the form.

    If you enter an ID that does not exist, the GET will fail (return an empty document or a 404 HTTP status code). In this case, frevvo will automatically revert back to the default document with default values as specified by the designer.

    In either case, if you modify/fill in fields and submit the form, it will PUT (since we chose PUT as the Write Method, the form will send an HTTP PUT) the resulting XML document to the resolved URI.

    For example, if you enter ID 03, frevvo will GET .../customers/03, display the form with fields initialized from the returned XML document and PUT the modified XML document to the same URI when the form is submitted. This PUT will update the customer with ID 03.

    If you enter ID 99 (which does not exist), frevvo will GET .../customers/99, which returns an empty document. The form will be displayed with default values (as entered originally by the designer). When submitted, the resulting XML document will be PUT to .../customers/99. This PUT will create a new customer with ID 99 (the behaviour depends on the implementation on the server - in our example, the PUT creates the customer).

    Customer Example

    This example is a good way to understand frevvo's handling of document URIs and the powerful capabilities of composing multiple document resources into view resources. You can download the entire example including source code and forms by clicking here.

    This example follows the principles of REST and uses the Restlet framework but you can use any framework or server-side model that you like. As mentioned earlier, frevvo forms can be thought of as View Resources that compose one or more Entity Resources (documents). In this example we have entities Customer and List of Customers. Reproduced here are the methods that they support.

    Resource Method Description Returns
    Customer List GET List of customers (may be criteria based) XML or JSON list of customers
    Customer List POST Create new customer URI of newly created customer
    Customer GET Get customer data XML representation of cutsomer
    Customer PUT Update customer
    Customer DELETE Remove customer

    This is implemented in the two classes: com.frevvo.restlet.customer.CustomersResource and com.frevvo.restlet.customer.CustomerResource. These simply provide implementations of the above methods returning the desired representation of the resource for a GET, creating a new customer for a POST and updating an existing customer for a PUT. In general, the representation that is returned depends on content negotiation via the Accept headers.

    Select Customer

    There are three forms. The first one is the Select Customer form. This form allows you to search for a specific customer. It uses the first GET method from the table above, and populates a drop down with the list of customers returned according to the search criteria. This is done using a rule. Edit the form, click on the Rules tab and open the Get Customer List rule.

    if (S.value.length > 0) {
    eval('x=' + http.get('http://<hostname>/customers/?pattern=' + S.value));
    C.options = x.customers;
    ID.options = x.ids;
    }
    

    This rule populates the dropdown Customers based on the list of customers returned by the GET method that is invoked by the rule. When a rule invokes http.get(), it also sets the Accept header in the request to 'application/json'. This causes the implementation to provide the JSON representation of the customer list. In this example, we return two JSON arrays: an array of names and an array of IDs. These arrays are used to populate the two dropdowns in the example - the Customer Names dropdown and the hidden Customer IDs dropdown. Try typing a search string (e.g. A). This will return the list of customers whose names start with A. Select a customer from the list. The second rule in this form ensures that the hidden Customer ID field is in sync with the selected customer.

    The Form action for this form is set to the URI template: http://<hostname>/frevvo/web/user/gallery/app/_73zHwep_EduZgK0BUzi1Ug/formtype/__AKE4PgqEdusGKt5_HoCDw?_method=POST&customer={ID}. As described in the Multi Page Forms section above, when the user clicks submit, the URI template above will be resolved based on the selected customer ID and the browser will be redirected to the resulting URI, which is simply that of the next form with a query parameter (customer=02, for example). This form is described below.

    Customer Information

    This form is described in the Updating a document section above. It GETs the XML representation for a specific customer using the third method in the table above, initializes the form with that information and displays it to the user. When submitted, the updated customer information is automaticlly PUT to the same [resolved] URI using the fourth method in the table above.

    Create Customer

    This form is described in the Creating a new document section above. When instantiated, it does a POST to the Read URI using the second method in the table above. This causes the server to create a new customer and return the URI of that customer. frevvo will automatically follow this URI, GET the representation of the customer and display the form (presumably with empty values). When the user enters all required fields and submits the form, frevvo will automatically PUT the resulting XML document to the URI for the newly created customer thereby updating the customer.

    In this manner, the combination of URI templates, read/write methods and form parameters provides a very powerful and flexible way to interact with the web.

    You can find further discussion of this example on the frevvo blog. The relevant articles are: Part 1 and Part 2. Other articles that may be of interest are How do I use my brand new WOA? and Ajax+REST: the next killer app?.


    Email Integration

    Form submissions can be emailed to a recipient when the user clicks the submit button. In order to configure the form to send an email upon submission, open the form designer and edit the form's properties.

    If you are using the XML Edition, set Doc Action to Email Document and specify an email address in the input field below. Each time the form is submitted, frevvo will send an email message with the form submission data and XML documents attachments containing the submitted data.

    Image:email_xml.png

    If you are using the Standard Edition, supply an email address in the EMail Results property field. frevvo will send an email message with only the form submission data.

    Image:email_standard.png

    The email address is limited to a single address. If you require more than a single recipient, set the address to an email group. The email address may either be a static address such as info@frevvo.com or a dynamic address by using template syntax such as {person}@frevvo.com if you want the name dynamic and the domain static or {emailAddress} to make the full email address dynamic.

    Here is an example using the dynamic template {emailAddress}. You must set one of your form controls to have the typeId emailAddress.

    Step 1 First set a typeId on one of your controls.

    Image:email_step1.png

    Step 2

    Second, use that typeId as the template in the form properties.


    Image:email_step2.png


    Also you can use a template with static text such as: {name}@frevvo.com. Here the value in your form field whose typeId is "name" would replace {name}. If the user enters "Joe" into the name form field the submission would be emailed to Joe@frevvo.com.

    Email Submission Formatting

    The form submission data is formatted by default as shown in the image below. The formatting can be customized as required. Contact frevvo client services for more details on how to customize your email output.

    Image:submission_email.png

    Integrating with your database

    frevvo provides a simple connector that integrates forms with your database. The connector is freely available for download and is licensed under an open source model. The documentation can be found at Connecting with your database.

    Integrating with web services

    Multi page forms

    You can forward the user from one frevvo form to another by specifying the URI of the second form in the form action for the first. For example, suppose you have two forms in your application. One named formA and the other named formB. When the user clicks the submit button on formA you want them to next see formB. In formA you open the form's edit properties and set the form action to "Go to URL" and in the URL property field you put the URI for formB.

    This URI can be found by clicking the Image:application_form_add.gif Embed icon for your form on the Forms list page.

    Here is an example of a form's URI:

    http://www.frevvo.com/frevvo/web/user/myUser/app/_uJKtwbesEduG2Me8fheS4Q/formtype/_18go4Lx7EduG2Me8fheS4Q?_method=POST
    

    For portability, we recommend you use relative URIs such as:

    ../../../app/_uJKtwbesEduG2Me8fheS4Q/formtype/_18go4Lx7EduG2Me8fheS4Q?_method=POST
    

    It is important that both frevvo forms have been made public. If formA is public but formB is not, when the user submits formA they will get a page not found error.

    Personal tools