Ajax Patterns And Best Practices (2006)
.pdf■P
Parent implementation, 356
Parent interface, implementing, REST-Based Model View Controller pattern
implementing asynchronous Parent interface instance, 359–360
implementing Base Class, 357–358
implementing synchronous Parent, 360–361
overview, 357
ParentBase class, 357
ParentBase.processRequest method, 361
parentElement property, HTML element, 69
parseElement function, 215, 219
parseHeaders method, 366
Passive caching, 81
password property, 237
pattern implementation, 221
permission exception, 164
Permutations pattern, 150, 233, 269, 277, 337
applicability, 116
architecture. See also book application example
overview, 116
resource separation from representation, 117–118
using cookies and HTTP authentication to authorize access, 119–122
associated patterns, 116
highlights of, 150–151
implementation, rewriting, 293–295
purpose of, 111–114, 116
rewriting URLs
generating content, 134
implementing details of, 130–134
overview, 128–129
using Accept header on client side, 135
shopping cart application example. See also shopping cart application example
PermutationsServlet class, 365, 367
■I N D E X |
379 |
Persistent Communications pattern, 116, 159, 203, 304–305, 308, 335, 337, 341, 362–363
applicability, 227–228 architecture
and change in Internet architecture, 228–231
implementing polling solution, 231–232 overview, 228
associated patterns, 228
calling ServerCommunicator intelligently, 244–246
implementation
global status resource example, 233–248 overview, 233
performance considerations, 262 presence detection example, 248–252 server push example, 252–261 version numbers and updates, 262
implementing ClientCommunicator, 236–241
implementing HTML page, 233–236
implementing ServerCommunicator, 241–244
implementing server-side monitoring process, 247–248
overview, 233
pattern highlights, 262–263 purpose of, 225–227
Persistent Communications patterns, 339 Personal Information grouping, 211 plain-vanilla web application, 16 platform-neutral languages, 14
POP3 (Post Office Protocol), 231 PopupDialogBox function, 189 PopupDialogbox function, 192 Post Office Protocol (POP3), 231 postURL data member, 285 predictive cache, 91, 109 Predictive caching, 82 preferredTypes property, 237
380■I N D E X
prefetch function, 93, 95–96, 98 presence detection
authenticating user, 248 overview, 248
updating ServerCommunicator, 248–252 presentation function, 161, 177 Presentation functionality, 196 presentation parameter, 176 previousSibling property, HTML element, 69 price comparison services, 111
prime number algorithm, 308 PrimeNumber tag, 321 PrimeNumberHandler class, 318–319 PrimeNumberHandler directory, 308
PrimeNumberHandler.ProcessRequest method, 320
PrivateLoop function, 239, 242 processElement function, 216, 219 ProcessRequest method, 319 processRequest method, 352, 358, 361, 363 processResults method, 349
ProcessTasks method, 327 prop property, 206 prototype property, 37, 239
prototype.instances property, 239 Proxy pattern, 82, 338
■Q
q value, 126
Query variable, Amazon.com, 347 queryIdentifier variable, 350
■R
reactional server, 247 Read-mostly data, 233 readyState property, 33, 43
reference property, dynamicFiller variable, 76 Remote Procedure Calls (RPCs), 25 Representation interface, 364
Representation Morphing pattern, 224, 268, 283. See also Representation Morphing pattern implementation
applicability, 202–203
architecture
basic theory, 204–205
defining blocks of state, 206–211
overview, 203–204
why pattern is not HTML component, 205–206
associated patterns, 203
pattern highlights, 224
purpose of, 197–202
Representation Morphing pattern implementation, 221–224
implementing framework, 211–213
implementing representation reference points
JavaScript representation reference point, 213–218
overview, 213
XSLT representation reference point, 218–220
overview, 211
Representational State Transfer (REST)
architecture style, 11
representation.canProcess method, 366
_representations data member, 366
req.getParameter method, 104
Request interface, 352
request parameter, 293
request.complete method, 291
request.getInputStream method, 242
resetAssignedHashCode method, 90
Resolve method, 141
Resource method, IUserIdentificationResolver interface, 137
Resource to Representation layer, 281
_resourceStateContentType data member, 296
response parameter, 293
responseText property, 23, 26, 69
responseXML parameter, 314
responseXML property, 26, 69
REST (Representational State Transfer)
architecture style, 11
REST data, 21–22
REST theory, 19–21
REST-Based Model View Controller pattern, 181. See also REST-Based Model View Controller pattern implementation
applicability, 335
architecture
defining appropriate resource, 338–340
defining calling interface, 340–343
defining data format foundation and extras, 343–346
overview, 336–338
associated patterns, 335–336
pattern highlights, 367–368
purpose of, 333–334
REST-Based Model View Controller pattern implementation
creating search engine client infrastructure
defining abstracted REST-Based Model View Controller pattern, 352–353
implementing search abstractions, 353–356
overview, 350–352
handling asynchronous search
implementing servlet-based Permutations pattern, 364–366
overview, 361, 364
posting query, 361–363
processing request, 367
retrieving result, 363–364
implementing Parent
implementing asynchronous Parent interface instance, 359–360
implementing Base Class, 357–358
■I N D E X |
381 |
implementing synchronous Parent, 360–361
overview, 357 implementing search
overview, 346
using Amazon.com for searching, 346–349
using Google for searching, 349–350 overview, 346, 357
Result element, XML, 312
Result interface, 352
_results data member, 326, 330, 359 return keyword, 168
rewrite component, 128 Rewriter interface instance, 294 rewriter parameter, 295 rewriting URLs
generating content, 134 implementing details of, 130–134 overview, 128–129
using Accept header on client side, 135 rich-client local installation, 14–15 rich-client web services, 15–16
root resource definition URL, 258 root URL, 118
RouterASPNet class, 130 routing component, 127
RPCs (Remote Procedure Calls), 25 runat attribute, 254
runFilter method, 293, 298 runIt function, 238 Runnable interface, 353
_runningThreads data member, 358 RunThreadedTasks method, 321, 326
■S
same origin policy, 23, 333 saveForm method, 283, 288–289 saveState method, 283, 290 screen scraping, 111
382■I N D E X
script element, 213
script tags, 30, 93, 235, 311 script-defined passive cache, 95 /search identifier, 339
/search URL, 181 SearchBuilder class, 354, 361 SearchRequest interface, 356 SearchResult interface, 356
Secure Shell (SSH) console window, 134 send method
ClientCommunicator, 240 XMLHttpRequest, 25
serialization, of XML documents, 323 Serialization.Generate method, 324 Serialization.Parse method, 324 Serializer implementation, 325 server framework, 109
server push implementation
completing ServerCommunicator, 256–261
overview, 252 specifying URLs
overview, 253
using hard-coded URL, 253 using HTTP redirection, 255–256 using user identification, 253–254
server2client property, 237 ServerCommunicator
calling intelligently, global status resource example, 244–246
completing, server push example, 256–261
implementing, global status resource example, 241–244
updating, 248–252 ServerCommunicator type, 232 ServerPush class, 257 server-side caching, 86–88 server-side code, 91 server-side framework, 88 server-side libraries, 145
server-side monitoring process, 247–248 service method, 250, 259
Servlet interface, 250 Session variable, 147, 362 setAttribute method, 223 SetCacheability method, 83
setConfiguration method, 295 Set-Cookie HTTP header, 146 SetExpires method, 83 setInterval method, 45 setQueryString method, 349
setRequestHeader method, XMLHttpRequest class, 25, 97, 135
setRootPath method, 103 setTimeout method, 44, 238–239 shopping cart application example
defining user identification interfaces, 136–137
HTTP authentication
authenticating when not necessary, 143–145
how functions, 137–139 implementing, 139–143 overview, 137
HTTP cookies
generating cookie, 145–146 how client manages, 146 identifying user with, 146–148 overview, 145
implementing shopping cart, 148–150 overview, 135–136
ShowContent function, 218 signature variable, 348
Signature.generateSignature method, 348 Simple Object Access Protocol (SOAP), 15, 335 single-shot display strategy, 226 SingleThreadModel interface, 246 Slashdot, 199
sleep() method, Thread class, 246 snippet content, 344
SOAP (Simple Object Access Protocol), 15, 335 Sort method, Array class, 131
span elements, 215, 217, 219–220, 313 span HTML tags, 208
span innerHTML property, 216–217 span tag, 22, 73
spanElement variable, 314 spanElement.innerHTML property, 314 Specialization interface, 351
src attribute, 70, 72, 74, 235 srcElement property, 167
SSH (Secure Shell) console window, 134 stale result, 314
StartIt function, 44
StartItNonEnding function, 45
State Filter layer, 281
state identification, 204 state identifier, 290
State interface instance, 301 state keyword, 277, 298
State Navigation pattern, 163, 181, 203, 319. See also State Navigation pattern implementation
applicability, 267 architecture
extending solution for web application, 272–276
managing state at protocol level, 277–280
moving toward ideal solution from user’s perspective, 268–270, 272
overview, 268 associated patterns, 268 pattern highlights, 301 purpose of, 265–267
State Navigation pattern implementation overview, 280–281
processing requests on client
details of State Navigation, 284–291 overview, 281–282
using State Navigation from HTML page, 282–284
■I N D E X |
383 |
processing requests on server
HTTP filters, when and how to trigger, 291–293
implementing State layer, 295–301 overview, 291
rewriting Permutations pattern implementation, 293–295
state object, 140, 215–216 state property, 177 /state URL, 181
StateController variable, 284, 288 StateController.loadState( ) method, 283 StateController.saveState( ) method, 283 StateFilter class implementation, 301 StateIdentifier property, 300 _stateManager data member, 296 StateManager interface, 300 _stateManager variable, 300 state.setBuffer method, 299
static GUI link, 153
static HTTP validation, 88–89, 103–104 static method, 118
static programming techniques, 206 static random transaction identifier, 313 static URL, 88
static user interfaces, 200 static validation, 88
staticHashCode data member, 90 status parameter, 95
status property, 26 status updates, 227 statusText property, 26
Stream Aggregator pattern, 82 style property, HTML element, 69 super.processRequest method, 361 super.service method, 250
switch statement, 32 synchronization techniques, 360 synchronized keyword, 359 synchronous form, 335
384■I N D E X
synchronous interface, 343 synchronous requests, 342 SynchronousParent class, 360 SynchronousServlet class, 367
■T
tabIndex property, HTML element, 69 table element, 167, 311
tagName property, HTML element, 69 tail variable, 298
target attribute, 163 target property, 167
task implementation, 307 Task Manager implementation
calling interface implementations multiple types, 322–325 overview, 318–320
retrieving results, 321 sending tasks, 320–321 defining interfaces, 316–317 implementing task, 330–331
overview, 316
packaging implementations, 317–318
understanding details of Task Manager, 325–330
task transaction identifier, 313 task variable, 327 task.Execute method, 327 taskManager parameter, 316 taskManager variable, 320
taskManager.GetResultWait method, 321 TaskManagerImpl class, 325
td element, 73, 167 tempReference variable, 240 TestTable button, 65 text-based browsers, 112 TextState class, 181
text/xml MIME type, 126, 344
this keyword, 37 this object, 327 this variable, 95
thisReference.verifyWindowName method, 288
this.verify method, 286 this.xmlhttp variable, 39 thrd variable, 361
_thread data member, 325, 327 ThreadPool, 328
tilde character (~), 119–120 title attribute, 218
Title child tag, 124 transaction identifier, 307, 312
TransactionIdentifier child element, 322 _transactionIdentifier data member, 331 TransactionIdentifier element, XML, 312 transactionIdentifier parameter, 315 TransactionIdentifier property, 316, 331 TriggerFilter class, 293, 295
try catch exception block, 98 type attribute, 323
■U
Uniform Resource Locators. See URLs URL /account, 118
url parameter, 23
URL request variables, 340
URL-encode, 348
URLRewriterASPNet class, 129
URLs (Uniform Resource Locators), 21, 123
chunking, 69–70, 72
defining, 123–125 rewriting, 122, 128
generating content, 134 implementing details of, 130–134 overview, 128–129
using Accept header on client side, 135
specifying overview, 253
using hard-coded URL, 253 using HTTP redirection, 255–256 using user identification, 253–254
UseIt.Method, 118 user data member, 249
user identification, 251, 253–254
user identification interfaces, 136–137 User Identification layer, 281
user interaction link, 156 user interface toolkit, 24 user variable, 259 userComplete method, 98
user-friendly component updates, 201 UserIdentification constructor, 140 userIdentification data member, 249 UserIdentification interface, 248 UserIdentificationResolver interface, 248 userIdentifier property, 257
username property, 237 _users data member, 249 UserState class, 257 UserState object instance, 259
■V
ValidationLibrarianServlet class, 108 value attribute, 204
value variable, 206, 238 variable counter, 44 variable instance, 284 version property, 257 versionTracker property, 245
■W
W3C (World Wide Web Consortium), 62 W3C HTML Document Object Model, 62 wait function, 360
WAP (Wireless Access Protocol), 112 web application framework, 20
■I N D E X |
385 |
Web Services Description Language (WSDL),
16, 349
WhoisOnline class, 248, 250 wiki, 203
Wikipedia project, 1 window.setTimeout method, 44, 238 window.XMLHttpRequest object, 29 Wireless Access Protocol (WAP), 112 World Wide Web Consortium (W3C), 62 WriteRedirection method, 134, 295
defaultRewriter, 131 IRewriter interface, 129
URL rewriter component, 129, 131
WSDL (Web Services Description Language),
16, 349
WWW-Authenticate, HTTP header, 139
■X
XHTML, 59
XML (Extensible Markup Language), benefits of, 12
XML schemas, 322
XMLContent type, addRepresentation method, 367
xmlhttp variable, 23, 30 XMLHttpRequest
calling domains other than serving domain
Apple Safari, 46
Microsoft Internet Explorer, 47–49
Mozilla Firefox, 49–51
overview, 45–46
implementing asynchronous calling mechanism
Asynchronous class, 36–37, 39–43 modified Ajax application, 34–36 overview, 34
problem of multiple requests and multiple callbacks, 37–38
providing feedback from asynchronous requests, 43–45
overview, 34
386■I N D E X
XMLHttpRequest class, 28–29, 34, 58–59, 69, 91, 142, 146, 159, 163, 173, 255, 274, 277, 283, 333
XMLHttpRequest instance, 232 XMLHttpRequest type, 19, 51, 270 XMLHttpRequest.open method, 96 xmlhttp.setRequestHeader method, 288 XMLIterateElements function, 288, 291, 324 xmlParse function, 220
X-Page-State, HTTP header, 277 _XPageState data member, 296 X-Page-State HTTP header, 275 X-Page-Window-Name, HTTP header, 277 X-query-identifier, HTTP header, 343
xsd.exe command-line utility, 323
xsl, 220
template element, XML, 220
text tags, 220
XSLT (Extensible Stylesheet Language
Transformations), 60, 218
XSLT representation reference point, 218–220
xsltFromSpan identifier, 219
xsltProcess function, 220
X-Version-ID, HTTP header, 245
■Z
zooming controls, MapQuest application, 79
