Search This Blog

Showing posts with label liferay. Show all posts
Showing posts with label liferay. Show all posts

Friday, November 8, 2013

Configure Cron Job for Schedulers


Cron

"Cron" is a UNIX tool which works as time-based job scheduler . The cron jobs can be configured by writing cron expressions which , the scheduler can understand. In this article we will show sample examples of cron expressions to understand it's configuration. 'CronTrigger' class uses the scheduling capabilities of cron to trigger the scheduler functions.

The Cron Expression

The cron expressions are  strings of texts made up of six or seven values separated by white space. The values are actually field positions which refer to a particular unit of time. The values are restricted to a specific syntax and numbers along with some special characters.

Position/TimeUnit Required Restricted Values  Restricted Special Characters
  1  Seconds    Yes        0-59           , - * /
  2  Minutes    Yes        0-59           , - * /
  3  Hours    Yes        0-23           , - * /
  4  Day of month    Yes        1-31           , - * ? / L W
  5  Month    Yes    1-12 or JAN-DEC           , - * /
  6  Day of week    Yes    1-7 or SUN-SAT           , - * ? / L #
  7  Year    No    empty, 1970-2099           , - * /


  • '*' (all values):-wildcard used to mean all values in possible in the time unit.

  • '?' (any specific value, only for day-of-month and day-of-week ):- like * but limited to the mentioned fields only
  • '-'  (ranges of values):- like 1-2 would mean 1-2 units of time.
  • ',' (separated specific values):- 1,5 would mean cron will run only on 1st and 5th unit of time.
  • '/' (incremental value):- "0/10" would mean cron will run only on every 10th unit of time.
  • 'L' (last unit of time) :- "L in Day of month" would mean cron will run only on the Last day of the month. Similarly last day of year, week.. etc .
  • 'W' (nearest weekday) :- "10W" at the day-of-month field, would mean : "the nearest weekday to the 10th of the month"..
 note:- 'LW' at day-of-month field would mean last weekday of the month.
  • '#'(specific day of month) -  "1#2" in the day-of-week field would mean : "the second Monday of the month".(i.e.daynumber#occurance in the month)

The Cron Expression Examples
 
Cron Expression Time Meaning
0 0  13 * * ? Run at 13pm daily.
0 20 9 ? * * Run at 9:20am daily.
0 25 9 * * ? Run at 9:25am daily.
0 25 6 * * ? * Run at 6:25am daily.
0 5 11 * * ? 2013 Run at 11:5am daily, throughout the year 2013
0 * 15 * * ? Run every minute, starting at 3pm and ending at 3:59pm, daily.
0 0/10 17 * * ? Run every 10 minutes starting at 5pm and ending at 5:55pm, daily.
0 0/10 17,18 * * ? Run every 10 minutes starting at 5pm and ending at 5:55pm, AND Run every 10 minutes starting at 6pm and ending at 6:55pm, daily.
0 0-10 10 * * ? Run every 1 minute starting at 10am and ending in 10 minutes, daily.
0 10,20 10 ? 4 Fri Run at 10:10am and at 10:20am every Friday in the month of April.
0 25 20 ? * MON-FRI Run at 8:25pm every weekday.
0 20 9 10 * ? Run at 9:20am on the 10th day of every month
0 20 9 L * ? Run at 9:20am on the last day of every month
0 20 9 L-3 * ? Run at 9:20am on the 3rd-to-last last day of every month
0 20 9 ? * 6L Run at 9:20am on the last Friday of every month
0 20 9 ? * 6L Run at 9:20am on the last Friday of every month
0 20 9 ? * 6L 2002-2005 Run at 9:20am on every last friday of every month during the years 2002, 2003, 2004 and 2005
0 20 9 ? * 6#3 Run at 9:20am on the third Friday of every month
0 0 13 1/15 * ? Run at 13pm every 15 days every month, starting on the first day of the month.
0 12 12 12 12 ? Run every December 12th at 12:12am.


Happy coding :)

Friday, October 18, 2013

To make JSP compatible with IE8 or IE 9

Add the following code to the javascript block.

#if ($browserSniffer.getMajorVersion($request) < 9)
  <meta http-equiv="X-UA-Compatible" content="IE=8" />
#else
  <meta http-equiv="X-UA-Compatible" content="IE=9" />
#end

this will make the jsp compatible with IE 8 or IE 9

Happy Coding !!

 

