Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Section
Column

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.

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.

Column
width240px

On this page:

Table of Contents
maxLevel1

 

 

 

Document URIs

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

...

ResourceMethodDescriptionReturns
Customer ListGETList of customers (may be criteria basedXML list of customers
Customer ListPOSTCreate new customerURI of newly created customer
CustomerGETGet customer dataXML representation of customer
CustomerPUTUpdate customer 
CustomerDELETERemove customer 

Updating a document

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

...

  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,  product name macro will store the generated document set and assign it a unique URI. The document set and the documents therein can be accessed at this URl.

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 URl . When the form is used (instantiated),  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,  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:

...

Here is an example form 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 Name. Consider the Updating a document example above and the sample form therein.

...

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.

...

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, 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.  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,  will automatically PUT the resulting XML document to the URI for the newly created customer thereby updating the customer.

...