SDSU CS 635 Advanced Object-Oriented Design & Programming
Spring Semester, 2004
Model-View-Controller part 2
Previous    Lecture Notes Index    Next    
© 2004, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 20-Apr-04


References


Patterns of Enterprise Application Architecture, Folwer, 2003, pp 330-386

Core J2EE Patterns: Best Practices and Design Strategies, 2nd, Alur, Crupi, Malks, 2003



Doc 17, Model-View-Controller part 2 Slide # 2

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?





Doc 17, Model-View-Controller part 2 Slide # 3
Converting object into html

One could add toHtml to the object

MusicAlbum ragas = new MusicAlbum.find(“Passages”);
String html = ragas.toHtml(); 




Better use XML and XSLT


Now we can produce many different views of the object without changing the object

Doc 17, Model-View-Controller part 2 Slide # 4
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


Doc 17, Model-View-Controller part 2 Slide # 5

Context Object


Problem

Avoid using protocol-specific system information outside its relevant context

Forces




Example

public class AlbumController extends ActionServlet {
   public void doGet(HttpServletRequest request, 
         HttpServletResponse response)
         throws IOException, ServletException {

HttpServletRequest & HttpServletReponse contain protocol specific information and API


Doc 17, Model-View-Controller part 2 Slide # 6
Solution

Use Context Object to encapsulate state in a protocol-independent way to be shared throughout the application





Doc 17, Model-View-Controller part 2 Slide # 7

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



Solution

Use an Application Controller to centralize retrieval and invocation of commands and views

A centralized point for handling screen navigation and the flow of the applications

Doc 17, Model-View-Controller part 2 Slide # 8
Structure



When to use it

When web pages should be visited in particular order

Different views are used depending on the state of objects



Doc 17, Model-View-Controller part 2 Slide # 9

Continuation-Based Web Servers


http://wiki.cocoondev.org/

http://www.beta4.com/seaside2/

http://www.plt-scheme.org/

http://sisc.sourceforge.net/


Doc 17, Model-View-Controller part 2 Slide # 10
Seaside

http://beta4.com/seaside2/

Free with source
http://segment7.net/projects/ruby/borges/index.html

Runs on:

Runs standalone or behind:



Doc 17, Model-View-Controller part 2 Slide # 11
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'


Doc 17, Model-View-Controller part 2 Slide # 12
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”);
}


Doc 17, Model-View-Controller part 2 Slide # 13
Wafer Project



Wafer Web Blog Implementation

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


Copyright ©, All rights reserved.
2004 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.

Previous    visitors since 20-Apr-04    Next