Thursday, July 28, 2016

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


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