Posts

Showing posts from December, 2013

Adding portlet in control panel

Image
Open the liferay-portal.xml and add the following these 2 entries.     1. <control-panel-entry-category>content </control-panel-entry-category>(Mandatory)     2. <control-panel-entry-weight>2.0 </control-panel-entry-weight>(Mandatory)     3.<control-panel-entry-class>  your-custom-class </control-panel-entry-class>(Optional) 1. Category is nothing but that which section your portlet should be appear in the control panel. If you see   the below screen shot it shows 4 options       my,content,portal,server 2. Low value it appears higher in the section 3. It is optional , If you didn't specify this entry it will take default class which defined in the portal.properties     #     # Set the name of a class that implements     # com.liferay.portlet.ControlPanelEntry. This class denotes the default     # value of of the element "control-panel-entry-class" in liferay-portlet.xml     # and is called by the Control Panel to dec

Calling service classes in from webcontent

Follwing URL gives what are the variables can be access in the CMS template. http://www.liferay.com/community/wiki/-/wiki/Main/CMS+Internal+API http://www.liferay.com/es/community/wiki/-/wiki/Main/Access+Objects+from+Velocity http://www.liferay.com/web/raymond.auge/blog/-/blogs/custom-velocity-tools-and-liferay-6-0 If we see the  $request output, it gives manythings. Some it requires to access the services from the custom portlet . We need to add property in portal-ext.properties .  If we find the "journal.template.velocity.restricted.variables" it contains key value as serviceLocator. Whenever we are adding the property in a file we need to remove the "serviceLocator" form below  and add it as below.     #     # Input a comma delimited list of variables which are restricted from the     # context in Velocity based Journal templates.     #     journal.template.velocity.restricted.variables= After restarting the server we can acce

Embedding portlet in a webcontent

We can embed portlet in a web content by using the following tag   <runtime-portlet name ="33"></runtime-portlet>  // here we are embedding the blogs portlet 1.Create the web content by selecting the basic web content .      Enter the title and when entering the content click on the source of the CKEditor and place the above tag in the editor.     Click on the Save button.       Place the web content display portlet in the  portal . select the appropriate web content . Then you see the Blogs portlet added in the web content.

Internationalization for custom portlet in liferay

Here  the following points are to define Internationalization in custom portlet      1. Create <resource-bundle>content/Language</resource-bundle> in portlet .xml before supports tag.      2. Create folder content in docroot/WEB-INF/src path and create Language.properties  file in content folder.       3. write the entries in the Language.properties file or language_fr.properties file as                 search-title = Search Title       4. In our JSP add the liferay tag  to detect the property.                  <liferay-ui:message key="search-title"/>           Also you can use LanguageUtil Utilty class to get entries

Creating Filter in custom portlet

Here we will do how access the portlet filter. These portlet filter which introduced in JSR-286. We will go through the how to create filter in customportlet. STEP:1 Here i am create the portlet filter when an action takes place i.e whenever there is an Action Request. Create the class the " ActionJSONFilter " which implements " ActionFilter " public class ActionJSONFilter implements ActionFilter Also we can implement the RenderFilter also ResourceFilter . All these are in the javax.portlet.filter.*; package. public class ActionJSONFilter implements ActionFilter { public void destroy() { System.out.println("destroy"); } public void init(FilterConfig arg0) throws PortletException { System.out.println("init"); } public void doFilter(ActionRequest arg0, ActionResponse arg1, FilterChain arg2) throws IOException, PortletException { System.out.println("doFilter"); } } STEP:2  Define the below e

Obtaining DB Connection

We can get the DB Connection by using the DATA ACCESS class. If we look into this class . It Contains many methods. 1. getConnection() 2. getConnection(String location) 1.cleanUp(Connection connection) 2.cleanUp(Connection connection, Statement statement) By Using these methods we can get Connection and we can cleanup connection. Connection Con = DataAccess.getConnection(); --------- --------- DataAccess.cleanUp(con);

Generating Stubs(webservices) in Liferay

Generating stubs in liferay , 1. we can generate the stubs in eclipse as         File ---> New ---> Others --->type webservices and select webservices client ---> Paste the WSDL in the service defination and move the slide till to TestClient and click on the "finish" to generate. WSDL can of type below http://localhost:8080/api/axis/Portlet_Blogs_BlogsEntryService?wsdl When i am trying to do in liferay eclipse it is not allowing to generate the stubs. So i am used Plain tomcat to generate the stubs. 2. We can also generate the stubs by ant    Drag and Drop the build.xml in ant    Locate the build-client . Double click on it . It Generate the <portlet-name>-portlet-client.jar file in the docroot/WEB-INF/client folder.      This lib contains the stubs. By Using that stubs we can write the our own implementations.

Accesing the webservices using REST

Here i am trying to delete the blogsEntry. Here is the sample code for the REST based application    String uri = "http://localhost:8080/api/secure/jsonws/blogsentry/delete-entry";      String userName="test@liferay.com";    String password = "test";      Credentials credentials = new UsernamePasswordCredentials(userName, password);      HttpClient client = new HttpClient();    client.getState().setCredentials(AuthScope.ANY, credentials);    client.getParams().setParameter("http.useragent", "Test Client");    client.getParams().setAuthenticationPreemptive(true);        PostMethod postMethod = new PostMethod(uri);    postMethod.addParameter("entryId", "10101") ;      int returnCode = 0;    try {     returnCode = client.executeMethod(postMethod); } catch (IOException e) { e.printStackTrace(); }

Order by Comparator

Whenever we create finder method by default it generates many methods associating with it starts by method name as  findBy ..... Sometimes it may requires you to display the results in the ASC/DESC. So we have one method which accepts OrderByComparator as parameter. Below example explains you how to retrieve the Title in the Ascending order. OrderByComparator comparator = OrderByComparatorFactoryUtil.create(TestModelImpl.TABLE_NAME, "title", orderByType.equals("asc")) jsonTestEntryPersistance.findByTitle("name",comparator);