Monday, September 30, 2013

Session timeout redirection

The session timeout can be handled using few properties in the portal-ext.properties file. .

# Extending session automatically
session.timeout.auto.extend=false



#This property can be used to redirect to home page when the session expires.
session.timeout.redirect.on.expire=true

#Set the login url
auth.login.url=/web/guest/home


note :
for session.timeout.warning=30,
#it is redirects to http://localhost:8080/web/guest/home

for session.timeout.warning=0,
#it is redirects to
#http://localhost:8080/web/guest/home?p_p_id=58&p_p_lifecycle=0&p_p_state=maximized&p_p_mode=view&saveLastPath=0&_58_struts_action=%2flogin%2flogin&_58_redirect=%2fweb%2f10311%2fwelcome

Translate Liferay in Your Language.(Pootle)



Now, it is your opportunity to translate Liferay in your own language. Liferay has started a forum for the ardent Liferay lovers to collaborate and translate the entire portal in their own language. This helps the community to customize and present their products with their own liking in their own language. The translate project also shows the percentage of completion of the entire project for each language. Here are two snapshots of the project updated to 30th Sept 2013.




 Liferay Translate or Pootle Here is the link to the project:- http://translate.liferay.com/pootle/ The project can also be accessed through the menu on our home page. Happy Translating Liferay!!

Wednesday, September 11, 2013

Add "HTTPOnly" and "Secure" attribute to Cookie for Liferay

Here are the ways
---------------------------
Secure Attribute
Writing a servlet filter to overwrite the session cookie:

private void rewriteCookieToHeader(HttpServletRequest request, HttpServletResponse response) {
if (response.containsHeader("SET-COOKIE")) {
String sessionid = request.getSession().getId();
String contextPath = request.getContextPath();
String secure = "";
if (request.isSecure()) {
secure = "; Secure";
}
response.setHeader("SET-COOKIE", "JSESSIONID=" + sessionid
+ "; Path=" + contextPath + "; HttpOnly" + secure);
}
}
------------------------

HTTPOnly Attribute

Go to Tomcat conf/context.xml file ,add

restart tomcat.

Unable to download documents from Document Library

This is one of the showstopper issue which people face when they use Liferay 6.1.20 EE GA2 with SSH. and IE 8,7 as the browser. While it works on other browsers like Firefox.The documents from the document library are not available.

Reason:

When the server uses SSL (https os Secure Socket Layer). The apache adds the following to the http headers.

Pragma: no-cache
Cache-control: no-cache,max-age=0,must-revalidate


The IE Browser is  not allowed to store the document in the local system and thus it fails to download the object.

refer:
response.setHeader( HttpHeaders.CACHE_CONTROL, HttpHeaders.CACHE_CONTROL_PUBLIC_VALUE);

present in the classes ServletResponseUtil, PortletResponseUtil.

Here is a link to the microsoft support , which explains the browser issue .
http://support.microsoft.com/default.aspx?scid=kb;en-us;316431

Solution:

Solution 1. Override the code of the classes ServletResponseUtil, PortletResponseUtil. in the setHeaders(request, response, fileName, contentType) method.

                           (or)

solution 2. Add the following line to the apache config file.


        Header unset Pragma

This will remove the pragma entry from the header and the issue would be solved. 






Tuesday, July 30, 2013

SAP Error Codes

The SAP native error codes during its integration with other technologies are always difficult to understand.. Here is a possible list of standard SAP Error Codes

/**********************************************************************/

/* Standard error codes.                                              */

/**********************************************************************/


ECodeECodeECodeECodeECodeECodeECodeECodeECodeECodeECodeECodeECodeECodeECodeECodeECodeECodeECode



Wednesday, July 24, 2013

Form re submission of/on Page Reload Errror

The property 'action-url-redirect' must be added to the liferay-portlet.xml file. This will not allow the form to be re submitted once the page is refreshed after a form submission is already done.




By default the property is false and thus the form resubmission occurs

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.

Tuesday, July 16, 2013

Enable Transactional cache in Liferay

RSS Portlet Connection Timeout

The property 'rss.connection.timeout' must be added to the Portal-ext.properties file.
Set the timeout in milliseconds like,
rss.connection.timeout=2000
This makes the RSS reades wait untill 2 seconds for reading the RSS feeds before timeout.

Show / Hide Lookand Feel Icon on a Liferay portlet

