Search This Blog

Friday, July 19, 2013

Running liferay script on control Panel Script console

Liferay has a script console at the Control Panel. It is accessible to the Liferay administrator. In the Script console Liferay API code , and other various code can be run seamlessly.

The script console is located at

ContolPanel --> Server --> Server Administration. 






 Here are few examples of codes run in the console and screenshot of the output. Most of the  codes were run here by selecting the Language as "Groovy".

Example 1.  Get list of users

Language : Groovy
code:

import com.liferay.portal.service.UserLocalServiceUtil;

userCount = UserLocalServiceUtil.getUsersCount();
users = UserLocalServiceUtil.getUsers(0, userCount);
count=0;
for (user in users) {
    count++;
    println(count+". User: " + user.getFullName());

}





































Example 2.  Get list of roles supported be the portal.


Language : Groovy
code:

import com.liferay.portal.service.RoleLocalServiceUtil;

roleCount =RoleLocalServiceUtil.getRolesCount();
roles=RoleLocalServiceUtil.getRoles(0,roleCount );

for(role in roles){
    println("Role Name: " + role.getName());
}




Example 3.  Get number of users in the portal . (using Javascript as language default script)
Language : Javascript
code:

number = Packages.com.liferay.portal.service.UserLocalServiceUtil.getUsersCount();

out.println(number);



How to Remove default Success Message your-request-completed-successfully



There are several ways to remove the message from displaying.


To remove the display use any of the following mentioned approach:

1. Remove entirely from a Portlet :
 Add this init param to your portlet.xml:


2. Remove  from specific  Portlet actions:
Add this to your implementation of processAction method.
SessionMessages.add(actionRequest, 
(LiferayPortletConfig)portletConfig.getPortletName()+ 
SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE);
  

3.Using Hook for HOOK for html\common\themes\ portlet_messages.jspf

a) remove the message display from all the portlets.



Comment out the lines , then the message will not be displayed for any of the portlets in Liferay at all.

b) remove the message display from specific portlets.

  create a hook and edit the portlet_messages.jspf file. Use the portletId to show/hide the message display. As shown

 

4. Masking with Custom Message in Portlet : Change that message key in your portlet's language.properties file with your custom text. Like, in the language_en.properties file for your custom portlet. add the custom message to the key:

 your-request-processed-successfully=Success! Process completed with no Errors. 

How to remove the message you-have-entered-invalid-data

There are several ways to remove the message from displaying. This message is present in the portal at the following path :-

   html\taglib\ui\error\end.jsp   


To remove the display use any of the following mentioned approach:

1. Using HOOK for all portlets :create a hook and edit the end.jsp file. In which you can comment out the lines , then the message will not be displayed for any of the portlets in  Liferay.

2. Using HOOK for specific portlet: create a hook and edit the end.jsp file. Use the portletId to show/hide the message display.


 


3. Masking with Custom Message in Portlet :
Change that message key in your portlet's language.properties file with your custom text.
Like, in the language_en.properties file for your custom portlet. add the custom message to the key:

   you-have-entered-invalid-data=Server Error: Please try again. 


4. Using CSS property:
Hook the file end.jsp (at html\taglib\ui\error\end.jsp ) with a surrounding CSS.


in the custom CSS of your portlet add

   .portlet-msg-error-invalid-data-show-hide{
     display : none;
   }

Wednesday, July 17, 2013

You are not allowed to use this program (crontab)

The crontab command used in unix sometimes shows the following error.

crontab -e
You (UnixUser) are not allowed to use this program (crontab)
See crontab(1) for more information
The system checks cron.allow file for allowing the user to use the crontab command. So, just add the user to the crontab.allow using the following command.
[UnixUser~]$ su
Password:
[root UnixUser]# echo UnixUser> /etc/cron.allow
 
Cron is driven by a crontab (cron table) file, a configuration file that specifies shell commands to run periodically on a given schedule.

XML Validation in Liferay

The property 'xml.validation.enabled' must be added to the Portal-ext.properties file.
If set false,

xml.validation.enabled=false

The xml files won't be validated inside the liferay. In some cases,where the xml,DTD ..etc files are kept external. This property can be used to avoid the validation errors.

My Blog List