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


Sunday, August 2, 2015

Upload file with ajax - Liferay

In developer life, to stuck at any point is routine. here is one of the point i am sharing where many of us stuck and it's take lot more times to come out with solution.


Scenario: upload file with Ajax.
Some time we need to upload(by file) some data and process them. but after finished data process page doesn't refreshed. to achieve this we defiantly use Ajax. so, generally we giving <portlet:resourceURL> in form action. form which include input file object. here in this case, if we submit the form and try to get uploaded file in liferay controller. it's doesn't work because of ajax. your serverResource() of  portlet controller is not able to fetch file object from request. because ajax request generally we are passing String & Number data. but this is File so ajax can not handle this tyep of data. after trying more and giving lot more time to resolve this. i found resolution that what i am going to share here....

Here is what you need to do... 

1) JSP contains input-file (With or Without Form)  

<script type="text/javascript" src="/XYZ-porlet/js/ajaxfileupload.js"></script>

  

<portlet:resourceURL var="fileImportURL" id="fileImport"></portlet:resourceURL>

 

<input id="fileUpload" name="file" type="file"  accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"/>

 

 <input type="button" name="upload" id="upload" value="Upload" onclick="ajaxFileUpload()" />


2) Write JS for AJAX

function ajaxFileUpload(){

$.ajaxFileUpload
    ({
        secureuri : false,
        fileElementId : 'fileUpload',
        data: {name: 'Ketan'},
        url: '<%=fileImportURL%>',
        success: function (data, status)
        {

                 alert("File upload success")
         },
        error: function (data, status, e) {

            alert("File upload faile");
        }
    })
 

   return false;

}

 

3) serveResource() of Liferay Controller

UploadPortletRequest uploadRequest   =  PortalUtil.getUploadPortletRequest(resourceRequest);
File file = uploadRequest.getFile("
fileUpload");

 

 

That's all enough to do for ajax file upload. Enjoy!!

 

 

Click Here to download required js file. 

 

 

Saturday, September 27, 2014

Liferay Category Import Export Apps on Liferay Market Place

Here i am sharing one more my work experience to liferay community.

I hope this may help to many liferay developer during development. it's about import/export functionality of Category.

Many time we need create long list of categories. Once we create all categories structure to particular community or organization then we want to copy whole structure to another community or another server. Currently we don't have any option doing this easily within few clicks. Again we need rework all categories entry.

So, here i come up with solution. I created App for that which is use to import/export category list from or to liferay community or organization.

Here you can find my liferay apps from Liferay market place Liferay Category Import-Export App

Thursday, October 10, 2013

Solr Configuration With Liferay

Hi Liferay Mastreo,

Solr Configuration with lifeary is so easy. here i describable  the steps which i follow for solr configuration with liferay 6.0.


1) Download Solr let-test version from here...

2) Download Apache let-test tomcat for solr (separate from liferay tomcat) from here...

3) Unzip .tar/.zip file of Solr which you downloaded version(in step 1) on your prefered location (ex. D:/Solr)

4) Unzip .tar/.zip file of Solr tomcat which you downloaded version(in step 2)on your preferred location (ex. D:/tomcat)

Configuration Solr with tomcat instance

5) apache-solr-1.4.0.war : copy this file from solr dist directory (here D:/Solr/dist) and past into /example/solr(here D:/Solr/example/solr) directory.

6) Configure Solr data directory path into solrconfig.xml (D:/Solr/exmple/solr/conf/solrconfig.xml)
  - Create directory called data into /example/solr/ (here D:/Solr/example/solr)
  - find <dataDir> tag update path of data directory  in ${solr.data.dir:DATA_PATH}
    (here DATA_PATH in our case D:/Solr/example/solr/data so ${solr.data.dir:D:/Solr/example/solr/data})

7) Create solr.xml into D:/tomcat/tomcat****/conf/Catalina/localhost with below content...
      <?xml version="1.0" encoding="utf-8"?>
      <Context docBase="SOLR_WAR_PATH" debug="0" crossContext="true">
        <Environment name="solr/home" type="java.lang.String" value="SOLR_HOME_PATH" override="true"/>
      </Context>
     ( here,
      SOLR_WAR_PATH is D:/Solr/example/solr/apache-solr-1.4.0.war
      SOLR_HOME_PATH is D:/Solr/example/solr)
8) Now start Solr tomcat from D:/tomcat/tomcat****/bin
9) After start successful of tomcat open solr server in your browser with this link
    http://localhost:port/solr (ex http://localhost:8081/solr)
    If you seen "Welcome to Solr!" screen with "Solr Admin" link then congratulation solr   configuration is done successfully.

Integration/Configuration of Solr plug-in with liferay

1) Download solr-plugin war file for liferay supported version from here ...

2) Put solr-plugin war file into "$LIFERAY_HOME/deploy" directory

