Liferay in Action - Pdf 11

MANNING
IN ACTION
Richard Sezov, Jr.
FOREWORD BY BRIAN KIM
Official Guide
www.it-ebooks.info
Liferay in Action
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
Liferay in Action
The Official Guide to
Liferay Portal Development
RICH SEZOV, JR
MANNING
SHELTER ISLAND
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
To my wife: Yo Deborah! I did it!
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 261
Shelter Island, NY 11964
Email: [email protected]
©2012 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in

PART 2 WRITING APPLICATIONS ON LIFERAY’S PLATFORM 63
3

A data-driven portlet made easy 65
4

MVC the Liferay way 91
5

Designing your site with themes and
layout templates 128
6

Making your site social 154
7

Enabling user collaboration 176
PART 3 CUSTOMIZING LIFERAY 209
8

Hooks 211
9

Extending Liferay effectively 241
10

A tour of Liferay APIs 263
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
BRIEF CONTENTS

1.3 How Liferay structures a portal 18
The high-level view 18

Adding content to a collection with
pages 20

Configuring a portlet’s scope 20
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
CONTENTS
viii
1.4 Getting around in Liferay 23
Pin icon 24

Add menu 24

Manage menu 24
Toggle Edit Controls 26

Go To menu 26

User Account 26
1.5 Imagining your site in Liferay 26
Asking the right questions 27

Defining and categorizing
collections 28

Designing content 28
1.6 Summary 28

URLs
in portals are different 52

Implementing Edit mode 53
2.6 Deploying and testing your portlet 57
Changing the portlet’s category and name 58

Telling Liferay
about a renamed portlet 60
2.7 Summary 61
PART 2 WRITING APPLICATIONS ON
LIFERAY’S PLATFORM 63
3
A data-driven portlet made easy 65
3.1 Introducing Inkwell: a case study 65
Company profile: Inkwell 66

What Inkwell needs in a web
site 67

Inkwell’s high-level portal design 67

Inkwell
portal phase 1 requirements 68
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
CONTENTS
ix
3.2 Designing the Product Registration portlet 69
A blueprint of the portlet 69

Defining portlets in your deployment descriptors 97

Having
one location for JSP dependencies 99
4.3 Creating a form with AlloyUI taglibs 102
Getting started with AlloyUI tag libraries 102

Providing
feedback and messages 105

Translating messages to multiple
languages 108

Validating user-submitted forms 109
Displaying data with the search container 111

Using the
search container to present your data 111

Editing and
deleting data 114

Protecting data with Liferay
permissions 116

Pointing to the permissions
configuration 116

Configuring Liferay permissions 117
4.4 Generating different field types with AlloyUI taglibs 120


Modifying the default
paths 141

The <template-extension> tag 142
Conditional settings 142

Theme security and roles 144
Color schemes 144
5.5 Understanding theme conventions 146
Using Liferay’s styling conventions 146

Using Liferay’s CSS
coding conventions 148
5.6 Designing a page with layout templates 149
Creating layout template projects 149

Anatomy of a layout
template 150
5.7 Inkwell implementation 152
5.8 Summary 152
6
Making your site social 154
6.1 Social networking: why is it important? 155
Allowing users to connect with each other 156

Expanding
your reach beyond your own site 156

Creating a dynamic,

7.1 Building a collaborative app: a slogan contest 178
7.2 Adding assets to your applications 179
Adding assets with entities 180

Using asset renderers to
publish your data 184
7.3 Running your data through a workflow 188
Understanding the flow of Liferay workflow 189

Workflow-
enabling your services 190

Handily handling
workflow 191

Portal-wide language properties 193
7.4 Tagging and categorizing content 196
Choosing between tags and categories 196

A tag for tags and
a tag for categories 197
7.5 Adding discussions and ratings 199
7.6 Creating custom queries using SQL 200
Crafting your query 201

Making your own finder 202
Displaying custom columns in a search container 204
7.7 Summary 206
PART 3 CUSTOMIZING LIFERAY 209
8


