View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

milestone 5

Project 5 was a continuation of the web interface modification to the newspaper generator. There's a funny story that goes along with this project (and the last). Basically we ended up over-building the project, and now it does more than it was required to do.

The requirements for this milestone were to support remote de-selection of news topics. Somehow within the ranks of Team Fox Force Five, this requirement got translated to "the web interface must be able to do everything". By the time we had things straightened out, the gears were already in motion. And once Team Fox Force Five gets rollin' there's no stopping us. So full remote, web-based functionality it was. Here's how we did it:

Getting the user input.

OK, in the last project we had settled on using lists and radio buttons for the sources/topics and primary categories respectively. We we're pretty sure that we could transmit the data this way, but the details on how it was transmitted, and how we would handle it were sketchy.

What we found out was that when the user clicked on an input button, the data arrived at our servlet via the request object. To be specific the request object held a dictionary named reqFields. The dictionary held the selected item keyed by the name that we had given to the selected item when composing the HTML.

So what can I do for you?

OK, here's the tricky part. If we had done this project like we were supposed to, then there'd be no doubt what the user wanted when they made a submission: they'd want to remove a previously added news topic.

But nooooo... we had to complicate the issue. Since we were aiming for full functionality, the user could now desire several different actions. They could want to:

Actually, there's a fifth one too: generate the paper. But that was being handled by a hyperlink rather than an input button.

So the big question was "How do we know what action the user wants performed"?

Couldn't we just use hyperlinking like we did for the generate paper? No, that wouldn't even transmit the information about what's been selected.

Couldn't you determine from the way the value was keyed in the reqFields what the user wants? Yes, that's a possibility. We could give each functionality's input a different key value. For instance, all the values on the "primary news category" list could be keyed by the value "primaryCategory". Then when the servlet recieves the request we can just check to see if there's a value keyed by the string "primaryCategory"; If there was, then the action they wanted was obviously to select this new primary category.

But the whole idea of cycling through all the possible key values seemed a little hokey. If we ever wanted to add a new feature, we'd have to go back and check for that value too. Besides, we had a better idea.

The Hidden Field

Ahh yes, the hidden field. What we ended up doing is including a hidden field with each form on the menu. The name of the hidden field was always the same: "action". The value of the field was different for each form however. For instance, the source list had a hidden field with the value "selectSource:", and the primary news category's was "selectPrimary:". Notice those colons there? They almost look like Smalltalk selectors don't they?

Lets take a look at the code:
self perform: (request fields at:'action') asSymbol with: request fields.

So what's going on here? Well, "request fields at:'action'" returns that hidden value discussed above such as 'selectPrimary:'. "asSymbol" takes that string and turns it into a symbol i.e. an action that can be performed. Now when we call "self perform:with:" the NPWebInterface performs that method with the name of the symbol and passes in, as a parameter, all of the fields. Now its simply a matter of writing those methods, and tada! No cycling, and you get the super-fast look up of a hashtable.

Link to this Page