Wednesday 13 January 2016

How to create Friendly URL for Liferay portlet

  • Q-What is friendly URL?
  • ans: Friendly URL is a technique to make short portlet URL.
  • To make friendly URL, we need to define router xml for that portlet.
  • In this router xml, we can define various parameters (implicit , explicit etc).
  • We can define multiple friendly URL for same portlet.
 Step1--first we need to create friendly-url-router.xml  inside src.
example:-
<?xml version="1.0"?>
<!DOCTYPE routes PUBLIC "-//Liferay//DTD Friendly URL Routes 6.2.0//EN"
"http://www.liferay.com/dtd/liferay-friendly-url-routes_6_2_0.dtd">

<routes>
    <route>
        <pattern>/{jspPageName}</pattern>
        <generated-parameter name="jspPage">/html/controller/{jspPageName}.jsp</generated-parameter>
        <implicit-parameter name="p_p_lifecycle">0</implicit-parameter>
        <implicit-parameter name="p_p_state">normal</implicit-parameter>
        <implicit-parameter name="p_p_mode">view</implicit-parameter>
    </route>
</routes>

Step2- we need to add three line code in liferay-portlet.xml

<icon>/icon.png</icon><friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class><friendly-url-mapping>ekhub</friendly-url-mapping><friendly-url-routes>com/test/ccavenue-friendly-url-routes.xml</friendly-url-routes><instanceable>false</instanceable>

Tuesday 12 January 2016

Diffrence b/n Liferay MVC vs Spring MVC

  • Liferay MVC and Spring MVC are vastly used portlet framework to create portlets in Liferay.
  • Liferay MVC is a lightweight framework which can be used to create portlet if it contains less complex render / resource logic and few action methods.
  • On other hand Spring MVC is full fledged portlet framework. It provides many functionality.
  • Liferay MVC can have just one render method. However liferay provides mechanism to render different jsps at runtime. render URL is used to call render method.
  • Spring MVC portlet provides multiple render methods. There will be one default render method which is called by default. To call other render methods, you need to pass render method mapping key to action parameter while creating render URL.
  • You can use Liferay MVC for simple portlet creation. Spring MVC Portlet framework can be used where you have complex render  / resource logic and you need spring integration in your portlet.
  • Liferay MVC vs Spring MVC is always debatable topic. You should choose the appropriate framework while created portlet based on you requirement
  • You may refer this link to create portlet in Liferay.
  • Action Methods
    • Both Liferay MVC and Spring MVC frameworks supports multiple action methods.
  • Resource Method
    • In Liferay MVC, you can define just one resource method.
    • In Spring MVC, you can define multiple resource method.

Following are the steps to implement Custom SQL

Following are the steps to implement Custom SQL
  1. Create Simple Liferay MVC Portlet
  2. Define entity in service.xml
  3. Run the Service Builder
  4. Create SQL queries configuration XML file (Custom SQL XML file)
  5. Write Native SQL in Custom SQL xml file
  6. Create Finder Implementation class
  7. Run the Service Builder
  8. Implement Required Custom SQL Method in Finder Implementation Java Class
  9. Run the Service Builder
  10. Write Custom Service Method in respective Local Service Implementation Class
  11. Run the Service Builder
  12. Use Respective Local Service Util class to call service method

How to increase String column size in a ServiceBuilder generated service?

Step1:Now the issue is that Strings here are mapped to a 75 VARCHAR in the database by default, but you can change that in the portlet-model-hints.xml file by specifying a max-length hint for the given field entry. Here's an example how to increase it to 500 for instance:
1
2
3
4
5
6
<model name="my.package.model.DummyEntity">
 <field name="id" type="long"></field>
 <field name="description" type="String">
  <hint name="max-length">500</hint>
 </field>
</model>