Friday, July 29, 2016

Adding a Plugins Portlet to the Liferay Control Panel

A "Gotcha!" situation came up when you need to add your custom portlet to the control panel section.

Now the important thing is that as a developer you can actually decide which of the items on the left menu are shown. in simple words which section of liferay control panel is display.

Furthermore you can add any custom portlet to the desired place[portal, server, content] in the left menu and make it part of the Control Panel. Custom portlet's  liferay-portlet.xml need some entries to be place your custom portlet at desired place in Control Panel. That is look similar to this:

<control-panel-entry-category>portal</control-panel-entry-category> <control-panel-entry-weight>1.0</control-panel-entry-weight>

=> The first element determines to which section of the menu will the portlet be added
     This entry value may be very based on liferay version. here i have given control panel category for Liferay 6.1 and 6.2.
 
   1 )  Liferay 6.1 control panel category values of either my, content, portal, server to place the portlet in the area in the control panel.

  2) Liferay 6.2 control panel category values is extended from the previous version. possible value listed below.
      For My Account Section : my
      For Control Panel Section: users, sites, apps, configuration
      For Site Administration Section: site_administration.pages, site_administration.content, site_administration.users, site_administration.configuration
    
=> The second one determines the position. default value is 1.5.

After doing above configuration for your custom portlet, please deploy and check your control panel respected section.

You are done with what all you need to do, Enjoy!!

HTH!!


Thanks,
Ketan Savaliya

Thursday, July 28, 2016

Create liferay service builder portlet using maven tool

Hello LRExpert,


Now a days maven as building tool is common practice during development. Lifeary is also support maven tool for building liferay plugin. this article is for those who just start using maven or use maven first to create portlet.

Here i have given steps to create new liferay portlet using maven tool. Please follow simple 11 steps given below.

1) Install Maven
    Find specific liferay maven package for liferay version. here in my case i am using liferay-portal-     6.2-ce-ga6. so, supported liferay maven package is liferay-portal-maven-6.2-ce-ga6.zip. liferay         maven package is nothing but just a zip file. unzip that maven package whenever you want. Insall     maven plugin followed by below steps...

    - Open CMD windows
    - Go to directory location where you just unzip file (i.e liferay-portal-maven-6.2-ce-ga6.zip )
    - Execute command Ant istall
    - Wait untill it's finished execution.
    - You are done with you Liferay Maven Plugin Installation.

2) Go to location in CMD window where you need to create liferay maven portlet (suppose d:/lrproject/Source)
     
3) Execute command : mvn archetype:generate
    This will display list of maven project which you can create like...
     ...
     ...
    221: remote -> com.liferay.maven.archetypes:liferay-ext-archetype (Provides an archetype to create Liferay extensions.)
222: remote -> com.liferay.maven.archetypes:liferay-hook-archetype (Provides an archetype to create Liferay hooks.)
223: remote -> com.liferay.maven.archetypes:liferay-layouttpl-archetype (Provides an archetype to create Liferay layout templates.)
224: remote -> com.liferay.maven.archetypes:liferay-portlet-archetype (Provides an archetype to create Liferay portlets.)
225: remote -> com.liferay.maven.archetypes:liferay-portlet-icefaces-archetype (Provides an archetype to create Liferay ICEfaces portlets.)
226: remote -> com.liferay.maven.archetypes:liferay-portlet-jsf-archetype (Provides an archetype to create Liferay JSF portlets.)
227: remote -> com.liferay.maven.archetypes:liferay-portlet-liferay-faces-alloy-archetype (Provides an archetype to create Liferay Faces Alloy portlets.)
228: remote -> com.liferay.maven.archetypes:liferay-portlet-primefaces-archetype (Provides an archetype to create Liferay PrimeFaces portlets.)
229: remote -> com.liferay.maven.archetypes:liferay-portlet-richfaces-archetype (Provides an archetype to create Liferay RichFaces portlets.)
230: remote -> com.liferay.maven.archetypes:liferay-portlet-spring-mvc-archetype (Provides an archetype to create Liferay Spring MVC portlets.)
231: remote -> com.liferay.maven.archetypes:liferay-servicebuilder-archetype (Provides an archetype to create Liferay Service Builder portlets.)
232: remote -> com.liferay.maven.archetypes:liferay-theme-archetype (Provides an archetype to create Liferay themes.)
233: remote -> com.liferay.maven.archetypes:liferay-web-archetype (Provides an archetype to create Liferay webs.)
...
...
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 817: 231 + Enter [Find your liferay plugin type number from above list and enter it as input for above step]

