Dynject comes with built-in support for extracting the values to be processed from the parameters on an HTTP Request. You can optionally specify that the parameters coming from the browser have a common prefix (useful for JSF-style applications, where the Container ID is prepended to the ID of the parameter).
In this example, we will reuse exactly the same Customer class from the Swing example. Your annotated POJO stays the same no matter in which context it is used.
You will usually have some kind of web form to let the user enter the values of the POJO properties:
Where the "Send" button invokes some Servlet. Well, reading and validating the user input in the corresponding servlet is as easy as:
Customer customer = new Customer();
ErrorMap errorMap= Shell.assign(customer, new HttpRequestSource(request));
Again, the assign method extracts all needed properties, validates the data, generates errror messages for those pieces of data that are incorrect and stores the correct ones into the appropriate fields, performing whatever conversions are necessary to match the data types (for example, from String to Calendar as in the case of birthdate).
The requirement for this to work automatically is that the names of the input fields be the same as the names of your properties. I.e. - the HTML text field that is used to enter the customer name must be called customer, and so forth.
Here are the sources for the full example:
And here's a sample result :