Presenting the new
interface to end users 235
8.4 Summary 239
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
CONTENTS
xii
9
Extending Liferay effectively 241
9.1 Introducing Ext plugins 243
Anatomy of an Ext plugin 244

How Ext works 245
The Ext strategy 246

Deploying Ext plugins 247
9.2 Ext in action 249
Struts 101 249

Modifying a core portlet action 251
Other extension points for the Ext plugin 252
9.3 Delivering a page, Liferay style 253
Struts? Again? 254

Layers and layers 255
9.4 Understanding Liferay development best practices 257
Practices for developing applications 257

Practices for

10.7 Indexing and search 282
Indexing your data 283

Searching your data 287
10.8 Summary 292
appendix A Liferay and IDEs 295
appendix B Introduction to the Portlet API 312
appendix C Inter-portlet communication 316
appendix D How to contribute to Liferay 331
appendix E Liferay 6.1 Documents API 335
index 343
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
xiii
foreword
During the mid to late 1990s, portals emerged with the promise to help bring
together applications seamlessly via a unified user interface. As a result, many software
developers today still maintain that preconception of the word portal.
Although that definition of a portal still holds true, I believe the meaning has
shifted to something more encompassing. My colleagues describe it as a “conver-
gence” in which traditionally horizontally separated web applications are now begin-
ning to converge within the portal as components of the portal. Portals like Liferay
are now comprehensive, ready-to-deploy solutions that include adjacent capabilities,
such as social collaboration, content management, and business process manage-
ment. And in parallel with that shift, portals are taking on the critical infrastructural
role of a platform on which a broad range of sophisticated enterprise web applications
can be developed.
That’s where this book comes in. If you’re new to portal technology, you’ll find Rich
Sezov’s writing style easy to follow as he guides you through the fundamentals of port-
lets. Rich not only teaches you how to integrate into the portal existing applications you

Corolla), and Brian Kim, Liferay’s Chief Operating Officer, was sitting next to me, giv-
ing me a hard time. I was already uncomfortable in the back seat: I’m 6'2", and my
knees were up next to my ears. But it was only a short trip from the Liferay Symposium
hotel in Anaheim, CA, to Brian Chan’s house (where we and the other occupants of
the car were staying), so I wouldn’t have to endure the cramped quarters for long.
You see, I’d written a couple of editions of Liferay’s Administrator’s Guide, but its
companion volume, the Developer’s Guide, had suffered several aborted attempts at get-
ting off the ground. It had finally achieved some semblance of completion, but it
wasn’t yet where I wanted it to be. The problem was, I needed to release some devel-
oper documentation soon, so I could get to work on the training materials and the
documentation for the next release of Liferay. For this reason, I’d resigned myself to
publishing what we had and then attempting to make the next edition of the book
more complete. We’d been self-publishing the Administrator’s Guide, so I thought we
should do the same with the Developer’s Guide, particularly because it wasn’t going to be
as complete as I wished.
Brian wasn’t giving me a hard time because of that: Liferay was in a period of rapid
growth, and we often found ourselves in the position of having more work than we
had hands to complete it. Instead, Brian was giving me a hard time, frankly, because
he had a bigger vision than I had.
“Why do you want to self-publish again?” Brian asked. “Don’t you think it would be
better if we worked with a book publisher?”
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
PREFACE
xvi
“Of course it would,” I said. “I just think that the material I currently have isn’t yet
up to the standards that one of the two publishers I’d want to work with would
accept.”
“Really? Okay, what would it take to get it that way?”
“Well, I’d have to be able to dedicate more time to writing the book, which I can’t