4) After Enter above steps, it's display liferay version list like...
Choose com.liferay.maven.archetypes:liferay-servicebuilder-archetype version:
1: 6.1.0
2: 6.1.1
3: 6.1.2
4: 6.1.10
5: 6.1.20
6: 6.1.30
7: 6.1.30.1
8: 6.2.0-B1
9: 6.2.0-B2
10: 6.2.0-B3
11: 6.2.0-M5
12: 6.2.0-M6
13: 6.2.0-RC1
14: 6.2.0-RC2
15: 6.2.0-RC3
16: 6.2.0-RC4
17: 6.2.0-RC5
18: 6.2.0-ga1
19: 6.2.1
20: 6.2.2
21: 6.2.4
22: 6.2.5
23: 6.2.10.4
24: 6.2.10.5
25: 6.2.10.6
26: 6.2.10.7
27: 6.2.10.8
28: 6.2.10.9
29: 6.2.10.10
30: 6.2.10.11
31: 6.2.10.12
32: 6.2.10.13
33: 6.2.10.14
34: 6.2.10.15
35: 7.0.0-m1
36: 7.0.0-m2
Choose a number: 36: 19 + Enter [Select liferay version, here i am using 6.2.1 ]

5) Define value for property 'groupId': : com.liferay.portlet.search 
    [project groupid in pom.xml]

6) Define value for property 'artifactId': : my-search-portlet

7) Define value for property 'version':  1.0-SNAPSHOT: : SNAPSHOT-1.0.0 
[Optional...Enter your preferred project version. Other wise default 1.0-SNAPSHOT]

8) Define value for property 'package':  com.liferay.project.search: : com.liferay.project.search
[Optional...Enter your preferred package path. Other wise default com.liferay.project.search]

9) Confirm properties configuration:
     groupId: com.liferay.project.search
     artifactId: my-search-portlet
     version: SNAPSHOT-1.0.0
     package: com.liferay.project.search
     Y: : Y [Enter Y for yest, N for no]

10) your cmd screen final output is....
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: liferay-servicebuilder-archetype:6.2.1
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.liferay.project.search
[INFO] Parameter: artifactId, Value: my-search-portlet
[INFO] Parameter: version, Value: SNAPSHOT-1.0.0
[INFO] Parameter: package, Value: com.liferay.project.search
[INFO] Parameter: packageInPathFormat, Value: com/liferay/project/search
[INFO] Parameter: package, Value: com.liferay.project.search
[INFO] Parameter: version, Value: SNAPSHOT-1.0.0
[INFO] Parameter: groupId, Value: com.liferay.project.search
[INFO] Parameter: artifactId, Value: my-search-portlet
[INFO] project created from Archetype in dir: d:\lrproject\Source\my-search-portlet
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25:01 min
[INFO] Finished at: 2016-07-28T19:29:27+05:30
[INFO] Final Memory: 16M/229M
[INFO] ------------------------------------------------------------------------

11) Enjoy you are Done. [your maven service builder portlet is create @ d:\lrproject\Source\my-search-portlet]


Veryfirst time you looks it's long process, but once you have more practice to create liferay plugin. then it's very easy to create maven project for liferay.

Hope this Help!!

Thanks,
Ketan Savaliya

Get value from Structure Field for Journal Article/Web Content in Liferay.


During your liferay development, many time you need get value from DDM Structure field. So, here i have piece of code which gives you value of structure field for journal article/ web content.

Suppose you have article content field data(from JournalArticle table) something like (Mention only one field for example.)...