3) Start Liferay tomcat to deploy solr plugin into portal.

4) Once liferay tomcat start successful. then stop both liferay tomcat and solr tomcat instance
      NOTE: Now liferay webapps contain "/solr-web" directory

5) Open solr-spring.xml from the $LIFERAY_HOME/tomcat/webapps/solr-web/WEB-INF/classes/META-INF

6) Find string {class="com.liferay.portal.search.solr.server.BasicAuthSolrServer"} which is in one of <bean> entry.

7) Inside that <bean> chagne the value as "solr_url" in value attribute of <constructor-arg />   e.g. <constructor-arg type=”java.lang.String” value=”http://localhost:8081/solr” /> 

8) Replace solr instance schema.xml copy from $LIFERAY_HOME/tomcat/webapps/solr-web/WEB-INF/conf/schema.xml  and paste into $SOLR_HOME/exmple/solr/conf

Finally you have done with configuration of solr with Liferay.

Now, Let's confirm weather is it correct configuration or wrong?  by follow below steps.
1) Open Solr tomcat instance first then liferay tomcat instance

2) Goto control_panel -> server administartion-> reindex all data from here

3) Look into solr tomcat server log : solr log change during reindexe from liferay server
   if it's change it means solr configuration is perfect.


That's it.
Enjoy with Solr!!

Note: here solr tomcat port is change to 8081 because both server not start at same time with same port number. you can change according to that.

Friday, August 23, 2013

ECJ Error : Task cannot continue because ECJ is not installed.

Hi all,

Many of java developer use ANT build tool for his project build process. many of us we got this kind of error. so, here i the solution to resolve this.

Please follow below steps...
1) Download ecj.jar file from  this link                                                                                                  "http://mvnrepository.com/artifact/org.eclipse.jdt.core.compiler/ecj/3.5.1"
2)  Goto the   Window -> Preferences 
     (this will display popup windos)

3)  Click On Ant  -> Runtime 

4) Click on Classpath tab 

5) Select Ant Home Entries (Default) option

6) Click on Add External JARs.. button

7) Select Downloaded file from directory -> open

8) Click on Ok


Now, build your project again with ant command. i am sure you will not get this error again.

That's it!!
Enjoy the code!!


Thank you,
Ketan Savaliya

Map Iterator/loop in java

Many time some little things goes our of our mind. Same thing happen in developer life also.So, here i am going to write a small piece of java code which is used daily routine.

Here i am talking about Collection framework Iteration of MAP.

When ever developer need Map almost all time they go to google for how to iterate MAP? so, ans for this question i am going to write small blog about MAP iteration. Bellow is the example for the same.

About Map : Map is part of collection framework. Mainly use to store data in key,value manner. Given a key and a value, you can store the value in a Map object. After the value is stored, you can retrieve it by using its key. now we go through step by step how to use MAP.



1) Declaration of MAP
        Map<String,String> stringMap = new HashMap<String, String>();

2) Store data into MAP

        stringMap.put("1","Apple" );
        stringMap.put("2","Ball");
        stringMap.put("3","Cat");

3) Iteration/Loop/Use of MAP

There are so many ways you can iterate MAP in java. but here i am going to simple way to iterate MAP in java as per my knowledge.
       - by Iterator
       - by EnterySet
       - by keySet

Here we use keySet to iterator MAP. this is very simple way as per my development experiance. like...

         for(String key : stringMap.keySet()){
                 System.out.println("Key : " + key + ", Value : " + stringMap.get(key) );
         }


4) Exmaple

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class test {

    public static void main(String[] s){
       
        Map<String,String> stringMap = new HashMap<String, String>();
        stringMap.put("3","Cat");
        stringMap.put("1","Apple" );
        stringMap.put("2","Ball");
       
        for(String key : stringMap.keySet()){
            System.out.println("Key : " + key + ", Value : " + stringMap.get(key) );
        }
 }

}


5) Output

Key : 3, Value : Cat
Key : 2, Value : Ball
Key : 1, Value : Apple

It's simple right? still we have to go googling for every time to iterate map. i ma sure this blog visit help you remember iteration of map.

That's it!!

Enjoy the code!!


Thank you,
 Ketan Savaliya


Tuesday, August 6, 2013

Web content data display in custom-portlet

Many more time during development we need display liferay web-content in our custom-portlet.
Liferay taglib already give tag to display web-content data.

Here is syntax for "<liferay-ui:journal-article/>"

<<liferay-ui:journal-article showTitle="true/false" articleId="longArticleId" groupId="longGroupId" />


Let take an example...

<<liferay-ui:journal-article showTitle="false" articleId="<%= journalArticleId%>"
groupId="<%= themeDisplay.getScopeGroupId() %>" />

here journalArticleId is long var which is articelId of web-content