Showing posts with label Liferay Custom Portlet. Show all posts
Showing posts with label Liferay Custom Portlet. Show all posts

Thursday, December 26, 2013

Friday, November 29, 2013

Kaleo Workflow Configuration for Custom Portlet in Liferay 6.1

1. Make sure you have deployed kaleo workflow war in your liferay portal.

2. Create the service.xml


3. Build the service

4. Edit the FeedbackLocalServiceImpl class and add the following methods:



5. Make the following entries in liferay-portlet.xml file



6. create the FeedbackAssetRendererFactory class



7. create the FeedbackAssetRenderer class-



8. create the /html/feedback.jsp file.


9. create the FeedbackWorkflowHandler class -



10. We are done with all the changes now, to see our portlet in action go to control panel → Workflow Configuration and set the workflow for your custom portlet.

Tuesday, November 19, 2013

Hiding SessionErrors Default Error Message

Whenever we make use of SessionErrors to display error message in Liferay, below default error message is also displayed by Liferay.



To get rid of this default message use the below code snippet -

NOTE: This will work for specific portlet only.

Monday, November 18, 2013

Monday, September 9, 2013

jQuery Autocomplete in Liferay Custom Portlet

In the following post we are going to implement jQuery Autocomplete in our custom portlet.

1. create the service.xml file-

2. Add the finder method in StudentLocalServiceImpl class-

3. Put the jquery js files in docroot/js folder and add the following entries in liferay-portlet.xml file -

4. view.jsp file-

5. Add the following methods in portlet class-

Sunday, September 1, 2013

Connecting Liferay with Another Database

In the following post we will connect liferay with some third party database (legacy database):

Method 1:

1. Create Service.xml

2. Create ext-spring.xml file as /WEB-INF/src/META-INF/ext-spring.xml

You wont believe but yes we are done!!


Method 2:

1. Make an entry in portal-ext.properties file for another database:

2. create service.xml:

3. create ext-spring.xml file:


done!


NOTE: In both the above methods, we have to create the table manually in the database.

Liferay Permission on Custom Portlet

As mentioned on Liferay Dcoumentation we can add permissions to your custom portlets using four easy steps (also known as DRAC):

1. Define all resources and their permissions.
2. Register all defined resources in the permissions system. This is also known as adding resources.
3. Associate the necessary permissions with resources.
4. Check permission before returning resources.

Here we are implementing Liferay Permission for custom portlet named StudentMaster.

1. The first step is to define your resources and the actions that can be defined on them. Create a file named default.xml in /src/resource-actions folder -


2. After defining resource permissions for our custom portlet, we need to refer Liferay to the resource-actions XML file that contains definitions. Create a properties file named portlet.properties that references the the file default.xml. In this portlet properties file, create a property named resource.actions.configs with the relative path to portlet’s resource-action mapping file (e.g.default.xml) as its value. Here’s what this property specification might look like:


3. Adding a Resource

After defining resources and actions, it’s time to add resources into the permissions system. Resources are added at the same time entities are added to the database. Each Entity that requires access permission must be added as a resource every time it is stored.

4. Adding Permission:

On the portlet level, no code needs to be written in order to have the permission system work for custom portlet. If we have defined any custom permissions (supported actions) in configuration file’s portlet-resource tag, they’re automatically added to a list of permissions in Liferay’s permissions UI. What good, however, are permissions that are available but can’t be set by users?
To let a user set permissions on model resources, we must expose the permission interface to the user. Just add these two Liferay UI tags to JSP:
1. : Returns a URL to the permission settings configuration page.
2. : Shows an icon to the user. These are defined in the theme, and one of them (see below) is used for permissions.

5. Checking Permission:


Thursday, August 23, 2012

Liferay Custom JSON Web Service Development



Following is the step by step description of generating a custom liferay plugin service and exposing it as JSON Web Service.



STEP:1 Create a liferay plugin project and create new service


Here is the sample service.xml



Make sure remote-service=”true” in entity tag declaration.



STEP:2  Build the service.



STEP:3  Add your custom method in SampleLocalServiceImpl class



STEP:4  Build the service.



STEP:5  Add the method definition to SampleServiceImpl class



STEP:6  build the service.



STEP:7  Add the following <servlet> and <servlet-mapping> Entries to portlet's web.xml file -



STEP:8  deploy the portlet.


STEP:9  To access your json web services enter the following url -

http://localhost:8080/<<portlet-context>>/api/jsonws





and Its Done!!!





Sunday, June 26, 2011

Extending Web Form Portlet – Adding File Upload Control

In Liferay Portal, Web Form Portlet is used to create custom forms but the types of field that can be created are limited. One such missing field type is File Upload Control. It’s a common requirement to have file upload control in forms.


Following are the steps to add File Upload Control to Web Form Portlet -


1.  Add a new field type to edit_field.jsp

<aui:option selected='<%= fieldType.equals("file") %>' value="file"><liferay-ui:message key="file" /></aui:option>

2.  Accordingly update the view.jsp to render the your new field

<c:when test='<%= fieldType.equals("file") %>'>

<aui:input cssClass='<%= fieldOptional ? "optional" : StringPool.BLANK %>' label=" <%=HtmlUtil.escape(fieldLabelDisplay) %>" name="<%= fieldName %>" type="file" value="<%=HtmlUtil.escape(fieldValue) %>"/>

</c:when>

3.  Set the preferences for this field in ConfigurationActionImpl.java

boolean isFileUpload = false;

if ("file".equals(fieldType)) {

isFileUpload = true;

}

preferences.setValue("isFileUpload", String.valueOf(isFileUpload));

4.  Finally get the file in WebFormPortlet.java and proceed with your implementation…

File file = uploadRequest.getFile(paramName.toString());

Proceed we the implementation with file object for example save to document library, send in mail etc.

 

 

Friday, May 6, 2011

Adding Portlet Preferences to Custom Portlet

The portlet preferences are intended to store basic configuration data for portlets. The PortletPreferences interface allows the portlet to store configuration data, not to replace the general-purpose databases.
Normally, there are two different types of preferences: Modifiable and Read Only.
Modifiable preferences can be changed by the portlet in any standard portlet mode (for example, EDIT, HELP, and VIEW). While Read-Only preferences cannot be changed by the portlet in any standard portlet mode, they may be changed by administrative modes.

By default, preference is modifiable.

Following are the steps to add portlet preferences (configurations) to custom portlet:

1. Add a configuration.jsp file:


2. Create an ConfigurationActionImpl class :


3. Made an entry in liferay-portlet.xml file:

<configuration-action-class>ConfigurationActionImpl</configuration-action-class>

4. Just Fetch and use the preferences:


5.Adding Preferences Default Value  to Portlet.xml:



In this way you can add any configuration options to the portlet and persist them portlet preferences.

If you have any questions or query, Please comment.....

Saturday, April 9, 2011

Display Journal Articles based on Tags

1. Have a long[] array containing Tag Ids for which you want to serach Journal Articles

long[] tagIds = {tagId1,tagId2,…..};

2. Create an AssetEntryQuery and set the tagIds as the criteria

AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
assetEntryQuery.setAllTagIds(tagIds);

3. Call the getEntries(AssetEntryQuery ob) method on AssetEntryLocalServiceUtil class to get the list of assetEntries

ListentryList = new ArrayList();
try {
entryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
} catch (SystemException e) {
e.printStackTrace();
}

4. Now iterate the list and pick classPK attribute for each entry and from that query JournalArticle Table for corresponding articleId.