CS 635 Advanced Object-Oriented Design & Programming Spring Semester, 2004 Model-View-Controller part 2 |
||
---|---|---|
© 2004, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 20-Apr-04 |
Transform View
A view that processes domain data elements by element and transforms them into HTML
Given a domain object, MusicAlbum, how to generate a web page for the object?
Converting object into html
One could add toHtml to the object
MusicAlbum ragas = new MusicAlbum.find(“Passages”); String html = ragas.toHtml();
Transform View Verses Template View
Template View
More tools support
No language to learn
Transform View
Easier to avoid domain logic in view
Testing can be done without Web server
Easier to make global changes to Web site
Context Object
Problem
Avoid using protocol-specific system information outside its relevant context
Forces
public class AlbumController extends ActionServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
Solution
Use Context Object to encapsulate state in a protocol-independent way to be shared throughout the application
Application Controller
Action management – map a request to an action that handles request
View management – locate and use the correct view
Problem
Centralize & modularize action and view management
Forces
Structure
When to use it
When web pages should be visited in particular order
Different views are used depending on the state of objects
Continuation-Based Web Servers
Seaside
http://beta4.com/seaside2/
Free with source
Example
ContinuationExample Subclass of WAComponent
renderContentOn: html html title: 'Continuation Example'. html heading: 'The First Page'. html anchorWithAction: [self tryMe] text: 'Start'
tryMe | name count message | name := self request: 'Your name'. count := 1. message := name , ' ready to stop yet? '. [self confirm: message , count printString] whileFalse: [count := count + 1]. self inform: 'Good bye'
Java Psuedocode
renderContentOn(WAHtmlRenderer html) { html.title(”Continuation Example”); html.heading(”The First Page”); html.anchorWithAction( tryMe, “Start”); } tryMe() { String name = request(”Your name”); int count = 1; String message = name + “ ready to stop yet”; while ( !confirm( message + count) ) { count = count + 1; } inform( “Good bye”); }
Wafer Project
Metric |
Java
Struts
|
Seaside |
Development
Time
|
1-2
weeks
|
~6
hours
|
Size |
4
MB
|
26
KB
|
Files |
155 |
1 |
Source
Size
|
159
KB
|
26
KB
|
Classes |
36 |
12 |