This wiki does not contain official documentation and is currently deprecated and read only. Please try reading the documentation on the Liferay Developer Network, the new site dedicated to Liferay documentation. DISCOVER Build your web site, collaborate with your colleagues, manage your content, and more. DEVELOP Build applications that run inside Liferay, extend the features provided out of the box with Liferay's APIs. DISTRIBUTE Let the world know about your app by publishing it in Liferay's marketplace. PARTICIPATE Become a part of Liferay's community, meet other Liferay users, and get involved in the open source project. Business Logic Customization Example
Table of Contents [-]
So you love everything about a built in Liferay function except for one thing, what should you do? Customize it of course! But how does one change the business logic in a Liferay Impl class without changing the code? This is what this document will show you.
Let's take adding a new User for example. By default, you are required to enter a screen name, valid email address, first name, and last name. Let's try to change the business logic so that screen name is NOT required.
The Action Class / method controlling the form submit is EditUserAction.updateUser(). Somewhere in there UserServiceUtil.addUser() is called, and we know that Liferay Util classes are autogenerated via Service Builder. The business logic lies within UserLocalServiceImpl.addUser().
Steps:
1. Create a new class that extends UserLocalServiceImpl.java and include the methods you want to override. Place this class in your ext environment. For example:
package com.ext.portal.service.impl;
public class ExtUserLocalServiceImpl extends UserLocalServiceImpl {
public User addUser(
....;
....;
)
protected void validate(
....;
....;
)
}2. Modify spring configuration file to tell the Util to talk to the Impl. An easy way to do this is to search for "UserLocalServiceImpl" in portal-spring.xml. You will see this:
<bean id="com.liferay.portal.service.UserLocalService.professional" class="com.liferay.portal.service.impl.UserLocalServiceImpl" lazy-init="true" />
We don't to touch portal-spring.xml or ext-spring.xml because their contents are autogenerated. So we'll create a new spring configuration file called custom-spring-info.xml and place it in ext-impl/classes/META-INF/. Input your new Impl reference:
<bean id="com.liferay.portal.service.UserLocalService.professional" class="com.ext.portal.service.impl.ExtUserLocalServiceImpl" lazy-init="true" />
Note: for some reason the name custom-spring.xml does not work. custom-spring-info.xml does work.
3. Modify portal-ext.properties to read your new spring configuration file:
spring.configs=\
META-INF/activemq-spring-jms.xml,\
META-INF/data-source-spring.xml,\
META-INF/misc-spring.xml,\
META-INF/counter-spring.xml,\
META-INF/documentlibrary-spring.xml,\
META-INF/documentlibrary-spring-jms.xml,\
META-INF/lock-spring.xml,\
META-INF/mail-spring.xml,\
META-INF/mail-spring-jms.xml,\
META-INF/portal-spring.xml,\
META-INF/portal-spring-jcr.xml,\
META-INF/portal-spring-jms.xml,\
META-INF/ext-spring.xml,\
META-INF/custom-spring-info.xml
4. Deploy your changes to tomcat and your good to go. Place a debug point in your custom class to make sure it's getting read.