tag:blogger.com,1999:blog-61558449818584063462024-03-20T01:22:40.099-07:00LiferayAnonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.comBlogger23125tag:blogger.com,1999:blog-6155844981858406346.post-36813263128707351062012-09-26T22:31:00.001-07:002012-09-26T22:31:21.259-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
Hi Friends,<br />
I could not write any new post due to my ill health and some personal as well as professional commitment. But I have decided now to write actively my experience while working with Liferay latest version i.e 6.x. In the meantime I am posting a link which have many solution. <a href="https://gist.github.com/rotty3000">RayAuge personal snippets</a></div>
Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com1tag:blogger.com,1999:blog-6155844981858406346.post-18376964870416055272011-04-13T03:45:00.000-07:002011-04-13T03:45:24.185-07:00Struts TipsHi Friends ,<br />
I was working on one of my j2ee project . From there I want to share few small but usefull tips for struts.In struts many time we caught in wrong side for duplicate page submission. I am going to share how to tackle that <BR> and how to pass parameter once redirect is done, one way is there to put parameters in session but it is messy.<br />
<B>Manage Redirect:</B><br />
It is quite simple we need to add one attribute redirect="true" in struts-config.xml<br />
e.g. <br />
<action path="{Action-Path}" type="{Action}" name="{Form-Bean}"><BR><br />
<forward name="{Forward-Name}" path="{Forward-Path}" <B>redirect="true"</B>/><br />
</action><br />
<B>Pass Parameter After Redirect:</B><br />
In action file in place of using mapping.findForward("{Action-Path}") use <B>ActionRedirect</B> (subclass of ActionForward).This class includes an addParameter() method.<br />
e.g.<br />
ActionRedirect ar = new ActionRedirect(mapping.findForward("{Action-Path}"));<br />
ar.addParameter("{Parameter-Name}", {Parameter-Value});<br />
return ar;<br />
<B>Or</B><br />
return (new ActionRedirect(mapping.findForward("{Action-Path}"))).addParameter("{Parameter-Name}", "{Parameter-Value}");<br />
Here all words with in <B>{}</B> are <B>place holders</B>.<BR>Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com1tag:blogger.com,1999:blog-6155844981858406346.post-34778082165644379282011-03-17T02:34:00.000-07:002011-03-17T02:34:23.055-07:00I18N Liferay 6.xHi today I will share how to use in built Liferay I18N functionality to your custom portlet in Liferay 6.x<BR><br />
It is very simple to add it , for that we need to modify just 2 files.<BR><br />
1.portlet.xml --- In this file add resource bundle entry.<BR><br />
e.g <resource-bundle>content.Language</resource-bundle><BR><br />
2.build.xml --- In this file we need to call below target.<BR><br />
<target name="build-lang"><BR><br />
<antcall target="build-lang-cmd"><BR><br />
<param name="lang.dir" value="docroot/WEB-INF/src/content" /><BR><br />
<param name="lang.file" value="Language" /><BR><br />
</antcall><BR><br />
</target><BR><br />
Now we need to just add one file with name <B>Language.properties</B> under <B>docroot/WEB-INF/src/content</B><br />
from build.xml using ant call buil-lang. That it !!!Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com1tag:blogger.com,1999:blog-6155844981858406346.post-55879772125281003562011-03-16T03:21:00.000-07:002011-03-16T03:21:13.266-07:00CK editor in Liferay 6.0Hi Friends, <br />
In this article I just want to share how to use CK editor in liferay 6.0 .<BR><br />
Follow these 4 simple steps.<BR><br />
Step 1.Add below line on your page<br />
<liferay-ui:input-editor width="80%" />.<BR><br />
<br />
Step 2.Create hidden variable to set the value of CK editor like below<br />
<aui:input name="content" type="hidden" /><BR><br />
<br />
Step 3.Add javascript init method like this<BR><br />
<aui:script><BR><br />
function <portlet:namespace />initEditor() {<BR><br />
return "<%= UnicodeFormatter.toString(content) %>";<BR><br />
}<BR><br />
</aui:script><br />
<BR><br />
Step 4:On submiting form we can assign CK editor value like this<BR><br />
function <portlet:namespace />saveEntry() {<BR><br />
var message = window.<portlet:namespace />editor.getHTML();<BR><br />
document.<portlet:namespace />fm.<portlet:namespace />content.value = message;<BR><br />
submitForm(document.<portlet:namespace />fm);<BR><br />
}<BR><br />
<br />
Currently we are having problem in liferay 6.0 is that when we refresh CK editor page , it gives JS error.<BR><br />
For that fix is like this get html/js/editor/ckeditor.jsp in function initCkArea() comment line 52 and 53 which starts with CKEDITOR.config.toolbar and CKEDITOR.config.customConfig respectively and add below line <BR><br />
ckEditor.setData(parent.<%= HtmlUtil.escape(initMethod) %>());<BR>In the same file comment line number 131 i.e<BR><br />
initCkArea(); and add <BR>if (parent.AUI) {<BR><br />
parent.AUI().on('domready', initCkArea);<BR><br />
}<BR>In side CKEDITOR.replace method at line number 123 in same file comment line starts with filebrowserBrowseUrl , filebrowserUploadUrl and <BR> add below code <BR><br />
customConfig: '<%= PortalUtil.getPathContext() %>/html/js/editor/ckeditor/ckconfig.jsp?p_l_id=<%= plid %>&p_p_id=<%= HttpUtil.encodeURL(portletId) %>&p_main_path=<%= HttpUtil.encodeURL(mainPath) %>&doAsUserId=<%= HttpUtil.encodeURL(doAsUserId) %>&cssPath=<%= HttpUtil.encodeURL(cssPath) %>&cssClasses=<%= HttpUtil.encodeURL(cssClasses) %>',<br />
filebrowserBrowseUrl: '<%= PortalUtil.getPathContext() %>/html/js/editor/ckeditor/editor/filemanager/browser/liferay/browser.html?Connector=<%= connectorURL %>',<br />
filebrowserUploadUrl: null,<br />
toolbar: '<%= TextFormatter.format(HtmlUtil.escape(toolbarSet), TextFormatter.M) %>'<BR><br />
<br />
Finally add required import i.e<br />
<%@ page import="com.liferay.portal.util.PortalUtil" %> and one extra variable <BR><br />
<br />
String portletId = ParamUtil.getString(request, "p_p_id");Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com8tag:blogger.com,1999:blog-6155844981858406346.post-7331523943753180902011-02-23T03:51:00.000-08:002011-02-23T03:58:50.014-08:00Simple java program to read json from text fileHi All,<br />
was busy some what from last couple of months. Finally started on liferay 6.0 from last couple of week.Today want to share simple program which can be used to read a text file and read json from it using apache commons library. Using apache commons library we can reduce our code to large extent. Here is the program.<br />
<br />
import java.io.IOException;<br />
import java.io.InputStream;<br />
<br />
import net.sf.json.JSONArray;<br />
import net.sf.json.JSONObject;<br />
import net.sf.json.JSONSerializer;<br />
<br />
import org.apache.commons.io.IOUtils;<br />
<br />
<br />
public class ClassloaderTest {<br />
<br />
public static void main(String [] args) {<br />
ClassLoader cl = ClassloaderTest.class.getClassLoader();<br />
InputStream is = cl.getResourceAsStream("json.txt");<br />
try {<br />
<br />
String s = IOUtils.toString( is );<br />
JSONObject json = (JSONObject) JSONSerializer.toJSON(s);<br />
<br />
JSONObject searchresults = json.getJSONObject("searchresults");<br />
System.out.println("ssssssss" + searchresults.optString("count", ""));<br />
JSONArray jarray = searchresults.getJSONArray("URI");<br />
for(int i=0 ; i < jarray.size(); i++) {<br />
System.out.println("jarray [" + i + "] --------" + jarray.getString(i));<br />
}<br />
} catch(IOException e) {<br />
e.printStackTrace();<br />
}<br />
}<br />
<br />
<br />
<br />
}<br />
<br />
and content of json.txt is below<br />
{<br />
"searchresults": {<br />
"URI": ["qa1", "qa2", "qa3", "qa4", "qa5"],<br />
"count": "5"<br />
} <br />
}<br />
<br />
jason.txt you can keep in the same package where your class is.<br />
Hope this post helps others.<br />
KamalAnonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com4tag:blogger.com,1999:blog-6155844981858406346.post-90573768085326131932010-11-11T01:35:00.000-08:002010-11-11T01:35:04.527-08:00creating layout in ext environment in liferayHi today I want to share how to create layout in ext environment in liferay. Though it should not be used as ext environment is hard to manage but some times we don't want to maintain seperate development environment (plugin) in that case it can be used.<br />
<b>Here are the steps:</b><br />
Step 1:<br />
In ext-web\docroot\WEB-INF create a file name liferay-layout-templates-ext.xml<br />
<br />
Step 2:<br />
Open file liferay-layout-templates-ext.xml and put code <br />
<br />
<?xml version="1.0"?><br />
<!DOCTYPE layout-templates PUBLIC "-//Liferay//DTD Layout Templates 5.2.0//EN" "http://www.liferay.com/dtd/liferay-layout-templates_5_2_0.dtd"><br />
<br />
<layout-templates><br />
<custom><br />
<layout-template id="4_2_columns" name="custom(4-2)"><br />
<template-path><br />
/layouttpl/customlayout/4_2_columns.tpl<br />
</template-path><br />
<wap-template-path><br />
/layouttpl/customlayout/4_2_columns.wap.tpl<br />
</wap-template-path><br />
<thumbnail-path><br />
/layouttpl/customlayout/4_2_columns.png<br />
</thumbnail-path><br />
</layout-template><br />
</custom><br />
</layout-templates><br />
<br />
<i>This is file where your mapping goes regarding .tpl files used to create your layout.</i><br />
<br />
Step 3:Make a <b>layouttpl</b> folder at same level as <b>html</b> folder in <b>ext-web</b>. Inside this folder make customlayout folder.<br />
<br />
Step 4:Now in customlayout folder you need to keep your .png and .tpl files related to layout as per the mapping .Now create a files with name 4_2_columns.tpl and 4_2_columns.wap.tpl in customlayout folder and put below code. <br />
<br />
<br />
<div class="columns-2" id="content-wrapper"><br />
<table class="lfr-grid" id="layout-grid"><br />
<tr><br />
<td class="lfr-column thirty" id="column-1" width="25%" valign="top"><br />
$processor.processColumn("column-1")<br />
</td><br />
<td class="lfr-column thirty" id="column-2" width="25%" valign="top"><br />
$processor.processColumn("column-2")<br />
</td><br />
<td class="lfr-column thirty" id="column-3" width="25%" valign="top"><br />
$processor.processColumn("column-3")<br />
</td><br />
<td class="lfr-column thirty" id="column-4" width="25%" valign="top"><br />
$processor.processColumn("column-4")<br />
</td><br />
</tr><br />
<tr><br />
<td colspan="4"><div style="border-bottom: 3px dotted #405DD5;"></div></td><br />
</tr><br />
<tr><br />
<td colspan="4"><br />
<table class="lfr-grid" id="layout-grid"><br />
<tr><br />
<td class="lfr-column thirty" id="column-5" valign="top"><br />
$processor.processColumn("column-5")<br />
</td><br />
<td class="lfr-column seventy" id="column-6" valign="top"><br />
$processor.processColumn("column-6")<br />
</td><br />
</tr> <br />
</table> <br />
</td> <br />
</tr><br />
</table><br />
</div><br />
<br />
<br />
and in 4_2_columns.wap.tpl put below code<br />
<br />
<table><br />
<tr><br />
<td><br />
$processor.processColumn("column-1")<br />
</td><br />
<td><br />
$processor.processColumn("column-2")<br />
</td><br />
<td><br />
$processor.processColumn("column-3")<br />
</td><br />
<td><br />
$processor.processColumn("column-4")<br />
</td><br />
<td><br />
$processor.processColumn("column-5")<br />
</td><br />
<td><br />
$processor.processColumn("column-6")<br />
</td><br />
</tr><br />
</table><br />
<br />
Now do ant deploy from ext-web and start the server after successful deployment. In dock in Layout Template you will get new layout. add it and see.<br />
That's all.Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com1tag:blogger.com,1999:blog-6155844981858406346.post-41257054675084724342010-10-07T05:51:00.000-07:002010-10-07T05:51:41.305-07:00getting url parameter value in liferayHi All,<br />
If we set url parameter value in normal jsp page like $some_url$?abc=ok. Then normally we can get value using <b>request.getParameter("abc")</b>; very simple.But in liferay I tried it was not working, then how to do in liferay?? not as simple as <br />
<b>request.getParameter("abc")</b>; but little more code. Taking above example<br />
<b> HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));<br />
String abc = httpReq.getParameter("abc");<br />
</b><br />
So we will get desired result.<br />
Hope this helps others.Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com9tag:blogger.com,1999:blog-6155844981858406346.post-1445412300958378032010-09-23T03:14:00.000-07:002010-09-23T03:14:33.381-07:00popup on popup in liferayTo implement popup on popup in liferay is quite simple. We need to have 2 pages one parent page on which 1st popup is already opened and 2nd page which will be opened in 2nd popup.<br />
<br />
For 1st page call:<br />
function <portlet:namespace/>parentPage(url) {<br />
var popup = Liferay.Popup(<br />
{ <br />
<b>stack: true</b>,<br />
draggable:false,<br />
title: 'Parent Page',<br />
position:[110,50],<br />
modal:true,<br />
width:450,<br />
height:365,<br />
url:url<br />
}<br />
);<br />
}<br />
here <b>stack:true</b> property is important which is responsible for pop on popup.<b>url</b> is which page we want to load . It can be portlet url. Other parameters are self explanatory. <br />
<br />
In child page you can simply write another popup.<br />
<br />
function <portlet:namespace/>childPage(url) {<br />
var popup = Liferay.Popup(<br />
{ <br />
<br />
title: 'Child Page',<br />
position:[110,50],<br />
modal:true,<br />
width:450,<br />
height:365,<br />
url:url<br />
}<br />
);<br />
}<br />
<br />
Thanks and Hope this help few people.Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com2tag:blogger.com,1999:blog-6155844981858406346.post-16356440596642967172010-08-04T05:59:00.000-07:002010-08-04T05:59:49.466-07:00orderable search container in liferay by exampleLiferay provide us with many good taglib out of them search container is one of them.It is widely used taglib. For simple understanding of search container please check Wiki here is the link <a href="http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/SearchContainer">Wiki Search Container</a>. One thing that article is missing how to implement ordering using. For that we will follow few step and will do a simple example.<br />
Step 1: Read the wiki article <a href="http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/SearchContainer">Search Container</a>.<br />
Step 2:Now write the below code in your jsp.<br />
<br />
<% <br />
PortalPreferences portalPrefs = PortletPreferencesFactoryUtil.getPortalPreferences(request); <br />
String orderByCol = ParamUtil.getString(request, "orderByCol"); <br />
<br />
String orderByType = ParamUtil.getString(request, "orderByType"); <br />
<br />
if (Validator.isNotNull(orderByCol) && Validator.isNotNull(orderByType)) { <br />
portalPrefs.setValue("KK_3", "kk-order-by-col", orderByCol); <br />
portalPrefs.setValue("KK_3", "kk-order-by-type", orderByType); <br />
<br />
} else { <br />
<br />
orderByCol = portalPrefs.getValue("KK_3", "kk-order-by-col", "name");<br />
orderByType = portalPrefs.getValue("KK_3", "kk-order-by-type", "asc"); <br />
<br />
}<br />
<br />
OrderByComparator orderByComparator = AddressBookUtil.getAddressBookOrderByComparator(orderByCol, orderByType);<br />
%><br />
<br />
<br />
Now I will explain what is happening we are getting the column on which we have to do ordering in <b>orderByCol</b> and order <b>asc or desc</b> in <b>orderByType</b>. <br />
In line <b>portalPrefs.setValue("KK_3", "kk-order-by-col", orderByCol);</b> <br />
here "KK_3" is namespace , "kk-order-by-col" is key and orderByCol is value. <br />
In last line <b>OrderByComparator orderByComparator = AddressBookUtil.getAddressBookOrderByComparator(orderByCol, orderByType);</b><br />
For this you need to write a comparator , I have written it in com.ext.portlet.addressBook.util.AddressBookUtil and write this code <br />
<br />
<br />
public class AddressBookUtil {<br />
<br />
/**<br />
* <br />
* @param orderByCol<br />
* @param orderByType<br />
* @return<br />
*/<br />
<br />
public static OrderByComparator getAddressBookOrderByComparator(<br />
String orderByCol, String orderByType) {<br />
<br />
boolean orderByAsc = false;<br />
<br />
if (orderByType.equals("asc")) {<br />
orderByAsc = true;<br />
}<br />
<br />
OrderByComparator orderByComparator = null;<br />
<br />
if (orderByCol.equals("name")) {<br />
orderByComparator = new AddressBookNameComparator(orderByAsc);<br />
} else if (orderByCol.equals("status")) {<br />
orderByComparator = new AddressBookStatusComparator(orderByAsc);<br />
} <br />
<br />
return orderByComparator;<br />
}<br />
<br />
}<br />
<br />
Now in same package write <b>AddressBookNameComparator</b> and <b>AddressBookStatusComparator</b> if you want you can write any where else and do the required imports. Below is the code for AddressBookNameComparator<br />
<br />
public class AddressBookNameComparator extends OrderByComparator {<br />
<br />
public static String ORDER_BY_ASC = "name ASC";<br />
<br />
public static String ORDER_BY_DESC = "name DESC";<br />
<br />
public AddressBookNameComparator() {<br />
this(false);<br />
}<br />
<br />
public AddressBookNameComparator(boolean asc) {<br />
_asc = asc;<br />
}<br />
<br />
public int compare(Object obj1, Object obj2) {<br />
AddressBook project1 = (AddressBook) obj1;<br />
AddressBook project2 = (AddressBook) obj2;<br />
<br />
int value = project1.getName().toLowerCase().compareTo(<br />
project2.getName().toLowerCase());<br />
<br />
if (_asc) {<br />
return value;<br />
} else {<br />
return -value;<br />
}<br />
}<br />
<br />
public String getOrderBy() {<br />
if (_asc) {<br />
return ORDER_BY_ASC;<br />
} else {<br />
return ORDER_BY_DESC;<br />
}<br />
}<br />
<br />
private boolean _asc;<br />
<br />
}<br />
<br />
Do the required imports .Same way you can do for other columns.<br />
Step 3: Use the SearchContainer taglib. <br />
<br />
<liferay-ui:search-container<br />
emptyResultsMessage="No Result Found"<br />
orderByCol="<%= orderByCol %>"<br />
orderByType="<%= orderByType %>"<br />
><br />
<liferay-ui:search-container-results results="<%= AddressBookLocalServiceUtil.getAddressBookList(searchContainer.getStart(), searchContainer.getEnd(),orderByComparator)%>"><br />
total="<%= AddressBookLocalServiceUtil.getAddressBookCount() %>"<br />
/><br />
<liferay-ui:search-container-row classname="com.ext.portlet.addressBook.model.AddressBook" escapedmodel="<%= true %>"><br />
keyProperty="bookId"<br />
modelVar="addressBook"<br />
><br />
<br />
<br />
<liferay-ui:search-container-column-text name="name" orderable="<%= true %>" orderableproperty="name"><br />
><br />
<br />
<%= addressBook.getName() %><br />
<br />
</liferay-ui:search-container-column-text><br />
<br />
<liferay-ui:search-container-column-text name="status" orderable="<%= true %>" orderableproperty="status" property="status"><br />
/><br />
<br />
</liferay-ui:search-container-column-text><br />
<br />
<br />
<liferay-ui:search-iterator /><br />
</liferay-ui:search-container-row></liferay-ui:search-container-results> <br />That is all about orderable search container.If you have read the wiki article then you will easily understand this.<br /><br />
HTHAnonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com13tag:blogger.com,1999:blog-6155844981858406346.post-25090008081027627872010-03-08T02:23:00.000-08:002010-03-08T21:34:25.727-08:00Hiding portlet in liferayRequirement: Hide the portlet for which user is not having permission to view.<br /><br />Simple Approach:<br /> It is very difficult to hide or show portlet at user level. To get rid of these type of problem liferay provide us Roles. So we can create roles and on those roles we can easily assign permission on each portlet.<br />Creating role in liferay is very simple.<br />Just login as Admin and using dock navigate to control panel , click on Role from left panel and then click Add...for more details refer portal administration guide from liferay.<br />Once this is done click on define permission and select portlet permission.<br />e.g. Suppose you want to remove view permission from portlet A then uncheck view.<br /><br />When you will login as user with that role then you will get message something like this.<br /> "you don't have required permission to access this portlet" <br />Finally to make this portlet invisible for that role user who is not having required permission to view the portlet.In portal-ext.properties add this line<br /> <span style="font-weight:bold;">layout.show.portlet.access.denied=false </span>Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com29tag:blogger.com,1999:blog-6155844981858406346.post-60960844771732127972010-03-08T00:57:00.000-08:002011-07-05T07:46:14.580-07:00IPC-using public render parameterIn last post we have learned how to do coordination between 2 portlet commonly known as Inter Portlet Communication. In post I am going to describe IPC using public render parameter.<br />
<br />
This is the simplest method for IPC given by JSR-286.<br />
<br />
Description:<br />
<br />
In JSR 168 (Portlet 1.0), the render parameters set in the processAction() method are available only in the render phase of the same portlet.<br />
<br />
By using the public render parameters feature, the render parameters set in the processAction() method of one portlet are available in render parameters of the other portlets. Using public render parameters instead of events avoids the additional process event call. The public render parameters can also be set on the render URL.<br />
<br />
To enable coordination of render parameters with other portlets within the same portlet application or across portlet applications, the portlet can declare public render parameters in its deployment descriptor using the public-render-parameter element in the portlet application section. Public render parameters can be viewed and changed by other portlets or components.<br />
<br />
In the portlet section, each portlet can specify the public render parameters to be shared through the supported-public-render-parameter element. The supported-public-render-parameter element must reference the identifier of a public render parameter defined in the portlet application section in a public-render-parameter element.<br />
<br />
Example: If we carry same old portlets which we have build in last example i.e for Event model IPC namely test1-portlet and test2-portlet.<br />
<br />
Step 1:<br />
<br />
Declare the render parameters to be shared in the portlet.xml file by setting the public render parameters at the portlet application level.<br />
<br />
e.g:<br />
<br />
<portlet-app ...><br />
<br />
<portlet> ... </portlet><br />
<br />
<public-render-parameter><br />
<br />
<identifier>user-id</identifier> <qname xmlns:x="http://abc.com/userId">x:userId</qname><br />
<br />
</public-render-parameter><br />
<br />
</portlet-app><br />
<br />
Note:<br />
<br />
1.A developer can declare a list of public paramters for a portlet application in portlet.xml.<br />
<br />
2.Parameter names are namespaced to avoid naming conflict.<br />
<br />
Step 2:<br />
<br />
Portlet must declare which public param they want to use.<br />
<br />
e.g.<br />
<br />
After adding declaration portlet.xml will look something like this.<br />
<br />
<portlet-app ......><br />
<br />
<portlet><br />
<br />
<portlet-name>test1</portlet-name> <display-name>test1</display-name><br />
<br />
........ ........<br />
<br />
<supported-public-render-parameter><br />
<br />
user-id<br />
<br />
</supported-public-render-parameter><br />
<br />
</portlet><br />
<br />
<public-render-parameter><br />
<br />
<identifier>user-id</identifier> <qname xmlns:x="http://abc.com/userId">x:userId</qname><br />
<br />
</public-render-parameter><br />
<br />
</portlet-app><br />
<br />
Note: Public params are available in all lifecycle method like processAction , processEvent, render and serveResource.<br />
<br />
Step 3: We can set render parameter in the processAction() method by using the defined public render parameter identifier as the key.<br />
<br />
e.g.<br />
<br />
public void processAction(ActionRequest request, ActionResponse response)<br />
<br />
throws IOException, PortletException { ........ response.setRenderParameter("user-id", userId); ........<br />
<br />
}<br />
<br />
Step 4: A portlet can read public render parameter using follwing method<br />
<br />
request.getPublicParameterMap()<br />
<br />
Note: Public render parameters are merged with regular parameters so can also be read using<br />
<br />
request.getParameter(name) or request.getParameterMap()<br />
<br />
Step 5: A portlet can remove a public render parameter by invoking following methods.<br />
<br />
response.removePublicRenderParameter(name)<br />
<br />
or<br />
<br />
portletURL.removePublicRenderParameter(name)Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com1tag:blogger.com,1999:blog-6155844981858406346.post-90402126405126969112010-02-25T23:13:00.000-08:002010-02-25T23:25:38.170-08:00Coordination between portlets in JSR-286To provide coordination JSR-286 provides 2 mechanism<br />1.Event: Portlet event that portlet can recieve and send.<br />2.Public Render Parameter : Render states that can be shared between portlets.<br /><br />Event :<br /><br />In JSR-168 :<br /> The only way to achive eventing was through portlet session.<br /> Limitation : Portlet has to be in the same web application.<br /><br />In JSR-286 :<br /> JSR 286 (Portlet 2.0) defines a lifecycle for events, so that eventing is possible between portlets that are in different web applications.<br /><br /> Definition Of Event in JSR -286 :<br /> An event is lifecycle operation occuring before rendering phase. It is a loosely coupled , acting as a agent for communication between portlets.<br /> Events allow portlets to respond on actions or state changes not directly related to an interaction of the user with the portlet.<br /><br />A portlet can declare events in its deployment descriptor by using the event-definition element in the portlet application section.<br />In the portlet section, each portlet specifies the events it would like to publish through the supported-publishing-event element and <br />the events it would like to process through the supported-processing-event element.<br /><br />The supported-publishing-event and supported-processing-event elements must reference the event name defined in the portlet application section in an event-definition element.<br /><br />The portlet creates events using the setEvent() method during action processing. The events are processed by the portlet container after the action processing has finished.<br />Portlets can also create events during the event phase by calling the setEvent() method on EventResponse.<br /><br />To receive events, the portlet must implement the javax.Portlet.EventPortlet interface. The portlet container calls the processEvent() method<br />for each event targeted to the portlet with an EventRequest and EventResponse object. The portlet can access the event that triggered the current<br />process event call by using the EventRequest.getEvent() method. This method returns an object of type Event encapsulating the current event name and value.<br /><br />Event names are represented as QNames to identify them uniquely. The event name can be retrieved by using the getQName() method that returns the complete<br />QName of the event, or by using the getName() method that returns only the local part of the event name. The value of the event must be based on the type<br />defined in the deployment descriptor.<br /><br />So this all about theory time for some practical.<br /><br />For this simple example I am going to use plugin sdk liferay version 5.2.3<br /><br />Step 1:<br /> create 2 portlets in plugins environment.Creating portlet in plugin is very simple just execute below command<br /> Go to {your_work_space}\plugins\portlets> and execute command <br /> create hello "Hello World" this will create portlet with portlet display name = "Hello World" and portlet name = hello<br /><br /> I am creating here 2 portlets with name test1 and test2<br /><br />Step 2: Go to your 1st portlet below location in our present case it is test1 i.e<br /> <br /> {your_work_space}\plugins\portlets\test1-portlet\docroot\WEB-INF<br /><br /> open porlet.xml file. In that add first Event definition as below<br /><br /> e.g.<br /> <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <br /> xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"><br /> <portlet><br /> <!-- here other portlet related content will come like portlet-name , diaply-name etc--><br /> <..><br /> </portlet><br /> <!-- Event Definition-starts --><br /> <event-definition> <br /> <qname xmlns:x="http:kamal.com/events">x:Name</qname><br /> <value-type>java.lang.String</value-type><br /> <!-- Event Definition-ends --><br /> </event-definition><br /> </portlet-app><br /><br />Step 3: Now we need to publish event<br /> We will make test1-portlet as Event Publishing portlet as well. So open again portlet.xml file same as step 2<br /> Add supported-publishing-event tag like below.<br /><br /> <supported-publishing-event><br /> <qname xmlns:x="http:sun.com/events">x:Name</qname><br /> </supported-publishing-event><br /><br /> Now your portlet.xml file structure will be like this.<br /><br /> <?xml version="1.0"?><br /><br /> <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br /> xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"><br /> <portlet><br /> <!-- here other portlet related content will come like portlet-name , diaply-name etc--><br /> <..><br /> <!-- supported-publishing-event- starts --><br /> <supported-publishing-event><br /> <qname xmlns:x="http:kamal.com/events">x:Name</qname><br /> </supported-publishing-event><br /> <!-- supported-publishing-event- ends --><br /> </portlet><br /> <event-definition> <br /> <qname xmlns:x="http:kamal.com/events">x:Name</qname><br /> <value-type>java.lang.String</value-type><br /> </event-definition><br /> </portlet-app><br /><br /><br /> Step 4: Now our Event publishing portlet is ready with required configuration , now we need to do same configuration for <br /> Event Processing portlet. Now open portlet.xml for test2-portlet and modify it as above with minor change in place of<br /> <supported-publishing-event> use <supported-processing-event> thats it. Now structure will look like this.<br /><br /> <?xml version="1.0"?><br /><br /> <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <br /> xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"><br /> <portlet><br /> <!-- here other portlet related content will come like portlet-name , diaply-name etc--><br /> <..><br /> <supported-processing-event><br /> <qname xmlns:x="http:kamal.com/events">x:Name</qname><br /> </supported-processing-event><br /> </portlet><br /> <event-definition> <br /> <qname xmlns:x="http:kamal.com/events">x:Name</qname><br /> <value-type>java.lang.String</value-type><br /> </event-definition><br /> </portlet-app><br /><br /> <br />Step 5: Now all configuration part is over , now we will modify java files<br /> Go to test1-portlet's JSPPortlet.java at location {your_work_space}\plugins\portlets\test1-portlet\docroot\WEB-INF\src\com\sample\jsp\portlet <br /> In processAction method add below code<br /> QName qname = new QName("http:kamal.com/events" , "Name");<br /> String value = "Hurray we have done it";<br /> actionResponse.setEvent(qname, value);<br /><br /> and add needful imports<br /> import javax.xml.namespace.QName;<br /><br />Step 6: Now Go to test2-portlet's JSPPortlet.java at location {your_work_space}\plugins\portlets\test2-portlet\docroot\WEB-INF\src\com\sample\jsp\portlet <br /> Add new method to process event<br /><br /> public void processEvent(EventRequest request, EventResponse response) { <br /> _log.info("I m in process event");<br /> Event event = request.getEvent();<br /> if(event.getName().equals("Name")) {<br /> String displayText = (String)event.getValue();<br /> response.setRenderParameter(<br /> "displayText", displayText);<br /> }<br /> }<br /><br /> and do needful imports<br /> import javax.portlet.Event;<br /> import javax.portlet.EventRequest;<br /> import javax.portlet.EventResponse;<br /><br />Step 7: Now we are done java part as well need to do minor coding in jsp to see our hard work live.<br /> Open view.jsp of test1-portlet to provide a link to invoke event<br /> e.g.<br /> <% <br /> PortletURL actionURL = renderResponse.createActionURL();<br /> %><br /> <a href="<%= actionURL.toString() %>">click here to invoke event</a><br /> do needful imports if required <br /> <%@ page import="javax.portlet.PortletURL" %><br /><br />Step 8: Open view.jsp of test2-portlet to show output <br /> just add following line <br /> <%= renderRequest.getParameter("displayText") %><br /> I have not done any thing extra , I tried to focus on concept and its implementation.<br /><br /> Start the server and if everything is working fine add both portlet test1 and test2 on a page and click the link <br /> provided on test1 portlet you will see the output on portlet test2.<br /> <br /> Pls do post your feedbacks.Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com9tag:blogger.com,1999:blog-6155844981858406346.post-42726145959395234212009-10-29T04:19:00.000-07:002009-10-29T04:24:28.424-07:00Implementing Print functionality for a web contentThis is almost straight forward implementation just follow few steps.<br /><br />Step 1. Get the page url u want to print I am thinking I am on the same page <br /><br /> of which I wanted to print the content . Then I can get the url like this <br /><br /> PortletURL url = PortletURLUtil.getCurrent(renderRequest, mimeResponse or renderResponse);<br /><br /> else you can create the url of the page like this <br /><br /> PortletURL printPageURL = renderResponse.createRenderURL();<br /><br /> and set the required parameter related to youur page plus these extra parameters<br /><br /> printPageURL.setWindowState(LiferayWindowState.POP_UP);<br /> printPageURL.setParameter("viewMode", Constants.PRINT);<br /> <br /><br />sample url will look like this :<br /> PortletURL printPageURL = renderResponse.createRenderURL();<br /> printPageURL.setWindowState(LiferayWindowState.POP_UP);<br /> printPageURL.setParameter("struts_action", "ur_stuts_action_path");<br /> printPageURL.setParameter("ur_param_1", "ur_param_value_1");<br /> printPageURL.setParameter("viewMode", Constants.PRINT);<br /> printPageURL.setParameter("print", String.valueOf(true));<br /><br />Step 2:<br /> create a boolean variable print with default value false.<br /> eg: <br /> boolean print = ParamUtil.getBoolean(request,"print");<br /><br />Step 3: Add this code on your page. <br /><br /> <c:choose><br /> <c:when test="<%= print %>"><br /> <script type="text/javascript"><br /> function printArticle() {<br /> print();<br /> } <br /> </script><br /> </c:when><br /> <c:otherwise><br /> <br /> <script type="text/javascript"><br /> function <portlet:namespace />printPage() {<br /> window.open('<%= printPageURL.toString()%>', '', "directories=0,height=480,left=80,location=1,menubar=1,resizable=1,scrollbars=yes,status=0,toolbar=0,top=180,width=640");<br /> }<br /> </script> <br /> </c:otherwise><br /> </c:choose><br /><br />Step 4: Add this code <br /><br /> <c:choose><br /> <c:when test="<%= print %>"><br /> <span style="float:right"><br /> <liferay-ui:icon image="Print" url="javascript:onclick=printArticle();" label="<%= false %>" /><br /> </span><br /> </c:when><br /> <c:otherwise><br /> <span style="float:right"><br /> <liferay-ui:icon image="Print" url='<%= "javascript:" + renderResponse.getNamespace() + "printPage();" %>' label="<%= false %>" /><br /> </span><br /> </c:otherwise><br /> </c:choose><br /><br />Thats it <br />Enjoy !!!Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com2tag:blogger.com,1999:blog-6155844981858406346.post-49979608403230129562009-10-29T03:23:00.000-07:002009-10-29T03:37:22.754-07:00For preview without saving the article in JournalHi today I want to share how to implement preview without saving web-content in liferay.<br />Step 1: <br /> Add following line <br /> <input type="button" value="<liferay-ui:message key="preview" />" onClick="<portlet:namespace />previewArticleNoStructure();" /><br /><br />Step 2:<br /> write the following function <br /><br /> function <portlet:namespace />previewArticleNoStructure() {<br /> document.<portlet:namespace />fm2.action = "<%= themeDisplay.getPathMain() %>/journal/view_article_content?<%= Constants.CMD %>=<%= Constants.PREVIEW %>&groupId=<%= String.valueOf(groupId) %>&articleId=<%= HttpUtil.encodeURL(articleId) %>&version=<%= version %>&languageId=" + document.<portlet:namespace />fm1.<portlet:namespace />languageId.value + "&type=" + document.<portlet:namespace />fm1.<portlet:namespace />type.value;<br /> document.<portlet:namespace />fm2.target = "_blank";<br /> document.<portlet:namespace />fm2.title.value = document.<portlet:namespace />fm1.<portlet:namespace />title.value;<br /> document.<portlet:namespace />fm2.xml.value = <portlet:namespace />getArticleContentNoStructure();<br /> document.<portlet:namespace />fm2.submit();<br /> <br /> }<br /><br />Step 3: <br /><br /> Write this function <br /><br /> function <portlet:namespace />getArticleContentNoStructure(){<br /><br /> var xsd = "<root available-locales=\"en_US\" default-locale=\"en_US\">";<br /> xsd += "<static-content language-id=\"en_US\">";<br /> xsd += "<![CDATA[";<br /> xsd += window.<portlet:namespace />editor.getHTML();<br /> xsd += "]]>";<br /> xsd += "</static-content>";<br /> xsd += "</root>";<br /> return xsd;<br /> }<br /><br />that's it .<br />Enjoy!!!Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com0tag:blogger.com,1999:blog-6155844981858406346.post-34931913265077676402009-09-10T21:46:00.000-07:002009-09-10T21:51:49.205-07:00Reading tempelates in liferayHi Friends,<br /> I have seen many new comers to liferay seems to be struggling regarding the email tempelates.<br />So I thought why not put the whole procedure in a document which can help. For this reason I am <br />writing this post may be it is quite simple for many but will be quite helpful for the new comers.<br /><br /><br />Brief Overview:<br /> If we see in existing liferay source code then we can find the email tempelates regarding <br /><br />create account and forgot password in com/liferay/portlet/admin/dependencies/ and they are read from there.<br /><br />In 1 case I can tell you from UserLocalServiceImpl and corresponding entry for each tempelate is there in<br /><br />portal.properties <br /><br /><br />Enough theory time to do your self:<br /><br />1.Just create a folder in ext-impl may be u can choose this path <br /> ext-impl\src\com\mytempelate<br /><br />2.Write a simple tempelate <br /> eg:<br /> Dear [$TO_NAME$],<br /><br /><br /><br /> Hi this is my first tempelate.<br /><br /><br /><br /> <br /> Sincerely,<br /><br /> [$FROM_NAME$]<br /><br /> save this as my_first_tmpl.tmpl<br /><br /><br />3.make an entry in portal-ext.properties <br /><br /> for our example like this :<br /> <br /> ext.myfirst.tempelate=ext-impl\src\com\mytempelate\my_first_tmpl.tmpl<br />This is just a normal key value pair.<br /><br />4.Now time to read your tempelate <br /><br /> String firstTemeplate = PrefsPropsUtil.getContent(user.getCompanyId(),"ext.myfirst.tempelate");<br /> <br /> or<br /><br /> String firstTemeplate = ContentUtil.get("ext-impl\src\com\mytempelate\my_first_tmpl.tmpl");<br /><br /><br /><br />5. We can easily replace the content :<br /> String firstTemeplate= StringUtil.replace(firstTemeplate, new String[] {"[$TO_NAME$]","[$FROM_NAME$]"<br /><br /> }, new String[] {<br /><br /> "any_name","any_name"<br /> });<br /><br />Thats it !!!Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com3tag:blogger.com,1999:blog-6155844981858406346.post-53662505910058137462009-08-13T02:45:00.001-07:002009-08-13T02:45:45.606-07:00Customizing url and changing default landing after loginIntroduction:<br /> Currently when ever we are login in we are getting path like <br /><br /> http://localhost:8080/web/guest/home<br /><br /> First we will try to simplify this url <br /> <br /> eg:<br /> Suppose I made a community with name Fquad then I want to access <br /> it as http://fquad.com rather than http://fquad.com:8080/web/guest/home<br /><br />How to achieve it??<br /><br /> we need to follow few simple steps for it <br /><br /> Step 1: Go to c:\WINDoWS\System32\drivers\etc or search for host file <br /> <br /> in host file add a line like this<br /> <br /> 127.0.0.1 www.fquad.com <br /><br /> Step 2: Stop the sever and start it and try to access the application with <br /> <br /> url http://fquad:8080/web/guest/home , if working fine go to step 3<br /> <br /> Step 3: Now create a community with name Fquad.<br /><br /> Step 4: Create 2 pages in Fquad community 1 public page and other private page.<br /><br /> Step 5: Go to manage pages of Fquad community click the setting tab and then click<br /> <br /> the Virtual Host tab then you can see Public Virtual Host text field fill it with <br /> <br /> www.fquad.com<br /> <br /> Step 6: Now try to access application using url http://fquad:8080/ <br /><br /> Step 7: To remove :8080 is simple just change connector port in tomcat/conf/server.xml<br /> <br /> search for line Connector port="8080" protocol="HTTP/1.1 and change 8080 to 80 thats it.<br /><br /> Sometimes it is required to land directly to private page of a community then in portal-ext.properties <br /> <br /> add 1 line , portal-ext.properties exist under tomcat\webapps\ROOT\WEB-INF\classes if not there create it<br /> <br /> default.landing.page.path=/group/fquadAnonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com12tag:blogger.com,1999:blog-6155844981858406346.post-75960282368603958842009-08-12T01:52:00.000-07:002009-08-12T01:55:46.814-07:00Give a try to ContactListener in ext environmentstep 1. create a class that extends ModelListener .<br /> <br /> eg. If want to extend ContactListener and want to do some action onAfterCreate then <br /> <br /> public class CustomContactListener extends ContactListener {<br /> public void onAfterCreate(BaseModel model) throws ModelListenerException {<br /> try {<br /> super.onAfterCreate(model)<br /> <br /> //your code<br /> System.out.println("Conatct info after update: " + contact.getContactId() + ":" + contact.getFirstName());<br /> }<br /> catch (Exception e) {<br /> throw new ModelListenerException(e);<br /> }<br /> }<br /> }<br /><br /> step 2. Make an entry in portal-ext.properties <br /><br /> value.object.listener.com.liferay.portal.model.Contact=\<br /> com.liferay.portal.model.ContactListener,\<br /> com.liferay.portal.model.CustomContactListener<br /><br />do ant deploy and update contact table entry and check in console whether updated data is coming or not.Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com0tag:blogger.com,1999:blog-6155844981858406346.post-70088858017499733172009-08-11T03:26:00.000-07:002009-08-11T04:06:18.563-07:00Using Json in LiferayIntroduction:<br /> We have 2 Service tiers..<br /><br />The Local tier - this tier has no permission checks and is simply a clean cut implementation of the business logic of the service.<br /><br />i.e. you set local-service="true" when you created the entity.<br /><br />e.g.<br />UserLocalServiceUtil.updateActive(long userId, boolean active) (re, no permission check is made, use with caution).<br /><br />The Remote Tier - this tier is designed to include your permission checks and finally calls the underlying Local service to actually perform the service operation. This tier is also the one on which ALL web-service methods are generated. All the HTTP, JSON, and SOAP are backed by the methods found in this tier.<br /><br />i.e. you set remote-service="true" when you created the entity AND you implemented methods in [Entity]ServiceImpl.java rather than leaving it blank.<br /><br />e.g.<br />UserServiceImpl.updateActive(long userId, boolean active) (i.e., makes a permission check internally):<br /> public User updateActive(long userId, boolean active)<br /> throws PortalException, SystemException {<br /> <br /> if ((getUserId() == userId) && !active) {<br /> throw new RequiredUserException();<br /> }<br /> <br /> UserPermissionUtil.check(<br /> getPermissionChecker(), userId, ActionKeys.DELETE);<br /><br /> return userLocalService.updateActive(userId, active);<br /> }<br /><br /><br />SO, all webservice methods which call their implementation of "updateActive" on the UserService are backed by this method. Also, this means that the caller must be authenticated in order to be tested for permissions... otherwise the call will fail. So, you need to be authenticated, AND you need to have permission.<br /><br />How does a JSON method get authenticated when it's called through and ajax call? All our JSON services are passed through an AutoLogin Filter which handles the authentication based on authorization cookies.<br /><br />Abstraction for using Json in Liferay:<br /><br />Step 1. generate service layer for your entity with remote-service="true"<br /> eg.<entity name="entityName" remote-service="true"><br /><br /><br />Step 2. In [entity]ServiceImpl write a method which you want to call using Json.<br /> eg. updateName(userName) throws Exception{//your code goes here}.<br /><br />Step 3. Do ant build-service -Dservice.file=your_service_xml_path from ext/ext-impl<br /><br />Step 4. Do ant deploy from ext.<br /><br />Step 5. Check file ext-web/docroot/html/js/liferay/ext_service_unpacked.js is updated with your method or not.<br /><br /> Note: In liferay version 5.2.x onwards this file is "ext_service.js".<br /><br />Step 6. Include js like this <script src="/html/js/liferay/ext_service.js"></script> in file in which you want to call json.<br /><br />Step 7. Call method like this <br /> eg:<br /> function updateName(userName) {<br /> var params = {<br /> userName: userName<br /> }; <br /> Liferay.Service.your_entity_namespace.entity_name.updateName(params);<br /> }Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com14tag:blogger.com,1999:blog-6155844981858406346.post-54717779326925818682009-08-10T22:51:00.000-07:002009-08-10T22:54:05.483-07:00Creating simple struts Portlet in liferay in 5 minIn struts portlet as compare to Jsp portlet we need to add 2 extra xml files <br /><br />1.struts-config.xml<br />2.tiles-defs.xml<br /><br />We have to modify follwing xml files.<br /><br />These xml files are located under "ext/ext-web/docroot/WEB-INF"<br /><br />2.1. portlet-ext.xml<br />--------------------<br /><br /><portlet><br /> <portlet-name>Sample</portlet-name><br /> <display-name>Sample Struts Portlet</display-name><br /> <portlet-class>com.liferay.portlet.StrutsPortlet</portlet-class><br /> <init-param><br /> <name>view-action</name><br /> <value>/ext/sample/view</value><br /> </init-param><br /> <expiration-cache>0</expiration-cache><br /> <supports> <br /> <mime-type>text/html</mime-type><br /> </supports><br /> <resource-bundle>com.liferay.portlet.StrutsResourceBundle</resource-bundle><br /> <security-role-ref><br /> <role-name>power-user</role-name><br /> </security-role-ref><br /> <security-role-ref><br /> <role-name>user</role-name><br /> </security-role-ref><br /></portlet><br /><br />2.2. liferay-portlet-ext.xml<br />----------------------------<br /><br /><portlet><br /> <portlet-name>Sample</portlet-name><br /> <struts-path>ext/sample</struts-path><br /> <use-default-template>false</use-default-template><br /></portlet><br /><br />2.3. liferay-display.xml<br />------------------------<br /><br />add<br /><br /><portlet id="Sample" /><br /><br />inside<br /><br /><category name="category.sample"><br /><br />2.4. struts-config.xml<br />----------------------<br /><br /><action path="/ext/sample/view" forward="portlet.ext.sample.view" /><br /><br />2.5. tiles-defs.xml<br />-------------------<br /><br /><definition name="portlet.ext.sample" extends="portlet" /><br /><definition name="portlet.ext.sample.view" extends="portlet.ext.sample"><br /> <put name="portlet_content" value="/portlet/ext/sample/view.jsp" /><br /></definition><br /><br /><br />(create the following two jsp files under "/ext/ext-web/docroot/html/portlet/ext/sample")<br /><br />2.6. init.jsp<br />-------------<br /><br /><%@ include file="/html/portlet/init.jsp" %><br /><br />2.7. view.jsp<br />-------------<br /><br /><%@ include file="/html/portlet/ext/sample/init.jsp" %><br />Simple Struts Portlet!<br /><br />2.8 Language-ext.properties<br />---------------------------<br /><br />Add a new entry in the above file,<br /><br />javax.portlet.title.Sample=Sample Struts PortletAnonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com3tag:blogger.com,1999:blog-6155844981858406346.post-39335923444618242812009-08-10T02:55:00.000-07:002009-08-10T03:06:02.867-07:00creating simple jsp portlet in LiferayFor creating simple Jsp portlet in Liferay we have to modify following files.<br /><br />Following xml files are located under "ext/ext-web/docroot/WEB-INF"<br /><br />1.1. portlet-ext.xml<br />--------------------<br />Add entry for your portlet <br /><br /><portlet><br /> <portlet-name>Sample</portlet-name><br /> <display-name>JSP Portlet Introduction</display-name><br /> <portlet-class>com.liferay.util.bridges.jsp.JSPPortlet</portlet-class><br /> <init-param><br /> <name>view-jsp</name><br /> <value>/html/portlet/ext/jsp_portlet/view.jsp</value><br /> </init-param><br /> <expiration-cache>0</expiration-cache><br /> <supports> <br /> <mime-type>text/html</mime-type><br /> </supports><br /> <resource-bundle>com.liferay.portlet.StrutsResourceBundle</resource-bundle><br /> <security-role-ref><br /> <role-name>power-user</role-name><br /> </security-role-ref><br /> <security-role-ref><br /> <role-name>user</role-name><br /> </security-role-ref><br /></portlet><br /><br />1.2. liferay-portlet-ext.xml<br />----------------------------<br />Make an entry for your portlet. <br /><br /><portlet><br /> <portlet-name>Sample</portlet-name><br /></portlet><br /><br />1.3. liferay-display.xml<br />------------------------<br />Make an entry for the category in which you want to display your portlet.<br /><br /><category name="category.sample"><br /> <portlet id="Sample" /><br /></category><br /><br />1.4. view.jsp<br />-------------<br /><br />create this file under "ext/ext-web/docroot/html/portlet/ext/jsp_portlet" <br />and put some contents<br /><br /><br />do "ant deploy" from "ext-web"<br /><br />1.5 Language-ext.properties<br />---------------------------<br /><br />(under /ext/ext-impl/src/content)<br /><br />Add two new entries in the above file, this helps us in I18N<br /><br />javax.portlet.title.Sample=Sample JSP Portlet<br /><br />category.sample=Example<br /><br />do "ant deploy" from "ext-impl"Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com1tag:blogger.com,1999:blog-6155844981858406346.post-51721549351022788962009-07-19T22:08:00.000-07:002009-07-19T22:10:39.421-07:00How to use Custom-sql in Liferay?Step-1:<br />------<br /><br />Create the file default-ext.xml under ext-impl/src/custom-sql (cerate custom-sql folder if it is not there)<br /><br /><?xml version="1.0"?><br /><br /><custom-sql><br /> <sql file="custom-sql/book.xml" /><br /></custom-sql><br /><br />(You can refer default.xml under portal source)<br /><br />Step-2:<br />------<br /><br />Create the file queries.xml, under the same folder, which will contain all the application specific queries as name / value pairs. <br /><br /><?xml version="1.0"?><br /><custom-sql><br /> <sql id="ur_id"><br /> <![CDATA[<br /> SELECT<br /> {Book.*}<br /> FROM<br /> Book<br /> WHERE<br /> (Book.title like ?)<br /> ]]><br /> </sql><br /></custom-sql><br /><br /><br />Step-3:<br />------<br /><br />Add your entry in portal-ext.properties<br /><br />custom.sql.configs=\<br /> custom-sql/default.xml, \<br /> custom-sql/default-ext.xml<br /><br />Step-4:<br />------<br /><br />Create the file "BookFinderImpl.java" under service/persistence and do the required imports<br /><br />public class BookFinderImpl extends BasePersistenceImpl implements<br /> BookFinder{<br /> <br />}<br /><br /><br />Step-5:<br />------<br /><br />Do ant build-service, so that the necessary interface is generated.<br /><br />Step-6:<br />------<br /><br />Now write the actual logic to access the custom SQL. You need to update the BookFinderImpl <br />we developed in the previous step. <br /><br /> // the name of the query<br /> public static String GET_QUERY = "id_given_in_queries.xml";<br /> <br /><br /> // the method which will be called from the ServiceImpl class<br /> public List<Book> getBooks(String pattern) throws SystemException {<br /><br /> Session session = null;<br /> try {<br /> // open a new hibernate session in normal case when you are opening session for same entity <br /> session = openSession();<br /> // In case of other entity you set the session first like below then open the session<br /> setSessionFactory((SessionFactory)PortalBeanLocatorUtil.getBeanLocator().locate(TagsAssetModelImpl.SESSION_FACTORY));<br /> session = openSession();<br /><br /> // pull out our query from book.xml, created earlier<br /> String sql = CustomSQLUtil.get(GET_QUERY);<br /><br /> // create a SQLQuery object<br /> SQLQuery q = session.createSQLQuery(sql);<br /> <br /> //In normal case : In our case book use this <br /> q.addEntity("Book", BookImpl.class);<br /><br /> //In other case : In our case TagsAsset use like this <br /> q.addEntity(TagsAssetModelImpl.TABLE_NAME, TagsAssetImpl.class);<br /><br /><br /> // Get query position instance<br /> QueryPos qPos = QueryPos.getInstance(q);<br /><br /> // fill in the "?" value of the custom query<br /> // this is same like forming a prepared statement<br /> qPos.add(pattern);<br /> <br /> // execute the query and return a list from the db<br /> return (List<Book>)q.list();<br /> <br /> /*<br /> // use this block if you want to return the no. of rows (count)<br /><br /> int rows = 0;<br /><br /> Iterator<Long> itr = q.list().iterator();<br /> <br /> if (itr.hasNext()) { Long count = itr.next();<br /> <br /> if (count != null) { rows = count.intValue(); } }<br /> <br /> return rows;<br /> */<br /> } catch (Exception e) {<br /> throw new SystemException(e);<br /> } finally {<br /> closeSession(session);<br /> }<br /> }<br /><br />Make the necessary additional imports.<br /><br />import java.util.List;<br /><br />import com.ext.portlet.library.model.Book;<br />import com.ext.portlet.library.model.impl.BookImpl;<br />import com.liferay.portal.SystemException;<br />import com.liferay.portal.kernel.dao.orm.QueryPos;<br />import com.liferay.portal.kernel.dao.orm.SQLQuery;<br />import com.liferay.portal.kernel.dao.orm.Session;<br />import com.liferay.util.dao.orm.CustomSQLUtil;<br /><br />Note:<br /><br />To get the result between a start and end index, you have to use, <br /><br />QueryUtil.list(q, getDialect(), begin, end);<br /><br />in the place of <br /><br />q.list();<br /><br />where, you will pass the parameters (begin and end) from your ServiceImpl class. <br /><br />Step-7:<br />------<br /><br />write the method in BookLocalServiceImpl.java<br /><br /> public List<Book> searchBook(String title) throws PortalException,<br /> SystemException, RemoteException {<br /><br /> // return bookPersistence.findByTitle(title);<br /> return BookFinderUtil.getBooks("%" + title + "%");<br /> }<br /><br /><br />Step-8:<br />------<br /><br />run "ant build-service" again passing the service.xml file as parameter. <br /><br />This will update the corresponding interface with the new method defined. <br /><br /><br />Step 9:<br />-------<br /><br />Now go ahead and call BookLocalServiceImpl method from your jsp or java normally how you call other methods<br /><br />ThanksAnonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com22tag:blogger.com,1999:blog-6155844981858406346.post-3334733420246944802009-07-10T06:35:00.001-07:002009-07-10T06:44:43.594-07:00Playing with portletURL in LiferayWith out tld :<br />============================================================================================<br />1.To get currentURL :<br /> PortletURL url = PortletURLUtil.getCurrent(renderRequest, mimeResponse or renderResponse)<br />============================================================================================<br /><br />============================================================================================<br />2.To make clone of a URL : <br /> PortletURL url = PortletURLUtil.clone(portletURL, mimeResponse or renderResponse)<br />============================================================================================<br /><br />=============================================================================================<br />3.creating PortletURL from actionResponse : <br /> PortletURL renderURL = ((ActionResponseImpl) actionResponse).createRenderURL();<br />===============================================================================================================<br /><br />============================================================================================================<br />4.creating PortletURL from renderResponse : <br /> a.For RenderURL:<br /> PortletURL renderURL = renderResponse.createRenderURL(); <br /> b.For actionURL:<br /> PortletURL actionURL = renderResponse.createActionURL();<br />============================================================================================================<br /><br />5.Using TLD's in Liferay :<br /> a. <br /><br /> <portlet:renderURL windowState="<%= WindowState.ur_state.toString() %>"><br /> <portlet:param name="param_name" value="param_value" /><br /> <portlet:param name="param_name" value="param_value" /><br /> </portlet:renderURL><br /><br /> b.<br /> <portlet:actionURL windowState="<%= WindowState.ur_state.toString() %>"><br /> <portlet:param name="param_name" value="param_value" /><br /> <portlet:param name="param_name" value="param_value" /><br /> </portlet:actionURL>Anonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com4tag:blogger.com,1999:blog-6155844981858406346.post-10477315043809282172009-05-28T21:04:00.000-07:002009-05-28T22:10:19.438-07:00Using Hooks in Liferay for customizing jsp<p>Using hooks customizing jsp page of a existing liferay portlet.</p><p> In this example I am taking portlet asset-publisher.<br /></p> Step 1: Go to plugins/hooks create a folder with any name. eg asset-publisher-hook<br /> Step 2: Go to asset-publisher-hook create folder docroot and build.xml file.<br /> Content of build.xml should be like this:<br /><br /> <p><br /> <project name="hook" basedir="." default="deploy"><br /> <import file="../build-common-hook.xml"><br /> </project> <br /> </p><br /><br /></import><br /> Step 3: Go to asset-publisher-hook/docroot create folder with name WEB-INF.<br /> Step 4: Now under WEB-INF create a file liferay-hook.xml and a folder with name jsps.<br /> Step 5: In liferay-hook.xml write following code.<br /> <br /> <?xml version="1.0" encoding="UTF-8"?><br /> <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 5.1.0//EN" "http://www.liferay.com/dtd/liferay-hook_5_2_2.dtd"><br /><br /> <hook><br /> <custom-jsp-dir>/WEB-INF/jsps</custom-jsp-dir><br /> </hook> <br /><br /><br /> <br /><br /> Step 6:Under jsps create folders html/portlet/portlet_name in our case portlet_name is asset-publisher.<br /> Step 7:Under portlet_name create the same structure for the page which we want to modify.<br /> Eg. In asset-publisher we will try to modify full_content.jsp then structure will be<br /> <br /> html/portlet/asset-publisher/display/full_content.jsp<br /><br /> Step 8:Customize the jsp file.<br /> Step 9:Go to plugins/hook<br /> Do ant deploy<br />Step 10:Check the changes on serverAnonymoushttp://www.blogger.com/profile/08884826637155492751noreply@blogger.com17