• Liferay 7/Liferay DXP Screen Name Validator

    Posted on June 19, 2017 by Hamidul Islam in liferay 7.


    Screen Name in Liferay is very important which is unique in the Portal. While creating user the Screen Name is mandatory field and Screen Name represents the actual user in the portal. Sometimes its necessary to validate the screen name entered by the user at the time of creation of users. In this article we will explain how to write Custom Screen Name Validator in the form of OSGI Module. We can validate screen name both in client side and server side. At the end of this article we will be able to define our own reserved words in the Liferay control panel and those reserved words can't be used while crating users in the portal. 

    Key Points:

    • Write Configuration Interface for reserved words
    • Implement ConfigurationBeanDeclaration
    • Implement ScreenNameValidator

    Step 1 : Create one OSGI Module

    You can create one OSGI module using maven archetypes. Open the command prompt and type 

    mvn archetype:generate -Dfilter=liferay


    We can select below from the above list

    com.liferay:com.liferay.project.templates.mvc.portlet (Liferay Project Templates MVC Portlet)

    Note :

    We are not creating any portlet here. But still we can use MVC Portlet archetype to create the project structure. Once directory structure is created we can delete portlet related class. At the end, the final artifact should be OSGI Module.

    Step 2: The Configuration Interface

    Here we will define the Reserved words in the form of java interface. Below is the interface

    In the above step we have created the default reserved words as admin and user. You can navigate Control Panel->Configuration->System Settings->Pro Liferay to save the reserved words. 


    Step 3 : Bean Declaration

    In this step we will register our above configuration interface with the framework so that our configuration can be easily retrieved from ConfigurationProvider

    Step 4: Implement Liferay ScreenNameValidator

    Step 5: Include meta type in BND file

    Add below in the bnd.bnd file

    -metatype: *

    This will include meta types (defined in Step 2) in the final OSGI JAR


    After deployment of this OSGI Module try to create user with screen name, admin or user. You should get error message with message that are set in Language.properties file. 



Comments are closed.
%d bloggers like this: