KNOWLEDGEBASE

We pride ourselves on bringing a fresh perspective and effective insight knowledge of each technology.

  • AUI Form Validation In Liferay

    AUI Form Validation In Liferay

    AUI Validators In Liferay

    Liferay Provides its own AUI Validators to validate the AUI Form Elements, There are numerous validators are available for the validations of Text, Numbers, Email, Password and etc...
    <%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %> <aui:form> <aui:input name="alpha" type="text"> <aui:validator name="alpha"/> </aui:input> <aui:input name="alphanum" type="text"> <aui:validator name="alphanum"/> </aui:input> <aui:input name="digits" type="text"> <aui:validator name="digits"/> </aui:input> <aui:input name="email" type="text"> <aui:validator name="email"/> </aui:input> <aui:input name="number" type="text"> <aui:validator name="number"/> </aui:input> <aui:input name="date" type="text" > <aui:validator name="date"></aui:validator> </aui:input> <aui:input name="maxLength4" type="text" > <aui:validator name="maxLength">4</aui:validator> </aui:input> <aui:input name="minLength3" type="text" > <aui:validator name="minLength">3</aui:validator> </aui:input> <aui:input name="required" type="text" > <aui:validator name="required"/> </aui:input> <aui:input name="required" type="text" label="Required Label is Hidden" showRequiredLabel="false"> <aui:validator name="required"/> </aui:input> <aui:input name="range" type="text"> <aui:validator name="range">[0,9]</aui:validator> </aui:input> <aui:input name="rangeLength" type="text"> <aui:validator name="rangeLength">[3,5]</aui:validator> </aui:input> <aui:input name="url" type="text"> <aui:validator name="url"/> </aui:input> <aui:input name="acceptFiles" type="file"> <aui:validator name="acceptFiles">pdf</aui:validator> </aui:input> <aui:input name="myDate" type="date"/> <aui:input name="myTimeZone" type="timeZone"/> <aui:input name="textarea" type="textarea"/> <aui:button type="submit" value="submit"/> </aui:form>


  • AUI Form In Liferay

    AUI Form In Liferay

    AUI Form In Liferay

    Liferay's AUI Library have extensive elements for handling form elements, AUI form elements are responsive and we can use the Liferay's AUI validators without having to use any javascript code or external libraray.


    <%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %> <%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> <aui:form> <aui:input name="title" type="text"/> <aui:input name="description" type="textarea"/> <aui:select name="items"> <aui:option value="item1">Item1</aui:option> <aui:option value="item2">Item2</aui:option> </aui:select> <aui:input name="timeZone" type="timeZone"/> <aui:input name="checkbox" type="checkbox"/> <aui:input name="radio" type="radio"/> <aui:input name="hidden" type="hidden"/> <aui:input name="file" type="file"/> </aui:form>


  • Liferay Service Builder

    Liferay Service Builder

    Liferay 7 Service Builder

    Lets see how to create a service builder module in liferay 7. Before creating the service builder module let me give the some introduction about service builder and its features,Service builder is used in liferay to create database tables and generate the api to read and write into the database.

    Environment
    Liferay IDE Milestone 3.0.1 M2
    Liferay CE Portal Tomcat 7 GA3
    JDK 8
    MySql 5.7

    To create a service builder module click on "New Liferay Module Project"



    Lets give the Service Builder Module's name as "products-data" and select the Project template name as "service-builer".


    Click on next button.


    Click on Finish, This will create a new Liferay Service Builder module for us.
    You can find this newely created service builder module inside the Liferay Wokspace's module folder.
    The folder structure of a service builder module will be as shown below.


    service.xml is the file where we will be creating and configuring new tables, in liferay relational database table is referred as entity or model, when you create a new service builder module it will come with some sample entity, lets remove that and use the entity defined below in service.xml
    <?xml version="1.0"?> <!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 7.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_7_0_0.dtd"> <service-builder package-path="com.liferaystack"> <author>Syed Ali</author> <namespace>LS</namespace> <entity local-service="true" name="Product" remote-service="true" uuid="true"> <!-- PK fields --> <column name="productId" primary="true" type="long" /> <!-- Group instance --> <column name="groupId" type="long" /> <column name="companyId" type="long" /> <!-- Audit fields --> <column name="name" type="String" /> <column name="description" type="String" /> <column name="manufacturer" type="String" /> <column name="userId" type="long" /> <column name="createDate" type="Date" /> <column name="modifiedDate" type="Date" /> <!-- Order --> <order by="asc"> <order-column name="name" /> </order> <!-- Finder methods --> <finder name="manufacturer" return-type="Collection"> <finder-column name="manufacturer" /> </finder> <!-- References --> <reference entity="AssetEntry" package-path="com.liferay.portlet.asset" /> <reference entity="AssetTag" package-path="com.liferay.portlet.asset" /> </entity> </service-builder>

    Liferay Service Builder Tags and Their Uses

    <namespace>LS</namespace>
    This tag is used to specify the namesspace for the taable, if we create a table named
    product then in database it will be created with namespace as "LS_Product"

    <entity local-service="true" name="Product" remote-service="true" uuid="true">
    
    Using entity tag we can create a new table/model/entity in liferay.
    • name: Used to specify the name of the entity or table
    • local-service: If it is set to true, local service will generated
    • remote-service: If it is set to true, remote services(Web Services) will generated
    • uuid: universal unique identifier will be generated for each entity

    <column name="productId" primary="true" type="long" />
    column tag is used to define the different columns for the database tables with different types
    • name: Name of the column
    • primary: Primary key of the table
    • type: types such as long,int,double,String,boolean,blob,Date,Collection

    <order by="asc">
     <order-column name="name" />
    </order>
    
    When we fetch or read from the tables then the records will be order as specified in this tag.
    • by: asc(Ascending order) or desc(Descending order)
    • <order-column name="name" /> Used to order based on the column name specified in this tag

    <finder name="manufacturer" return-type="Collection">
     <finder-column name="manufacturer" />
    </finder>
    
    When you have many rows of products in the table and you want to fetch all the product belongs to a single manufacturer at that time you can go with finder which allows you fetch the rows based on the finder-column name specified.

    Once you are done with defining the fields, the next step is to build the service, to build the service
    just right click on the module go to Liferay>> then click on build service.



    after building the service, deploy the module, you will be able to see the new table in your database.