• No results found

Optional: Adding Friendly URL Mapping to the Portlet

In document Liferay Developer Guide 6.0 (Page 35-38)

catch(Exception e) {

SessionErrors.add(actionRequest, "error");

} } }

public void sendEmail(

ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException {

// Add code here to send an email }

}

Note how we no longer need to invoke the processAction method of the su-per class, because we are not overriding it.

This change of name also requires a simple change in the URL, to specify the name of the method that should be invoked to execute the action. In the edit.jsp edit the actionURL so that it looks like this:

<portlet:actionURL var="editGreetingURL" name="setGreeting">

<portlet:param name="jspPage" value="/edit.jsp" />

</portlet:actionURL>

That's it, now you know all the basics of portlets and are ready to use your Java knowledge to build portlets that get integrated in Liferay. The next section explains an extension provided by Liferay to the portlet specification to provide pretty URLs to your portlets that you can use if desired.

Optional: Adding Friendly URL Mapping to the Portlet

You will notice that when you click the Edit greeting link, you are taken to a page with a URL similar to this:

Optional: Adding Friendly URL Mapping

to the Portlet 37

http://localhost:8080/web/guest/home?

p_p_id=mygreeting_WAR_mygreetingportlet&p_p_lifecycle=0&p_p_state=norma

l&p_p_mode=view&p_p_col_id=column-1&_mygreeting_WAR_mygreetingportlet_jspPage=%2Fedit.jsp

In Liferay 6 there is a new feature that requires minimal work to change this into:

http://localhost:8080/web/guest/home/-/my-greeting/edit

This feature, known as friendly URL mapping, takes unnecessary parameters out of the URL and allows you to place the important parameters in the URL path rather than the query string. To add this functionality, first edit liferay-port-let.xml and add the following lines directly after </icon> and before <instance-able>. Be sure to remove the line breaks and the backslashes!

<friendly-url-mapper-class>com.liferay.portal.kernel.portlet.Default\

FriendlyURLMapper</friendly-url-mapper-class>

<friendly-url-mapping>my-greeting</friendly-url-mapping>

<friendly-url-routes>com/sample/mygreeting/portlet/my-greeting-friendly-url\

-routes.xml</friendly-url-routes>

Next, create the file (note the line break):

my-greeting-portlet/docroot/WEB-INF/src/com/sample/mygreeting/portlet/my\

-greeting-friendly-url-routes.xml

Create new directories as necessary. Place the following content into the new file:

<?xml version="1.0"?>

<!DOCTYPE routes PUBLIC "-//Liferay//DTD Friendly URL Routes 6.0.0//EN"

"http://www.liferay.com/dtd/liferay-friendly-url-routes_6_0_0.dtd">

<routes>

<route>

<pattern>/{jspPageName}</pattern>

<generated-parameter name="jspPage">/

{jspPageName}.jsp</generated-parameter>

</route>

</routes>

Redeploy your portlet, refresh the page, and try clicking either of the links again. Notice how much shorter and more user-friendly the URL is, without even having to modify the JSPs. For more information on friendly URL mapping, you can check full discussion of this topic in Liferay in Action.

38Optional: Adding Friendly URL Mapping

4. 4. C C REATING REATING L L IFERAY IFERAY T T HEMES HEME S

Themes are hot deployable plugins which can completely transform the look and feel of the portal. Theme creators can make themes to provide an interface that is unique to the site that the portal will serve. Themes make it possible to change the user interface so completely that it would be difficult or impossible to tell that the site is running on Liferay. Liferay provides a well organized, modular structure to its themes. This allows the theme developer to be able to quickly modify everything from the border around a portlet window to every object on the page, because all of the ob-jects are easy to find. Additionally, theme developers do not have to customize every aspect of their themes. A theme can inherit the styling, images, and templates from any of the built in themes, overriding them only where necessary. This allows themes to be smaller and less cluttered with extraneous data that already exists in the default theme (such as graphics for emoticons for the message boards portlet).

Introduction

Liferay's themes are designed in such way that they can be very easy to create.

You can start by making changes in CSS files and as your customization requirements grow you can also make changes to the HTML that controls the page design.

Some of the technologies that you may need to know in order to make the best use of themes are:

• CSS: If desired you can create a whole new theme just by changing a CSS file.

• Velocity: a simple yet powerful tool to create templates. You will need to use it in order to customize the HTML generated by the theme.

• JavaScript: can be used to add special behaviors.

• XML: each theme has a configuration file written in XML. You will use this file to specify some settings of the theme.

To follow the examples of this guide you will also need some familiarity with using the command line. Alternatively you can use the Liferay IDE and use its menus instead of the commands used in the text.

But let's finish the introduction and get started with our first theme.

In document Liferay Developer Guide 6.0 (Page 35-38)