<?xml version="1.0"?>

 <root available-locales="en_US" default-locale="en_US">
  <dynamic-element name="country" type="text" index-type="" index="0" instance-id="Page_Title">
  <dynamic-content language-id="en_US"><![CDATA[India]]></dynamic-content>
  </dynamic-element> 
 </root>


Then your code to get value of country field is like...

JournalArticle article = JournalArticleLocalServiceUtil.getArticle(...);

Document document = SAXReaderUtil.read(article.getContent());

Node node = document.selectSingleNode("/root/dynamic-element[@name='country']/dynamic-content");

String country = node.getText();


if you have multiple field then your code looks like...(Suppose your field have two times as repeated field )

1) Access first element value is....

Node node = document.selectSingleNode("/root/dynamic-element[@name='country' and @index='0']/dynamic-content");
String country = node.getText()


2) Access second element value is....

Node node = document.selectSingleNode("/root/dynamic-element[@name='country' and @index='1']/dynamic-content");
String country = node.getText()



HTH...!!!


Thanks,
Ketan Savaliya





Liferay MySQL Error 'option sql_select_limit=default' at line 1

Hello LRDeveloper,

Sometime when you setup your fresh tomcat even you start first time with you mysql db, you got error something like... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_SELECT_LIMIT=DEFAULT' at line 

This is nothing more complex but problem with your tomcat\lib\ext\mysql.jar file. just download update version of mysql connector jar and replace it with old tomcat\lib\ext\mysql.jar. make sure your new file have name like mysql.jar only.

HTH and save you valuable time.

NOTE: above solution is worked for me if i update mysql connector with "mysql-connector-java-5.1.6.jar" version and rename it with mysql.jar. Liferay version i am using 6.1.20.


Thank you!!


Thanks,
Ketan Savaliya

Friday, July 22, 2016

Maven ServiceBuilder stop override portlet-model-hints.xml with lifeary

Hello Liferay Experts,

Here i am sharing some important liferay + maven information. which i got after spending my more then half day, it may help you as well.

This is helpful for those who are working with liferay 6.1 + service builder  + maven build tool. some time you need to change DB field size rather then default size which generate from service builder code.

Obviously liferay expert very well know to change  portlet-model-hints.xml  to increase filed size. if you don't know about that then this is importance for you, you need to change that file. it's famous and well known problem with maven is overriding your portlet-model-hints.xml everytime while you build service. please check MAVEN-37 and LPS-10607 links for reporting @ liferay.

Due to this you want be able to change your filed size because if you change that file and getting that reflect you need service build. as i said earlier service build is again override your changes if you do build service. to overcome/resolve this issue here i come up with workaround and few step to follow....

1.  Your maven portlet parent pom.xml configure the liferay maven plugin for version 6.1.30 like              bellow...
    <build>
<plugins>
<plugin>
                       <groupId>com.liferay.maven.plugins</groupId>
             <artifactId>liferay-maven-plugin</artifactId>
             <version>6.1.30</version>
             .....

        </plugin>
     </plugins>
   </build>

2. Maven portlet parent pom.xml also have entry in dependency for above liferay maven plugin.

     <dependencies>
<dependency>
   <groupId>com.liferay.maven.plugins</groupId>
   <artifactId>liferay-maven-plugin</artifactId>
   <version>6.1.30</version>
</dependency>
</dependencies>


3. Make sure maven porlet all three pom.xml refer the same configuration version of liferay maven     plugin. suppose you have maven portlet name portlet-test then check below files

    -porlet-test/pom.xml
    -porlet-test/portlet-test-porlet/pom.xml 
    -porlet-test/portlet-test-portlet-service/pom.xml

4. Update portlet-model-hints.xml with your required changes something like

    <field name="message" type="String">
<hint-collection name="TEXTAREA" />
    </field>

5. Rebuild service.xml and deploy porlet then check your DB table wether your changes get reflect or     not. i am sure yes it is.

6. Make smiley face.....


Hope this save someone development time and make them relax...!!

Thank you.

NOTE : 
I am working with maven 6.1.2 and liferay 6.1.2 and above solution is perfectly working fine with mentioned version.


Thanks,
Ketan Savaliya