Front cover......Page 1
brief contents......Page 7
contents......Page 9
preface......Page 21
acknowledgments......Page 23
Roadmap......Page 24
Who should read this book?......Page 26
Software requirements......Page 27
Author Online......Page 28
about the cover illustration......Page 29
Part 1 – Getting started with portlet development......Page 31
Introducing portals and portlets......Page 33
1.1 What is a portal?......Page 34
1.2.1 Enriched user experience......Page 36
1.2.2 Unified information view......Page 39
1.3 What is a portlet?......Page 40
1.4.1 Inter-portlet communication vs. inter-servlet communication......Page 42
1.4.2 Portlets vs. widgets......Page 43
1.5.1 The portlet container......Page 45
1.5.2 The portal server......Page 46
1.6.1 Installing Liferay Portal 6.x......Page 48
1.6.2 Registering users with Liferay Portal......Page 50
1.6.3 Creating a public portal page in Liferay Portal......Page 51
1.6.4 Adding portlets to a Liferay Portal page......Page 53
1.6.5 Roles and permissions in Liferay Portal......Page 54
1.7.1 Configuring Eclipse IDE......Page 56
1.7.2 Setting up the project structure......Page 64
1.8.1 Creating a Hello World portlet......Page 65
1.8.2 Building the Hello World project with Ant......Page 69
1.8.3 Building the Hello World project with Maven......Page 72
1.8.4 Adding the Hello World portlet to a portal page......Page 73
1.9 Summary......Page 76
The portlet lifecycle......Page 78
2.1 Requirements for the User Registration portlet......Page 79
2.2.1 Portlet and servlet containers......Page 81
2.2.2 Portlets-web components with multiple request-processing phases......Page 82
2.3.1 Portlet URLs vs. servlet URLs......Page 84
2.3.2 Portlet URL types......Page 86
2.4.1 Creating portlets with the Portlet interface......Page 87
2.4.2 Creating portlets with the GenericPortlet class......Page 90
2.5 Generating portlet content based on portlet mode......Page 92
2.5.1 Writing content generation methods for each portlet mode......Page 94
2.5.2 Defining support for portlet modes......Page 97
2.6 Portlet development in depth......Page 98
2.6.1 The Portlet API objects......Page 99
2.6.2 Creating JSPs to display portlet content......Page 100
2.6.3 The portlet deployment descriptor......Page 102
2.6.4 Dispatching portlet requests using the PortletRequestDispatcher......Page 103
2.6.5 Internationalization and localization using resource bundles......Page 105
2.6.7 Creating portlet URLs......Page 106
2.6.8 Container-runtime options......Page 108
2.7 Implementing the User Registration portlet......Page 110
2.7.1 The UserRegistrationPortlet class......Page 111
2.7.2 JSP pages......Page 114
2.8 Summary......Page 115
Portlet 2.0 API- portlet objects and container-runtime options......Page 116
3.1 Requirements for the Book Catalog portlet......Page 117
3.2.1 Portlet request objects and lifecycle interfaces......Page 122
3.2.2 PortletRequest constants......Page 124
3.2.3 PortletRequest methods......Page 127
3.2.4 Handling portal server-specific requests using PortalContext......Page 129
3.3 Portlet response objects......Page 130
3.3.1 Encoding URLs with the encodeURL method......Page 132
3.3.2 Generating content using RenderResponse......Page 133
3.3.3 Responding to an action using ActionResponse......Page 134
3.3.4 Choosing an appropriate phase for an action......Page 137
3.3.5 Adding custom JavaScript and CSS files to a portal page......Page 138
3.4.1 PortletSession object and methods......Page 142
3.4.2 PortletSession usage in the Book Catalog portlet......Page 143
3.4.3 Obtaining session attributes using PortletSessionUtil......Page 144
3.4.4 An in-depth look at portlet session scopes......Page 146
3.4.6 Similarities between HttpSession and PortletSession......Page 148
3.5 Discovering the portlet environment using PortletContext......Page 149
3.6 Retrieving portlet configuration using PortletConfig......Page 150
3.7 Container-runtime options......Page 151
3.7.1 Using actionScopedRequestAttributes......Page 153
3.7.2 Using servletDefaultSessionScope......Page 157
3.7.3 Using escapeXml......Page 158
3.7.5 Specifying Portlet and Portlet application container-runtime options......Page 160
3.8 Summary......Page 161
Portlet 2.0 API- caching, security, and localization......Page 162
4.1 Caching generated content......Page 163
4.1.1 Expiration-based content caching......Page 164
4.1.2 Validation-based content caching......Page 167
4.2 Localizing portlet content......Page 171
4.2.1 Implementing portlets to support localization......Page 172
4.3 Portlet modes in depth......Page 173
4.3.1 Custom portlet modes......Page 174
4.3.2 Portal-managed and portlet-managed portlet modes......Page 178
4.3.3 Portlet modes and markup types......Page 180
4.4 Portlet window states in depth......Page 181
4.4.1 Custom window states......Page 182
4.4.2 Portlet window states and markup types......Page 183
4.5 Programmatic security......Page 184
4.6.1 Uploading files......Page 186
4.6.2 Using wrapper classes......Page 188
4.6.3 Using the PortletURLGenerationListener interface......Page 189
4.7 Designing portable portlets......Page 191
4.7.1 Portal server features and limitations......Page 192
4.7.2 Designing for change......Page 193
4.8 Summary......Page 196
Building your own portal......Page 197
5.1 Requirements for Book Portal......Page 198
5.2 Getting started developing Book Portal......Page 200
5.2.1 Creating an organization for Book Portal......Page 201
5.2.2 Creating roles for Book Portal users......Page 203
5.2.3 Mapping roles to the Book Portal organization......Page 204
5.2.4 Creating Book Portal users and assigning them to the organization......Page 205
5.2.5 Mapping users to roles......Page 207
5.3.1 Creating a Home portal page......Page 208
5.3.2 Adding an Announcements portlet......Page 212
5.3.3 Adding an RSS feed portlet......Page 214
5.3.4 Setting permissions for portal pages and portlets......Page 215
5.3.5 Using the built-in Document Library and Book Catalog portlets together......Page 218
5.3.6 Setting permissions for displaying the book catalog......Page 221
5.3.7 Setting permissions for displaying discussion forums......Page 222
5.4 Configuring Liferay Portal server settings......Page 223
5.4.1 Setting the authentication mechanism......Page 224
5.4.2 Specifying the default user associations......Page 225
5.5 Developing with the Liferay Plugins SDK......Page 226
5.5.1 Configuring the Plugins SDK......Page 227
5.5.2 Developing portal themes......Page 228
5.5.3 Developing page layout templates......Page 233
5.6 Summary......Page 236
Using the portlet tag library......Page 237
6.1 Using the tag library to build a Book Catalog portlet......Page 238
6.2.1 Making portlet objects available with
......Page 240
6.2.2 Using in the Book Catalog portlet......Page 242
6.3.1 Using the tag......Page 243
6.3.3 Using the tag......Page 250
6.4.1 Using the tag......Page 251
6.5 Creating portlet-specific HTML elements using ......Page 253
6.5.1 When to use the tag......Page 254
6.5.2 Obtaining form field values in the portlet class......Page 257
6.6 Adding properties to URLs using ......Page 258
6.7 Summary......Page 259
Part 2 – Developing portlets using Spring and Hibernate......Page 261
Getting started with Spring Portlet MVC......Page 263
7.1 Why use Spring Portlet MVC?......Page 264
7.2.1 An e-commerce example......Page 265
7.2.2 Dependency injection and application contexts......Page 267
7.2.3 Web application contexts......Page 270
7.3 A Hello World portlet, the Spring way......Page 271
7.3.1 The Hello World portlet’s controller class......Page 272
7.3.3 The Hello World portlet’s portlet deployment descriptor......Page 273
7.3.4 The Hello World portlet’s web application context......Page 274
7.3.5 The Hello World portlet’s web application deployment descriptor......Page 275
7.4 How Spring Portlet MVC works......Page 276
7.5 Using DispatcherPortlet......Page 278
7.6.1 Naming web application context XML files......Page 279
7.6.2 Scope of beans defined in the web application context XML......Page 280
7.7 Using built-in controllers......Page 282
7.7.1 Using the Controller interface......Page 283
7.7.2 Using the AbstractController......Page 284
7.7.3 Using the ParameterizableViewController......Page 286
7.7.4 Using the PortletModeNameViewController......Page 287
7.7.5 Using the PortletWrappingController......Page 289
7.8 Using built-in handler mappings......Page 290
7.8.1 Developing a Book Catalog portlet with Spring Portlet MVC......Page 292
7.8.2 Using PortletModeHandlerMapping......Page 293
7.8.3 Using ParameterHandlerMapping......Page 294
7.8.4 Using PortletModeParameterHandlerMapping......Page 297
7.8.5 Using AbstractHandlerMapping......Page 300
7.9.1 Implementing and configuring a handler interceptor......Page 302
7.9.2 Processing requests using handler interceptors......Page 303
7.10 Handling exceptions......Page 306
7.10.1 Request handling with exceptions......Page 307
7.10.2 Mapping exceptions to a view based on the exception class......Page 308
7.11 Summary......Page 310
Annotation-driven development with Spring......Page 311
8.1 An overview of annotations......Page 312
8.2 Developing the Book Catalog portlet using annotations......Page 313
8.3.1 Identifying controllers with @Controller......Page 315
8.3.2 Classpath scanning and autoregistration......Page 316
8.3.3 Dependency injection using @Autowired and @Qualifier......Page 318
8.3.4 Dependency injection using @Resource and @Inject......Page 319
8.3.5 Mapping requests to handlers and methods using @RequestMapping......Page 320
8.3.6 Identifying render methods with @RenderMapping......Page 325
8.3.7 Identifying action methods with @ActionMapping......Page 327
8.3.8 Passing request parameters using @RequestParam......Page 329
8.3.9 Identifying model attributes using @ModelAttribute......Page 331
8.3.10 Reusing model attributes using @SessionAttributes......Page 334
8.3.12 Initializing WebDataBinder using @InitBinder......Page 337
8.4 Configuring beans that provide annotation support......Page 340
8.5.1 The Spring Validation API......Page 343
8.5.2 Validating beans with JSR 303......Page 346
8.6 Spring’s form tag library......Page 353
8.7 Unit testing with mock objects and TestContext......Page 354
8.7.1 Ant buildfile to run unit tests......Page 355
8.7.2 Unit testing with mock objects......Page 356
8.7.3 Unit testing with Spring’s TestContext framework......Page 357
8.8.1 Localizing content......Page 360
8.8.2 Adding external JavaScript and CSS files......Page 361
8.8.3 Uploading files using PortletMultipartResolver......Page 362
8.9 Summary......Page 363
Integrating portlets with databases......Page 364
9.1 Combining portlets and databases......Page 365
9.2 Exploring the Book Catalog portlet’s database tables......Page 366
9.2.2 The TOC_TBL table......Page 367
9.3 Spring’s JDBC module for database interaction......Page 368
9.3.1 Defining a data source......Page 369
9.3.2 Creating database connections......Page 375
9.3.3 Creating DAOs......Page 376
9.3.4 Creating service interface and implementation classes......Page 379
9.4 Accessing Spring beans from non-Spring objects......Page 381
9.5 AOP support in Spring Framework......Page 382
9.5.2 Using AspectJ annotations to create aspects......Page 384
9.6.1 Defining a transaction manager......Page 388
9.6.2 Specifying transactional methods......Page 389
9.6.3 Configuring annotation-driven transaction management......Page 390
9.7 Using Hibernate for database interaction......Page 391
9.7.1 Using the Java Persistence API (JPA)......Page 392
9.7.2 Mapping classes to relational database tables......Page 393
9.7.3 Connecting to a database......Page 395
9.7.4 Using Spring with Hibernate......Page 397
9.8 Summary......Page 401
Part 3 – Advanced portlet development......Page 403
Personalizing portlets......Page 405
10.1 Introducing portlet personalization......Page 406
10.2 Personalization requirements for the Book Catalog portlet......Page 407
10.3.1 Adding support for EDIT portlet mode......Page 409
10.3.2 Writing a render method for EDIT portlet mode......Page 410
10.4.1 Retrieving user preferences from the portlet request......Page 412
10.4.2 Saving portlet preferences to the persistent store......Page 413
10.5 Saving preferences with PortletPreferences......Page 414
10.5.3 Resetting preferences......Page 416
10.6 Validating preferences......Page 418
10.6.1 Validating preferences before setting them in PortletPreferences......Page 419
10.6.2 Validating preferences using PreferencesValidator......Page 420
10.6.3 Configuring PreferencesValidator in the portlet deployment descriptor......Page 422
10.6.4 Handling ValidatorException......Page 425
10.7.1 Obtaining preferences in the portlet class and JSP pages......Page 427
10.7.2 Personalizing content and behavior......Page 430
10.7.3 Defining portlet preferences in portlet.xml......Page 433
10.8 Summary......Page 434
Communicating with other portlets......Page 435
11.1 Why do you need inter-portlet communication?......Page 436
11.2 An inter-portlet communication example......Page 437
11.3 Inter-portlet communication using portlet sessions......Page 439
11.3.1 Defining multiple portlets in the portlet deployment descriptor......Page 440
11.3.2 Storing and retrieving information from PortletSession......Page 441
11.3.3 Inter-portlet communication in action......Page 445
11.3.4 Advantages and disadvantages of using PortletSession......Page 446
11.4 Inter-portlet communication using public render parameters......Page 447
11.4.1 Setting and retrieving public render parameters......Page 448
11.4.2 Methods related to public render parameters......Page 453
11.4.3 Advantages and disadvantages of using public render parameters......Page 454
11.5 Inter-portlet communication using portlet events......Page 455
11.5.1 Sending portlet events......Page 457
11.5.2 Receiving portlet events......Page 462
11.5.3 Advantages and disadvantages of using portlet events......Page 465
11.6 Summary......Page 466
Ajaxing portlets......Page 467
12.1 Ajax basics......Page 469
12.2 Your first Ajax portlet......Page 470
12.2.2 Sending Ajax requests using the XMLHttpRequest object......Page 472
12.2.3 Handling Ajax requests using portlet or servlet components......Page 474
12.2.4 Retrieving the servlet response to update portlet content......Page 475
12.3.1 Date/Time portlet’s security requirements and possible solutions......Page 477
12.3.2 Implementing security using portal server-specific APIs......Page 478
12.4.1 Serving resources using the ResourceServingPortlet interface......Page 480
12.4.2 Sending a resource request using a resource URL......Page 483
12.5 Downloading binary content using portlets......Page 485
12.6 Resource URLs and caching......Page 488
12.7 Creating a rich interface for the Book Catalog portlet......Page 489
12.8 Creating rich user interfaces using Ajax......Page 491
12.8.1 Simplified Ajax with Dojo......Page 492
12.8.2 Simplified Ajax with jQuery......Page 498
12.8.3 Simplified Ajax with DWR......Page 501
12.9 Creating real-time portlets using Polling and Comet......Page 510
12.9.2 Comet or Reverse Ajax-pushing data when it’s available......Page 511
12.9.3 Comet support in DWR......Page 512
12.10 Cross-domain Ajax......Page 518
12.11 Ajax and inter-portlet communication......Page 519
12.11.1 Inter-portlet communication using Comet......Page 520
12.11.2 Inter-portlet communication using a JavaScript function......Page 521
12.12 Summary......Page 523
Reusable logic with portlet filters......Page 524
13.1 Types of portlet filters......Page 525
13.2.1 Portlet filter interface methods......Page 526
13.2.2 Portlet filter lifecycle......Page 527
13.3 Using portlet filters with the Book Catalog portlet......Page 529
13.4 Setting the portlet title with the portlet filter......Page 530
13.5 Validating requests with portlet filters......Page 533
13.6 Converting text to hyperlinks with portlet filters......Page 535
13.7 Filter chaining......Page 538
13.8 Summary......Page 539
Portlet bridges......Page 540
14.1 What is a portlet bridge?......Page 541
14.2 iFrame portlets......Page 543
14.3 JSF portlets......Page 545
14.3.2 JSF web application project structure......Page 546
14.3.3 Developing the Book Catalog web application using JSF......Page 548
14.3.4 Developing the Book Catalog portlet using a JSF portlet bridge......Page 553
14.4.1 Book Catalog Wicket web application requirements......Page 555
14.4.2 Wicket web application project structure......Page 556
14.4.3 Developing the Book Catalog web application using Wicket......Page 558
14.4.4 Developing the Book Catalog portlet using a Wicket portlet bridge......Page 560
14.5 Summary......Page 562
Web Services for Remote Portlets (WSRP)......Page 563
15.1 What makes remote portlets a reality?......Page 565
15.2 Getting started with WSRP using Liferay Portal......Page 568
15.3 Creating a WSRP producer and adding portlets to it......Page 569
15.4 Creating a WSRP consumer......Page 575
15.5 Locally registering remote portlets......Page 577
15.6 Registering WSRP consumers with WSRP producers......Page 580
15.6.3 In-band and out-of-band registration examples......Page 581
15.6.4 Leasing......Page 583
15.7 Summary......Page 584
A.1 Installing GateIn Portal......Page 585
A.2 Getting familiar with the GateIn Portal user interface......Page 586
A.3 Creating the Book Portal web portal......Page 587
A.3.1 Setting up a new web portal......Page 588
A.3.3 Creating a custom user group......Page 593
A.3.4 Associating users to groups......Page 596
A.3.5 Removing the portal’s default home page......Page 597
A.3.6 Creating portal pages and adding portlets......Page 598
A.3.7 Programmatically securing a custom portlet......Page 600
A.3.8 Importing custom portlets into GateIn Portal......Page 601
A.3.9 Defining default groups and memberships for registered users......Page 602
B.1 Installing MySQL database and HeidiSQL client......Page 604
B.2.1 Configuring Liferay Portal with MySQL......Page 607
B.2.2 Exploring the Liferay Portal database tables......Page 609
Symbols......Page 612
A......Page 613
B......Page 615
C......Page 617
D......Page 619
E......Page 620
F......Page 621
G......Page 622
H......Page 623
I......Page 624
J......Page 625
L......Page 626
M......Page 627
O......Page 628
P......Page 629
R......Page 634
S......Page 636
T......Page 639
U......Page 640
W......Page 641
Z......Page 642
Back cover......Page 644