Skip to content

Commit fc74f3b

Browse files
more doc fixes.
1 parent 7283a51 commit fc74f3b

1 file changed

Lines changed: 32 additions & 13 deletions

File tree

README.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@ The design of this example differs in two significant ways from the traditional
3737
Steps to understanding the system
3838
---------------------------------
3939

40-
**Play with the running application.**
40+
**Run the application.**
4141

4242
Begin by downloading the code, invoking "play run" in your shell, then retrieving http://localhost:9000
43-
to retrieve the single form as illustrated at the top of this page. The form displays the fields
43+
to display the single form illustrated at the top of this page. The form displays the fields
4444
associated with a "Student": Name, Password, Hobbies, Level, GPA, and Majors. Some of these
45-
are required, some are optional. Try filling out the form in both valid and invalid ways.
46-
45+
are required, some are optional. Try filling out the form in both valid and invalid ways and
46+
pressing Submit to see what happens.
4747

4848
When you submit a valid version of the form, the system will redisplay the form with exactly the
49-
same data that you entered.
49+
same data that you entered, and also show a representation of the Student model instance
50+
created from the form values.
5051

5152
**Run the tests.**
5253

@@ -71,7 +72,7 @@ to invoke the test cases. You should get output similar to the following:
7172

7273
We'll come back to this later, but this step verifies that tests run correctly in your environment.
7374

74-
**Review the controller.**
75+
**Review the controllers.**
7576

7677
Now review the controller class. [Application](https://github.com/ics-software-engineering/play-example-form/blob/master/app/controllers/Application.java)
7778
has just two methods: getIndex() which displays the form in the index page and postIndex() that processes a form submission
@@ -111,11 +112,7 @@ is where things get most interesting. The [main](https://github.com/ics-softwa
111112
and [index](https://github.com/ics-software-engineering/play-example-form/blob/master/app/views/index.scala.html)
112113
templates are pretty much what you'd expect.
113114

114-
Note that the main template imports JQuery which is needed for Bootstrap Javascript components and not normally shown
115-
in the built-in Play examples. What is really not shown in the built-in Play examples is the
116-
fact that in order to test your code with HTMLUnit, you cannot use a version of JQuery more recent than 1.8.3.
117-
Look at [Build.scala](https://github.com/ics-software-engineering/play-example-form/blob/master/project/Build.scala#L17-19)
118-
to see how to load a newer version of Bootstrap with an older, HTMLUnit-compliant version of JQuery.
115+
Note that the main template shows how to import JQuery in case you want to use Bootstrap Javascript components.
119116

120117
The second thing to review is the [views.bootstrap](https://github.com/ics-software-engineering/play-example-form/tree/master/app/views/bootstrap)
121118
subpackage, containing Bootstrap 2.x Scala templates for various form controls. Kudos to [Jason
@@ -125,20 +122,42 @@ Finally, the [views.formdata](https://github.com/ics-software-engineering/play-e
125122
subpackage contains the single backing class ([StudentFormData](https://github.com/ics-software-engineering/play-example-form/blob/master/app/views/formdata/StudentFormData.java)) required for this application.
126123
Note that the backing class consists of public fields containing the String data to be displayed/bound in the form,
127124
as well as a validate() method that determines if the submitted form data is valid or not.
125+
126+
**Review the tests.**
127+
128+
Testing is pretty straightforward, uses [Fluentlenium](https://github.com/FluentLenium/FluentLenium#what-is-fluentlenium-), and implements the
129+
[page object pattern](https://github.com/FluentLenium/FluentLenium/wiki/Page-Object-Pattern).
130+
131+
Start by looking at [IndexPage](https://github.com/ics-software-engineering/play-example-form/blob/master/test/tests/pages/IndexPage.java).
132+
This class implements a bunch of methods to fill out the form and check to see whether the
133+
displayed form contains a success or error message. Note that most of these methods depend upon
134+
finding an HTML element with a specific ID, and so the Bootstrap Scala templates need to make
135+
sure these ID fields are set correctly.
136+
137+
The actual test code is in [ViewTest](https://github.com/ics-software-engineering/play-example-form/blob/master/test/tests/ViewTest.java).
138+
There are four tests: one that just checks that we can retrieve the page, one that tests that
139+
submitting an empty form generates a validation error, one that submits a form filled out
140+
from a valid Student ID, and a final one that fills out a valid form manually by using the
141+
IndexPage methods.
142+
143+
Getting tests to work exposes an unfortunate library versioning issue: HTMLUnit requires
144+
a version of JQuery no later than 1.8.3, while recent versions of Twitter Bootstrap
145+
have a Maven dependency of JQuery 1.9.0. [Build.scala](https://github.com/ics-software-engineering/play-example-form/blob/master/project/Build.scala#L17-19)
146+
illustrates how to load a newer version of Bootstrap with an older, HTMLUnit-compliant version of JQuery.
128147

129148
Issues
130149
------
131150

132151
While this code works and is pretty easy to understand, there are at least two design problems with it
133152
that I can see:
134153

135-
* Verbosity. It's kind of a drag to have two representations for a Student, one as a model and
154+
* **Verbosity.** It's kind of a drag to have two representations for a Student, one as a model and
136155
one as a backing class for forms. I know that I presented this as a feature, but at the end
137156
of the day it's born of necessity. Perhaps there exists an elegant way to implement composite entities
138157
(i.e. a Student that contains a List of Hobbies) in which display, binding, and validation
139158
can be done easily and understandably with a single class.
140159

141-
* Integrity. The current code encapsulates validation in the StudentFormData class, and certain
160+
* **Integrity.** The code provides validation in the StudentFormData class, and certain
142161
methods (such as Student.makeInstance) must assume that they are being passed a valid
143162
StudentFormData instance. That kind of assumption is worrisome, and annotation-based
144163
constraints could avoid it. Annotation-based constraints also offer the potential

0 commit comments

Comments
 (0)