Practice WOD: DigitsForm

Prior to doing this WOD, you should have reviewed all the material in the Resources section of this module and watched the screencasts.

Next, create a new branch off of a successfully completed branch from the first WOD. Name this new branch “Attempt-N-1″, where N is the original branch you’re going to base this WOD on. For example, if the branch “Attempt-2″ contains the code base that you want to build this WOD on, then create a branch called “Attempt-2-1″ to indicate that this is the first attempt (1) to extend the code from “Attempt-2″ to support form processing.

Instructions

Convert your form mockup into a dynamic form following the four step process outlined in the screencast.

  1. Start your timer.
  2. Create a Java backing class for the form data. Call this views.formdata.ContactFormData. Provide three public String fields: firstName, lastName, and telephone, each with a default value of an empty string.
  3. Make the view dynamic. Edit the parameter list to accept a form called contactForm. Add the @import helper._ statement. Replace the <form> element with a call to the @form scala template. Replace the name, id, and value attributes of the elements with calls to to the contactForm parameter.
  4. Handle the form in the controller. Modify the controller method handling the GET request to pass an empty form object to the view template. Add a new controller method to handle the POST request from the user. The implementation of this method should get the form data, then print it out to the Play console.
  5. Support the POST request in the routes file. Update the routes file to allow a POST request from the user.
  6. When finished, clicking the Add button after adding data to your NewContact page should print out the data in your Play console.
  7. To end the WOD, commit the working code to your branch.

When finished, stop your timer, and record how many minutes it took you to complete the WOD.

Rx: <20 min Av: 20-30 min Sd: 30-40 min DNF: 40+ min

Demonstration

Once you’ve finished doing the WOD a single time, watch me do it:

Standard WOD Caveats

You’ll learn significantly less from watching me solve the WOD if you haven’t attempted the WOD yourself first.

While it’s an achievement to finish the WOD no matter how long it takes, you might experience “diminishing returns” if you work longer than the DNF time. Thus, it might be strategic to stop working at the DNF time and watch my solution.

After watching my solution, I recommend that you repeat the WOD if you have not achieved at least Av performance. If so, be sure to:

Feel free to keep trying until you make Rx if that’s of interest to you.

How to repeat the WOD

To repeat the WOD, simply switch your local workspace branch to master, then create a new branch off of master called “Attempt-2″ (or whatever attempt you are on). Then, in the play console, type ; clean ; compile ; run to clean the target directory, then recompile the system, then run the web application.