The property 'portlet.css.enabled' must be added to the Portal-ext.properties file.

If made true,

portlet.css.enabled=true

# shows the 'Look and Feel' icon on the portlet titlebar. Enabling the user to edit it.This is default.

If made false,

portlet.css.enabled=false

# hides the 'Look and Feel' icon on the portlet titlebar . Disabling it can speed up the portal performance.

How to get the current logged in user in liferay

There are more than one way to do this. Let's look at some of the options available.
  1. User user = (User) request.getAttribute(WebKeys.USER);
    The User class is the Liferay's model User class.

  2. ThemeDisplay td  = (ThemeDisplay) request.getAttribute( WebKeys.THEME_DISPLAY );
    User user = td.getUser();


    This ' ThemeDisplay 'class can be used to get various information about the portal page,user and theme. Classes ThemeDisplay, User and WebKeys are available in portal-service.jar

  3. User currentUser = PortalUtil.getUser( request );

    The 'PortalUtil' has various utility functions , which come handy during Liferay Programming. This is also a part of the Portal-service.jar.

  4. LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
    User currentUser=liferayFacesContext.getUser();


    The class 'PortalFacesContext' has been renamed to 'LiferayFacesContext'.This class exists in order to assist with migrating old JSF 1.2 based projects from the legacy PortletFaces-Tools project to the new LiferayFaces project.

    Hope It helps you in your portal programming. Happy Coding :)


Friday, July 16, 2010

Add Javascript to Ice Faces or Facelets

There are several ways to add JavaScript code to an ice faces page. One of which is explained here.The "Direct to Dom" (akaD2D) rendering of icefaces makes it difficult to add javascript or any other code to it.

Q. Where to add the code? .
Ans. The answer is to put the < script type="text/javascript"> just code after the < ice:root> between < html> < head> .add the javascript in the similar way as you add it in jsp/html. then close the tag and at the end before closing the root (i.e < /ice:root> ) add the < /html> tag.

Q. How to call an icefaces componet?
Ans. Use the formname:componentid format to use it in the javascript function.

Q. How to use the body onload thing without using body tag.
Ans. The answer lies in using the window event.

Here is an example which makes everything clear


< jsp:root version="2.0" f="http://java.sun.com/jsf/core" h="http://java.sun.com/jsf/html" ice="http://www.icesoft.com/icefaces/component" jsp="http://java.sun.com/JSP/Page">
< f:view>
< script type="text/javascript>
function setFocusOnLogin(){ document.getElementById("icefaces_formaname:icefaces_component_id").focus(); }//its used to call the icefaces component's focus event
window.attachEvent("onload", setFocusOnLogin);//like body onload , its called on page load < /script>
< ice:portlet>
< ice:form id="icefaces_formaname">
< ice:inputtext id="icefaces_component_id" size="10">
< /ice:inputtext>
< /ice:form>
< /ice:portlet>
< /f:view>
< /jsp:root>

Hope you get it. For any concerns feel free to post a comment.

Tuesday, January 27, 2009

ProcessAction Method

ProcessAction() Method

The JSR-168 Specification defines a portlet container that manages portlets.Each portlet’s life cycle contain some specific methods as per JSR-168 namely init(),ProcessAction(),destroy() method etc. . The portlet developer can implement these methods to provide the desired functionality.Among all the life-cycle methods of a portlet one of the most important method is the ProcessAction() method.This ProcessAction() method is Called after the user submits changes to a jsr-168 compliant portlet. It is Intended to process input from a user Interaction.The user must interact with the portlet giving some or the other kind of data to it which must be processed by a portlet.This way we can say that the portlet processing is done in the ProcessAction() method.Even if one tries to maximize the size of the portlet window it calls the ProcessAction() method.

public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException
{
}

The processAction() method is called only by the ActionURL. The other URL i.e RenderURL doesnt invoke the processAction() method.When the form submit button is pressed, the action url is used. The action url indicates to the portal that it is an action request. Responding to the action request, the portal invokes the processAction() method before invoking the render() method.

The request values are obtained from the actionURL in the following way

public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException
{
// get the values submitted with the form

String identity = request.getParameter("parameter1");
String color = request.getParameter("parameter2");

......
}

the way we set the render parameters for the render() method is

public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException
{

......

response.setRenderParameter("parameter1", value1);
response.setRenderParameter("parameter2", value2);
}

Wednesday, January 21, 2009

