basic portlet copyright © 2000-2006 liferay, inc. all rights reserved. no material may be...

18
Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission from Liferay, LLC.

Upload: archibald-wells

Post on 30-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Basic Portlet

Copyright © 2000-2006 Liferay, Inc.

All Rights Reserved.No material may be reproduced electronically or in print without written

permission from Liferay, LLC.

Page 2: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Introduction

Difficulty Level: Easy

The source code for this presentation is located here:source-code-part1

Make sure to read the code! It’s important to become familiar with the basic structure before the exercises get more complicated.

Page 3: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Objectives

The goal of this tutorial is to create a JSP portlet

1. Define the portletportlet-ext.xmlliferay-portlet-ext.xml

2. Create the JSPview.jsp

Page 4: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Directory Structure

Configuration files are located here:ext\ext-web\docroot\WEB-INF

JSPs are located here:ext\ext-web\docroot\html

Page 5: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Define the Portlet

The first step will be to define the portlet in portlet-ext.xml

The second step will be to define the portlet in liferay-portlet-ext.xml

Page 6: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

portlet-ext.xml

<portlet>

<portlet-name>EXT_2</portlet-name>

<display-name>JSP Portlet Introduction</display-name>

<portlet-class>com.liferay.portlet.JSPPortlet</portlet-class>

<init-param>

<name>view-jsp</name>

<value>/portlet/ext/jsp_portlet/view.jsp</value>

</init-param>

<expiration-cache>0</expiration-cache>

Page 7: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

<supports>

<mime-type>text/html</mime-type>

</supports>

<resource-bundle>com.liferay.portlet.StrutsResourceBundle</resource-bundle>

<security-role-ref>

<role-name>power-user</role-name>

</security-role-ref>

<security-role-ref>

<role-name>user</role-name>

</security-role-ref>

</portlet>

Page 8: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Checkpoint

1. What is <portlet-name> used for?

2. What is <portlet-class> used for?

3. What is view-jsp?

4. What is /portlet/ext/jsp_portlet/view.jsp?

5. What is <role-name> used for?

Page 9: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

liferay-portlet-ext.xml

The second step is to define the portlet in liferay-portlet-ext.xml<portlet>

<portlet-name>EXT_2</portlet-name>

</portlet>

Page 10: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

view.jsp

1. Create the following directory structure:ext\ext-web\docroot\html\portlet\ext\jsp_portlet

2. Create view.jspext\ext-web\docroot\html\portlet\ext\jsp_portlet\view.jsp

3. Enter the following in view.jspJSP Portlet!

Page 11: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Checkpoint

1. Why did we place view.jsp here?ext\ext-web\docroot\html\portlet\ext\jsp_portlet\view.jspHint: portlet-ext.xml

2. Where are configuration files like portlet-ext.xml and liferay-portlet-ext.xml located?

Page 12: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Deploy the Files to Tomcat

1. Click Start Run…

2. Type cmd and press Enter

3. Navigate to C:\Training\liferay\ext

4. Type ant deploy

Page 13: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Checkpoint

Verify that your files were deployed to Tomcat correctly. This is a required step!

1. Go to \tomcat\webapps\ROOT\WEB-INF

2. Check portlet-ext.xml and liferay-portlet-ext.xml and make sure they are correct

3. Go to tomcat\webapps\ROOT\html\portlet\ext\jsp_portlet

4. Make sure that view.jsp exists and that it is correct

See the Troubleshooting section if your files were not deployed correctly.

Page 14: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Final Steps

1. Restart Tomcat:Click on the Tomcat WindowPress Ctrl-CDouble click startup.bat

2. Open up a new browser and type http://localhost:8080Login: [email protected]: test

3. Click Add Content Undefined

4. Click javax.portlet.title.EXT_2

Page 15: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Troubleshooting

Question: My files are not being deployed to Tomcat correctly!

Answer: You have an error in app.server.{user.name}.properties

1. Make sure that app.server.{user.name}.properties is located in C:/Training/liferay/ext

2. Verify that your {user.name} is correct

3. Make sure that app.server.{user.name}.properties contains the following:app.server.type=tomcatapp.server.tomcat.dir=C:/Training/liferay/tomcat

Page 16: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Troubleshooting

Question: My portlet is not showing up when I clickAdd Content Undefined

Answer: Your portlet is not defined correctly in portlet-ext.xml or liferay-portlet-ext.xml

1. Check portlet-ext.xml and liferay-portlet-ext.xml inC:/Training/liferay/tomcat/webapps/ROOT/WEB-INF

2. Make sure that the EXT_2 portlet is defined correctly.

Page 17: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Congratulations!

You’ve created your first JSP Portlet!

1. Defined the portlet inportlet-ext.xml

2. Defined the portlet in liferay-portlet-ext.xml

3. Created the JSP inext\ext-web\docroot\html\portlet\ext\jsp_portlet\view.jsp

Page 18: Basic Portlet Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission

Revision HistoryEdward Shin 09/14/06 Updated for Liferay 4.1.2