hope), but I’ve tried to make what could become a dry subject interesting. To me,
there’s nothing dry about Liferay: it’s an exciting product that can do a ton of things,
and I think it’s an ideal platform on which to build a web site. I hope that by the end
of this book, you’ll think so too.
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
xvii
acknowledgments
When I started working on this book, I thought I’d be finished much sooner than I
was actually able to do so. I already had material that formed about a third of what the
book eventually became, and I figured the rest of it would slide easily into place. Boy,
was I wrong! If anyone reading this is considering writing a book, everything other
authors tell you about the process is true: it’s a lot more work than you think it’s going
to be. And the people around you are just as key to your success as you are.
First and foremost, I’d like to thank my wife, Deborah, and my daughter, Julia, for
their incredible sacrifice. Over the past year, I’ve been holed up in my office for more
hours than I’d like to count, and they’ve borne the brunt of the effects of a missing
husband and father. Thank you, Deborah, for your understanding, patience, kind-
heartedness, and support; and thank you, Julia, for your good cheer and your always-
diverting games and fun.
No acknowledgments for anything having to do with Liferay would be complete
without mentioning Brian Chan, who created Liferay, as well as the other founders of
Liferay, Caris Chan, Bryan Cheung, Brian Kim, and Mike Young. You make huge sacri-
fices of time and talent every day to keep both the company and product moving for-
ward. You trusted me out of the blue (and without prior contact) with a huge
responsibility when the company was tiny and vulnerable. Thank you for believing in
me. And thanks to Brian Kim for giving me a good kick in the rear (as described in
the preface).
Liferay’s core engineers are without a doubt some of the smartest people on the
planet. In all likelihood, I’d still be working on the code for this book if it weren’t for

glances at the training material for the last year. Thanks, Steve, for being so easy to
work with and so willing to pick up a wide variety of tasks.
I guess I have to move this along faster, or it’ll get to be as long as the book itself.
Thanks to all the trainers who helped keep the training material going while I was
working on the book: Julio Camarero, Juan Fernandez, Olaf Kock, Jonathon Omahen,
Sten Martinez, Alberto Montero, Zsigmond Rab, and Steven Cao. Thanks to Tim Tel-
cik for taking off and running with the
PDF tools.
Speaking of training, special thanks to Ed Shin and Jeff Handa for helping me
maximize my time on the book by organizing various training tasks. Thanks also to
Mike Han for keeping us in line and for your help with my workflow questions.
Thanks to Greg Amerson for the awesome Liferay
IDE/Developer Studio and all of
your excellent feedback. You’re making Liferay development easier every day, man.
To Ivan Cheung and James Min: I wouldn’t be in Liferay without you guys. Thanks!
Neil Griffin is to me the (slightly) older brother I never had. Thanks for your
encouragement and wisdom, Neil.
Thanks to my many coworkers who were so encouraging over the past year: Josh
Asbury, Alice Cheng, Paul Hinz, James Falkner, Michelle Hoshi, JR Houn, Mike
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
ACKNOWLEDGMENTS
xix
Saechang, Scott Lee, Nate Cavanaugh, Aaron Delani, Craig Kaneko, Ryan Park, Cyn-
thia Wilburn, Charles May, Zsigmond Rab, Zsolt Balogh, Jeff Young, Ed Chung, Jerry
Niu, Jeff Han, Louis Mui, Juan Fernandez, Thiago Moreira, Ruth Huijser, Joe Shum,
and Alex Chow. Thanks to Cecilia Lam for putting up with my hare-brained sympo-
sium ideas (a compliments contest?) so people could win copies of this book.
Manning put together a fantastic team for this book. Thank you, Marjan Bace, for
such a great bunch of people to work with, and for your hands-on approach. Thanks

beginner who wants to read the book from cover to cover, to the experienced
Java EE
developer who wants to dive into subjects of interest.
In order to do this, I’ve created an example company whose web site we’ll work on
together throughout the book. The code examples are purposefully designed to hit
many of the most-needed Liferay features and
APIs that you’ll want to use in your own
work, but they stand on their own. Experienced developers should be able to jump in
and work with the examples in any order you like.
Who should read this book
If you’re familiar with Java web development, this book is for you. You don’t need to
have any prior experience with portals or Liferay; in fact, I’d prefer that you didn’t.
That way, you can approach the material with a fresh view of portals and Liferay in
particular. But because this is an In Action book, we hit the ground running really fast;
if you need an introduction to the
Portlet API, you may want to read appendix B in
between chapter 2 and chapter 3.
If you’ve done work with other portals before, this book will help you become
familiar with Liferay and all it has to offer. Your knowledge of the
Portlet API will help
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
ABOUT THIS BOOK
xxi
you understand the underpinnings of Liferay’s platform, and you’ll learn how to
make use of lots of Liferay-specific APIs that enhance and complement it.
Seasoned Liferay developers will also be served well by this book. Liferay 6.0 and
6.1 introduce many architectural changes that affect developers, and many best prac-
tices from previous versions change in more recent releases. You’ll also get to see how
to work with some of Liferay’s newer