JSR 168 Portlet Specifications

Agenda

What are JSR and JCP?
• What is a Portlet as per JSR 168?
• JSR168 Specifications
  1. Portlet Lifecycle Methods
  2. Portlet Modes
  3. Portlet Window States
  4. Portlet Data Models
  5. Dispatching requests
  6. Caching and Security.
• A sample Portlet.


What are JSR and JCP?

JCP – Java Community Process

The international Java community develops and evolves Java™ technology specifications using the Java Community Process (JCP).The community is involved in the definition of future versions and features of the Java platform. Since its introduction in 1998 as the open, participative process to develop and revise the Java™ technology specifications, reference implementations, and test suites, the Java Community Process (JCP) program has fostered the evolution of the Java platform in cooperation with the international Java developer community.

JSR-Java Specification Request

A JSR is a Java Specification Request. This is the document submitted to the PMO (The Program Management Office is the group within Sun designated to oversee the Java Community Process and manage the daily running of the program. The actual development of the specification occurs within the Expert Groups.) by one or more members to propose the development of a new specification or significant revision to an existing specification.

Courtesy- http://www.jcp.org/en/introduction/faq
http://en.wikipedia.org/wiki/Java_Community_Process

What is a Portlet as per JSR 168?

General Perception
– A portal is a webpage with many different links to various applications.

• Programmer’s View
– “A portal is a web based application that –commonly- provides personalization, single-sign on, content aggregation from different sources and hosts the presentation layer of Information Systems.”- JSR 168 spec

Now we must come across a series of questions..for better understanding.

A series questions (3W and 1H)
1. What is a Portlet?
2. What is Portal Page?
3. What is the difference between a portal page with many links and a portal page with portlets?
4. How is it different from a page with lots of links?

Portlet

• “A portlet is a Java technology based web component, managed by a portlet container, which processes requests and generates dynamic content.”
-- JSR 168 spec
• A portlet is itself an application having its own lifecycle.

Portlets and relationship with Portals

• “Portlets are used by portals as pluggable user interface components that provide a presentation layer to Information Systems.”
--JSR 168 spec
• So now we know how its entirely different from a website containing a lots of links apparently called portals

So it’s obvious that portlets are the basic building block of a successful web Portal where each portlet is assigned to do some specific task and the user is able to gather maximum information on a single page. The portal itself provides the user management capability and users have the facility to single sign on to use all the facilities provided by the entire portal. Personalization is also one of the most important features a portal provides. All these things are much more difficult and developed separately on a traditional portal page which is just a page with bunch of links. Ease of “plug in and run” concept and ease of removal from the portal page gives a new age portal a winning edge over traditional portals

JSR168 Specification
• Portlet Lifecycle Methods
• Portlet Modes
• Portlet Window States
• Portlet Data Models


Portlet Lifecycle Methods

This life cycle of a portlet is expressed through the init (), processAction(),
Render() and destroy() methods of the Portlet interface. The Portal calls the init() method to instantiate the portlet. Then the browser requests are handled by the portlet using ProcessAction() method if the request involves some kind of data processing. Else the render method takes care of it by rendering the page using either doView(),doEdit() or doHelp().Remember the render method is called whenever

a. the processAction() method is called by action request.

b. the renderRequest() comes into picture which doesn’t involve data processing.

c. any other portlet on the same portal page calls the render() method.

Portlet Modes
Generally a portlet has three modes
a. View mode –normal mode to show the content.

b. Help Mode –to show a help page about the application.

c. Edit mode –to show edit page for editing the portlet preferences.

d. But a portal can also have a “custom mode” if the manufacturer wishes to have.

Portlet Window States

• NORMAL

• MAXIMIZED

• MINIMIZED

• CUSTOM –based on manufacturer discretion.

Portlet Data Models

• Portlet to store view information in the “render parameters.”

• Session related information in “portlet session”

• User persistent data in the “portlet preferences”

Portlet Request Dispatcher

• It dispatches the request to other portlets or servlets using the Portlet request Dispatcher with the only Include () method.

Caching and Security

• Portlets that want their content to be cached using expiration cache must define the duration (in seconds) of the expiration cache in the deployment descriptor.
• Security constraints are a declarative way of annotating the intended protection of portlets. A constraint consists of the following elements:
  1. Portlet collection
  2. User data constraint

Can We Design a sample Portlet with the basic knowledge about portlets….???

My Blog List