to
create the portlet application that depends on the service layer you generated previ-
ously. You also start using Liferay’s Alloy
UI tag libraries to lay out the forms required by
the application.
In chapter 5, we take a break from applications and look at Liferay themes.
Themes let you completely customize the way Liferay looks, so that your web site can
have the look and design that you define. This chapter will prepare front-end develop-
ers for working their design magic with Liferay.
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
ABOUT THIS BOOK
xxii
We move out of themes and back to Liferay APIs with chapter 6. Here, you learn
about Liferay’s Social API, so that you can enable users to connect with each other and
view their activities on your site. You’ll also see how Liferay integrates with existing
social networks.
Chapter 7 continues with a focus on the user by looking at Liferay’s Collaboration
API. In this chapter, you create a new portlet that provides a platform on which users
can collaborate: a slogan contest. You’ll learn how to create Liferay assets, to use Life-
ray’s Workflow
API, to tag and categorize your content, to add discussions and ratings,
and to use custom SQL queries in Liferay applications.
From here, we leave the realm of Liferay applications and begin looking at custom-
izing Liferay in chapter 8. This chapter shows you hook plugins, and how hooks can
be used to customize properties,
JSP files, and services. You use a hook to modify Life-
ray’s Shopping portlet and give it a custom user interface.
We put Liferay customization on steroids with chapter 9. Here, you use Ext plugins
to customize anything in Liferay. As far as Liferay’s development framework goes, this

you couldn’t read it, which sort of defeats the purpose of printing it in the first place.
One other thing must be mentioned about the code: there’s a lot more of it than
appears in the book. In the text, I’ve pointed out only the important code, and left the
mundane, obvious stuff as a download only. If I showed everything, the book would be
really boring, and you wouldn’t want to read it. If you want to look at the complete
examples, please download the code. You can find it at Manning’s web site at
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
ABOUT THIS BOOK
xxiii
www.manning.com/LiferayinAction or at my profile on liferay.com at www.liferay
.com/web/richard.sezov/documents.
Software requirements
One of Liferay’s strengths is that it comes from an agnostic philosophy with regard to
the environment in which it runs. This means you’re free to choose whichever envi-
ronment you like to work in the most. Because it’s Java, of course,
JDK 5+ must be able
to run on your machine. Further details about this appear in chapter 2, where you
install a Liferay development environment. Even more details appear in appendix A,
where I show you how to get set up in multiple
IDEs.
Because Liferay supports so many deployment combinations, you also have a huge
choice of what database or application server you want to use. For simplicity’s sake, for
the book I used the development configuration that Liferay developers use the most:
a Tomcat runtime and a
MySQL database. Liferay conveniently supplies a Liferay/
Tomcat bundle as a download, so you don’t have to worr y about installing Liferay
yourself into a Java application server. Of course, you’re free to use any of Liferay’s
deployment combinations, but I think this one is the best for developers. It’s small,
fast, lightweight, and easily configured.

reminds us vividly of how culturally apart the world’s towns and regions were just 200
years ago. Isolated from each other, people spoke different dialects and languages. In
the streets or in the countryside, it was easy to identify where they lived and what their
trade or station in life was just by their dress.
Dress codes have changed since then and the diversity by region, so rich at the time,
has faded away. It is now hard to tell apart the inhabitants of different continents, let
alone different towns or regions. Perhaps we have traded cultural diversity for a more
varied personal life—-certainly for a more varied and fast-paced technological life.
At a time when it’s hard to tell one computer book from another, Manning cele-
brates the inventiveness and initiative of the computer business with book covers based
on the rich diversity of regional life of two centuries ago, brought back to life by
Maréchal’s pictures.
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status