Thursday, 30 October 2014

How to remove "Terms of use" page by using Hook in Liferay

The first time users log into Liferay Portal, they’re presented with a “terms of use” page. Users must agree to the terms of use in order to continue. This feature is controlled by a property
in Liferay’s default portal.properties file that looks like this:

           terms.of.use.required=true

we can configure a hook to turn off this feature by changing the property from true

to false.

Step 1:First, we meed to  configure our hook to override properties by editing liferay-hook.xml 
   
       Open the liferay-hook.xml file from our project’s docroot/WEB-INF folder of our example-hook (what we created in previous post)

configure our hook to override properties by editing liferay-hook.xml to look like this:

liferay-hook.xml

<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd">

<hook>
    <portal-properties>portal.properties</portal-properties>
    <custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>

</hook>


Step 2: open portal.properties  file from our project’s docroot/WEB-INF/src  folder 
         and put this 
            terms.of.use.required=false



Step 3: Save and close this file And deploy our hook

Create a new user and log in. The Terms of Use page should not be there 
 New users won’t need to accept the terms of service,and we won’t need to restart our portal for this to take effect.

NOTE:if you wanted to revert this property back to the default behavior, all you would need to do is undeploy the hook, and the portal would immediately revert without the need for a restart.





Wednesday, 29 October 2014

Customizing (Changing) content of terms_of_use using Hook

First we need to create a hook .Here we create Hook by name example-hook

Steps for creating hook
  1) New Liferay Plugin Project   give the project name as example-hook
  2) Select plugin type Hook
  3)Finish

   

Now we will modify your portal’s Terms of Use page.

1)Open the liferay-hook.xml file from your project’s docroot/WEB-INF folder in Liferay IDE

2)Select the Custom JSPs folder from the outline to bring up the custom JSP options. Select the       checkbox Customize Liferay Portal JSPs and create the default custom JSP folder /META-   INF/custom_jsps, by clicking the icon that has the three yellow diamonds.



3)Add to the listing of custom JSPs by clicking the plus icon and specifying Portal’s html/portal/terms_of_use.jsp file. Hint, the browse icon on the right-hand side within the custom JSP text field simplifies finding the JSP you want to customize. It lets you scroll through the JSPs that are accessible and lets you specify key words to narrow your search.
  

4) Save it

5)Open your hook’s docroot/META-INF/custom_jsps/html/portal/terms_of_use.jsp file and modify it as you want.
 
 Note, lots of errors will show in the editor because the resources used in the JSP (e.g., PortalUtil) are not available in the project; but they’ll be available from the portal once the hook plugin is deployed to the portal server. 

6)Deploy your hook and wait until it is deployed successfully. 

7)Create a new user and log in. The Terms of Use page should include the changes you made above.

NOTE

Now there are two Terms of Use JSP files in the liferay-portal-[version]/tomcat-[tomcat-version]/webapps/ROOT/html/portal directory. One is called terms_of_use.jsp and another terms_of_use.portal.jsp. terms_of_use.jsp is your hook’s version, while terms_of_use.portal.jsp is the original. To revert back to the original, undeploy your hook. Your replacement JSP is removed, and the .portal.jsp file is automatically renamed, taking its place. You can override any JSP in the Liferay core, while retaining thew ability to easily revert your changes. However, it’s not possible to override the same JSP from multiple hooks; Liferay won’t know which version to use.






Sunday, 26 October 2014

compleate code for Reg Portlet


view.jsp

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />

<%@page import="javax.portlet.ActionResponse"%>
<%@ include file="/html/reg/init.jsp" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@page import="com.liferay.portal.model.Country"%>
<%@page import="com.liferay.portal.service.CountryServiceUtil"%>

<portlet:defineObjects />

<%
  PortletURL formURL=renderResponse.createActionURL();
  formURL.setParameter(ActionRequest.ACTION_NAME, RegConstants.ACTION_FORM );
%>


<aui:form name="fm" method="POST" action="<%=formURL.toString()%>">
<%-- <aui:input name="redirectURL" type="hidden"
    value="<%=renderResponse.createRenderURL().toString()%>"/> --%>
 
   <aui:input name="userName" label="User Name">
          <aui:validator name="required"/>    
   </aui:input>
   <aui:input name="email" label="Email Id">
         <aui:validator name="required"/>
         <aui:validator name="email"/>
   </aui:input>
 
   <aui:input name="dob" label="Date Of Birth" id="dob"   value="" >
          <aui:validator name="date"/>
   </aui:input>    
   <aui:input name="contact" label="Contact No">
             <aui:validator name="number"/>
             <aui:validator name="minLength">10</aui:validator>
              <aui:validator name="maxLength">10</aui:validator>
   </aui:input>
   <aui:select name="countryId"/>
   <aui:select showEmptyOption="true" name="city" label="City">
      <aui:option label="n1" value="n1"></aui:option>
      <aui:option label="n2" value="n2"></aui:option>
   
  </aui:select>
 
  <%--   <aui:input type="file" name="uploadResume" size="75"/>  --%>

   <aui:button type="submit" value="Submit"/>
</aui:form>

 <aui:script>
     Liferay.Util.focusFormField(
          document.<portlet:namespace/>fm.<portlet:namespace/>userName);
       
 </aui:script>
 <aui:script>
    AUI().ready(function(A){
      var frm=document.<portlet:namespace />fm;
      var countries=frm.<portlet:namespace />countryId;
      Liferay.Service(
                '/country/get-countries',
                 {active:true},
                 function(obj){
                    for(var key in obj){
                     if(obj.hasOwnProperty(key)){
                     var name=obj[key].name;
                     var countryId=obj[key].countryId;
                     countries.options[key]=new Option(name,countryId);
                  }
                 }
                }
              );
           });
     </aui:script>

<%
    PortletURL listRegsURL=renderResponse.createRenderURL();
    listRegsURL.setParameter("jspPage","/html/reg/list.jsp");
%>
   &nbsp;|&nbsp;
   <a href="<%= listRegsURL.toString()%>">Show All Register Detail &raquo;</a>


init.jsp

<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
<%@taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@page import="javax.portlet.PortletURL" %>
<%@page import="javax.portlet.ActionRequest" %>
<%@page import="com.reg.RegConstants"%>
<%@page import="java.util.List"%>
<%@page import="com.slayer.model.REGForm"%>
<%@page import="com.slayer.service.REGFormLocalServiceUtil"%>

 <%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>


//RegPortlet.java(action class)
package com.reg;

import com.liferay.util.bridges.mvc.MVCPortlet;

import java.io.File;
import java.io.IOException;
import java.sql.Date;
import java.util.List;


import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletURL;

import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ServiceContextFactory;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.PortletURLFactoryUtil;
import com.liferay.portlet.documentlibrary.model.DLFileEntry;
import com.liferay.portlet.documentlibrary.model.DLFolder;
import com.liferay.portlet.documentlibrary.service.DLFileEntryServiceUtil;
import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
import com.slayer.model.REGForm;
import com.slayer.model.impl.REGFormImpl;
import com.slayer.service.REGFormLocalServiceUtil;

/**
 * Portlet implementation class RegPortlet
 */
public class RegPortlet extends MVCPortlet {
public void form(ActionRequest actionRequest,ActionResponse actionResponse)
     throws IOException, PortletException{

String userName=ParamUtil.getString(actionRequest, "userName");
String email=ParamUtil.getString(actionRequest, "email");
String dob=ParamUtil.getString(actionRequest, "dob");
long contact=ParamUtil.getLong(actionRequest, "contact");
String city=ParamUtil.getString(actionRequest,"city");
//Boolean uploadResume=ParamUtil.getBoolean(actionRequest,"uploadResume");
System.out.println("InPuts Are==>"+userName+","+email+","+dob+","+contact+","+city);
 REGFormLocalServiceUtil.insert(userName,email,dob,contact,city);
ThemeDisplay themeDisplay =
(ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
PortletConfig portletConfig =
(PortletConfig) actionRequest.getAttribute("javax.portlet.config");
String portletName = portletConfig.getPortletName();
PortletURL successPageURL = PortletURLFactoryUtil.create(
actionRequest,
portletName + "_WAR_" + portletName + "portlet",
themeDisplay.getPlid(),
PortletRequest.RENDER_PHASE);
successPageURL.setParameter("jspPage", RegConstants.PAGE_SUCCESS);
System.out.println("***********");
actionResponse.sendRedirect(successPageURL.toString());
System.out.println("hiiiiiii");
}

}

//RegConstants.java (Interface)
package com.reg;

public interface RegConstants {
static final String ACTION_FORM = "form";

 static final String PAGE_SUCCESS = "/html/reg/success.jsp";
static final String PAGE_LIST="/html/reg/list.jsp";

}

service.xml

xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
<service-builder package-path="com.slayer">
<author>mohsin</author>
<namespace>REG</namespace>

<entity name="REGForm" local-service="true" remote-service="true">

<!-- PK fields -->

<column name="regId" type="long" primary="true" id-type="increment"/>

<!-- Audit fields -->

<column name="userName" type="String" />
<column name="email" type="String" />
<column name="dob"  type="String"  />
<column name="contact" type="long" />
<column name="city" type="String" />
<column name="createDate" type="Date" />
<!-- <column name="modifiedDate" type="Date" />
       -->
<!-- Other fields -->

<!-- <column name="field1" type="String" />
<column name="field2" type="boolean" />
<column name="field3" type="int" />
<column name="field4" type="Date" />
<column name="field5" type="String" /> -->

<!-- Order -->

<!-- <order by="asc">
<order-column name="field1" />
</order>

Finder methods

<finder name="Field2" return-type="Collection">
<finder-column name="field2" />
</finder>
 --> </entity>
</service-builder>

// REGFormLocalServiceImpl.java



package com.slayer.service.impl;



import java.util.Date;

import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.service.ServiceContext;
import com.slayer.model.REGForm;
import com.slayer.model.impl.REGFormImpl;
import com.slayer.service.base.REGFormLocalServiceBaseImpl;

/**
 * The implementation of the r e g form local service.

 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link com.slayer.service.REGFormLocalService} interface.
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author mohsin
 * @see com.slayer.service.base.REGFormLocalServiceBaseImpl
 * @see com.slayer.service.REGFormLocalServiceUtil
 */

public class REGFormLocalServiceImpl extends REGFormLocalServiceBaseImpl {
public REGForm insert(String userName,String email,String dob,long contact,String city){
REGForm regForm =new REGFormImpl();
regForm.setUserName(userName);
regForm.setEmail(email);
regForm.setDob(dob);
regForm.setContact(contact);
regForm.setCity(city);
regForm.setCreateDate(new Date());
//regForm.setUploadResume(uploadResume);
try{
regForm=addREGForm(regForm);
}catch(SystemException e){
e.printStackTrace();
}
 return regForm;
}
}



list.jsp


<%@include file="/html/reg/init.jsp"%>
<%@page import="com.liferay.portal.kernel.util.ListUtil" %>
<portlet:defineObjects/>
<h1>List of Registered Member</h1>

<% 
   List<REGForm>regs = REGFormLocalServiceUtil.getREGForms(0,-1);
  PortletURL iteratorURL = renderResponse.createRenderURL();
  iteratorURL.setParameter("jspPage",RegConstants.PAGE_LIST);
%>

<liferay-ui:search-container delta="4"
   emptyResultsMessage="Sorry there are no item to display."
    iteratorURL="<%=iteratorURL%>">
   <liferay-ui:search-container-results
     total="<%=regs.size() %>"
     results="<%= ListUtil.subList(regs,
                                   searchContainer.getStart(),
                                   searchContainer.getEnd()) %>"/>
   
 <liferay-ui:search-container-row modelVar="reg"
           className="REGForm">
       <liferay-ui:search-container-column-text 
                name="User Name" property="userName"/>    
<liferay-ui:search-container-column-text 
                name="Email Id" property="email"/>
<liferay-ui:search-container-column-text 
                name="DOB" property="dob"/>    
<liferay-ui:search-container-column-text 
                name="Contact No" property="contact"/>    
<liferay-ui:search-container-column-text 
                name="City" property="city"/> 
<liferay-ui:search-container-column-text 
                name="Reg Date" property="createDate"/> 
                   
</liferay-ui:search-container-row>                                
    
<liferay-ui:search-iterator
         searchContainer="<%=searchContainer%>"/>                                  
   </liferay-ui:search-container>
   
<br><a href="<portlet:renderURL/>"> &laquo; Go Back </a>

*********Adding delete link in each  row*********

list.jsp
     Put this code in scriptlet

 PortletURL deleteRegURL=renderResponse.createActionURL();
  deleteRegURL.setParameter(ActionRequest.ACTION_NAME,
                RegConstants.ACTION_DELETE_REG);
  deleteRegURL.setParameter("redirectURL",iteratorURL.toString());

Put this code before </liferay-ui:search-container-row> 

 <%deleteRegURL.setParameter("regId",Long.toString(reg.getRegId()));%>
           <liferay-ui:search-container-column-text name="Delete"
                          href="<%=deleteRegURL.toString() %>" value="delete"/>


//RegPortlet.java(action class) add delete method in action class

public void deleteReg(ActionRequest actionRequest, ActionResponse actionResponse)
           throws IOException,PortletException{

long regId=ParamUtil.getLong(actionRequest, "regId");
if(regId > 01){ //valid regId
try{
REGFormLocalServiceUtil.deleteREGForm(regId);
}catch(PortalException e){
e.printStackTrace();
}catch(SystemException e){
e.printStackTrace();
}

}
//gracefully redirecting to the list view
String redirectURL=ParamUtil.getString(actionRequest,"redirectURL");
actionResponse.sendRedirect(redirectURL);

}



//RegConstants.java (Interface)

static final String ACTION_DELETE_REG="deleteReg";



  Adding Actions on in each row


Saturday, 25 October 2014

Registration page with validation

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="javax.portlet.PortletURL" %>
<%@page import="javax.portlet.ActionRequest" %>

<portlet:defineObjects />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<link rel="stylesheet" href="css/layout-admin.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/jquery-ui.css" type="text/css" media="screen" />
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />

<%
  PortletURL regFormURL=renderResponse.createActionURL();
  regFormURL.setParameter(ActionRequest.ACTION_NAME,"regForm");
%>
<script>
function validateForm(){
var x=document.forms["regForm"]["username"].value;
if(x==null || x==""){
alert("Please Enter User Name");
return false;
}
}
function validateForm(){
var x=document.forms["regForm"]["loginid"].value;
if(x==null || x==""){
alert("Please Enter login Id");
return false;
}
}

function validateForm(){
var x=document.forms["regForm"]["pwd"].value;
if(x==null || x==""){
alert("Please Enter password");
return false;
}
}
function validateForm(){
var x=document.forms["regForm"]["confpwd"].value;
if(x==null || x==""){
alert("Please Retype password for confirm password");
return false;
}
}
function validateForm(){
var x=document.forms["regForm"]["email"].value;
if(x==null || x==""){
alert("Please enter a valid Email id");
return false;
}
}

function validateForm() {
    var x = document.forms["regForm"]["email"].value;
    var atpos = x.indexOf("@");
    var dotpos = x.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {
        alert("Not a valid e-mail address");
        return false;
    }
}
function validateForm(){
var x=document.forms["regForm"]["phone"].value;
if(x==null || x==""){
alert("Phone Number is mandatory Please enter your phone number");
return false;
}
}
function validateForm(){
var x=document.forms["regForm"]["address"].value;
if(x==null || x==""){
alert("Please Enter your address");
return false;
}
}
function validateForm(){
var x=document.forms["regForm"]["answer"].value;
if(x==null || x==""){
alert("Please give answer for the selected question")
}
}



$(document).ready(function () {  
$("#datepicker1" ).datepicker( {
         changeDate:true,
changeMonth: true,//this option for allowing user to select month
         changeYear: true, //this option for allowing user to select from year range
         showOn: "button",
         buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
         buttonImageOnly: true
       
}).datepicker("setDate", new Date());
   
});
</script>



<form name="<portlet:namespace/>regForm" method="POST" action="<%=regFormURL.toString()%>"  onsubmit="return validateForm()" >
<table summary="Demonstration form">
  <tbody>
  <tr>
    <td><label for="username">Enter your name:</label></td>
    <td><input name="<portlet:namespace/>username" size="35" maxlength="50" type="text"></td>
  </tr>
  <tr>
    <td><label for="dateOfBirth">Date Of Birth:</label></td>
    <td><input name="<portlet:namespace/>dateOfBirth" id="datepicker1" size="35" maxlength="50"        
                                      type="date"></td>
  </tr>
     
  <tr>
    <td><label for="email">Email Id:</label></td>
    <td><input name="<portlet:namespace/>email" size="35" maxlength="30" type="text"></td>
  </tr>
  <tr>
    <td><label for="pwd">Required password</label></td>
    <td><input name="<portlet:namespace/>pwd" size="35" maxlength="25" type="password"></td>
  </tr>
  <tr>
    <td><label for="confpwd">Confirm password</label></td>
    <td><input name="<portlet:namespace/>confpwd" size="35" maxlength="25" type="password"></td>
  </tr>  
 
  <tr>
    <td>
        <label for="address">Address:</label></td>
    <td><textarea name="<portlet:namespace/>address"  maxlength="50" ></textarea></td>
  </tr>
  <tr>
    <td><label for="country">Country:</label></td>
    <td><select name="<portlet:namespace/>country"> </select></td>
  </tr>
  <tr>
    <td><label for="state">State:</label></td>
    <td><select name="<portlet:namespace/>state"> </select></td>
  </tr>
  <tr>
    <td><label for="city">City:</label></td>
    <td><select name="<portlet:namespace/>city"> </select></td>
  </tr>  
  <tr>
    <td><label for="phone">Phone Number:</label></td>
    <td><input name="<portlet:namespace/>phone" size="35" maxlength="25" type="text"></td>
  </tr>  
 
 
   <tr>
    <td><label for="question">Security Question:</label></td>
    <td><select name="<portlet:namespace/>question" >
        <option value="000" selected="selected">Select any Security Question</option>
        <option value="008">What is your favourite Place</option>
        <option value="012">What is your pet name</option>
        <option value="016">What is your College Id</option>
        <option value="020">Who is your first Teacher</option>
        <option value="024">Your first school</option>
        <option value="660">Your bike number </option>
    </select>
    </td>
  </tr>
  <tr>
    <td><label for="answer">Security Answer:</label></td>
    <td><input name="<portlet:namespace/>answer" size="35" maxlength="50" type="text"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input name="Submit" value="Register" type="submit">
        <input name="Reset" value="Reset" type="reset">
       
       <!-- <button type="submit"><img src="/images/submit.png" alt="Submit"></button> -->
   
     </td>
   
   
  </tr>
  </tbody>
</table>
</form>

///action class

package com.register;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class RegisterPortlet extends MVCPortlet{

public void regForm(ActionRequest actionRequest,ActionResponse actionResponse)
       throws IOException, PortletException{
String username=ParamUtil.getString(actionRequest,"username");
    String dateOfBirth=ParamUtil.getString(actionRequest, "dateOfBirth");
    String email=ParamUtil.getString(actionRequest, "email");
    String pwd=ParamUtil.getString(actionRequest,"pwd");
    String confpwd=ParamUtil.getString(actionRequest, "confpwd");
    String address=ParamUtil.getString(actionRequest,"address");
    String country=ParamUtil.getString(actionRequest,"country");
    String state=ParamUtil.getString(actionRequest,"state");
    String city=ParamUtil.getString(actionRequest,"city");
    String phone=ParamUtil.getString(actionRequest,"phone");
    String question=ParamUtil.getString(actionRequest,"question");
    String answer=ParamUtil.getString(actionRequest,"answer");
   
    System.out.println("your in puts ::"+username+","+dateOfBirth+","
      +email+","+pwd+","+confpwd+","+address+","+country+","+state+","+city+","+phone+","+question+","+answer);

 
}
}

Saturday, 18 October 2014

Image Slider In Liferay

ce login as Admin go to Admin >> Site Administration
 
 
Once you go to Site Administration select Content Panel there you can click on web content
 
 
 
Create Structure
 
In the web content top navigation Manu you can see manage option menu there you can select 
structure link as follows
 
 
 
 
Once click on Structures then window pop up will be launch there you can enter your structure name and description
 
 
The following is Structure Creation Screen
 
 
In the bottom of pop up window you can see User Interface Design to Design Structure as follows
 
 
 
We have many controls so we can use all elements and we can design. Now we already have code for Image Slide show Structure so you simply click on source and in editor use following source code.
 
 
<root available-locales="en_US" default-locale="en_US">
<dynamic-element dataType="image" fieldNamespace="wcm" indexType="keyword" name="images" readOnly="false" repeatable="true" required="false" showLabel="true" type="wcm-image" width="">
<dynamic-element dataType="link-to-page" fieldNamespace="ddm" indexType="keyword" name="imagelink" readOnly="false" repeatable="false" required="false" showLabel="true" type="ddm-link-to-page" width="small">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[Link to Page]]>
</entry>
<entry name="predefinedValue">
<![CDATA[]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
<meta-data locale="en_US">
<entry name="label">
<![CDATA[Image]]>
</entry>
<entry name="predefinedValue">
<![CDATA[]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
<dynamic-element dataType="number" fieldNamespace="ddm" indexType="keyword" name="containerwidth" readOnly="false" repeatable="false" required="false" showLabel="true" type="ddm-number" width="small">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[Container Width]]>
</entry>
<entry name="predefinedValue">
<![CDATA[]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
<dynamic-element dataType="number" fieldNamespace="ddm" indexType="keyword" name="containerhight" readOnly="false" repeatable="false" required="false" showLabel="true" type="ddm-number" width="small">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[Container Hight]]>
</entry>
<entry name="predefinedValue">
<![CDATA[]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
<dynamic-element dataType="number" fieldNamespace="ddm" indexType="keyword" name="intervaltime" readOnly="false" repeatable="false" required="false" showLabel="true" type="ddm-number" width="small">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[Interval Time]]>
</entry>
<entry name="predefinedValue">
<![CDATA[]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
</root>
 
The following screen after use source in editor
 
 
 
The following is Graphical view of Structure
 
 
 
Finally click on save button then your structure will be created
 
 
Finally close pop up window and go back to Web content Manage Screen
 
Create Template and associate with Respective Structure
 
Now we need create template and it will use above created structure. In the web content screen top navigation goes manage option menu there you can findTemplates Link
 
 
 
 
Once we click on template then pop window will be open there we can see +Add to create new template.
 
Now we need to fill the name and description along with that we need select respective structure. In our case we already create structure i.e. Image Slide Show Structure we need to select that.
 
We already know we are using free market template so we need to select Language as Free Marker (ftl) and its default language, apart from that we can use velocity and XSLT
 
 
 
In the bottom of pop up you can see Template editor and its respective Structure variables /fields and other available variables was shown in left side.
 
In the structure we have used some fields all fields you can see left side as follows
 
 
 
We already have Free Marker Template code for Image Slide Show please use following code in Editor and save then template will be created.
 
 
<script>
AUI({ filter: 'raw' }).use('aui-carousel', function(A) {
new A.Carousel({
intervalTime:${intervaltime.getData()},
contentBox: '#myCarousel',
activeIndex:0,
height:${containerhight.getData()},
width:${containerwidth.getData()}
}).render();
 
});
</script>
<#if images.getSiblings()?has_content>
<div id="myCarousel">
<#list images.getSiblings() as cur_images>
 
<#if cur_images_index==0>
<a href="${cur_images.imagelink.getData()}">
<div class="carousel-item" style="background: url(${cur_images.getData()})width:${containerwidth.getData()}px; height:${containerhight.getData()}px;" class="carousel-item carousel-item-active";">
</div>
</a>
</#if>
<a href="${cur_images.imagelink.getData()}"> <div class="carousel-item" style="background: url(${cur_images.getData()});width:${containerwidth.getData()}px; height:${containerhight.getData()}px;" class="carousel-item""></div></a>
</#list>
 
</div>
</#if>
 
 

In the Template Design we use html and AUI Script to design template. And we will use stricture variable or fields to fill with dynamic content. These all design was made using Free Market Templates (FTL)
 
However use above template code in editor and finally save it then template will be create and it will be associated with one structure that is we created previously.
 
Note:
 
When we click in fields and variables in left side those will be added in the editor automatically where your cursor point in the editor. Templates editor is every flexible to code or design free marker templates in editor.
 
Each template should be associated with one structure and based in structure we need to code free market template to use structure variables and based on template design we will get input elements to design web content with dynamic data.
 
The following free marker template code in editor

 
 
Now finally save then your template will be created and it will be in the templates list as follows.
 
 
 
Now close pop up window and go back to web content screen.
 
Create web content by using Template
 
Well we are ready with Template and Structure and we will create web content using above template.
 
In the web content screen you can see +Add button option menu in the top navigation there you can see newly created template name that is Image Slide Show Template
 
 
Now you will get web content creation screen with selected template. We need to fill name for web content.
 
Based on template we need to fill the content and in our scenario we are using images element as repeatable so we can add more images by click + icon apposite to images file input element.
 
And we are using Height, Width and Interval we need to fill those values and it should be numbers and we can also select hyper link for each image
 
 
Once we fill the content in the web content template finally click on publish button then content will be available to use and it will be shown in web content list.
 
 
Using Web Content
 
We have done all steps now the content will be available to use. We will use web content display portlet to display web content in the pages.
 
Navigate to desirable page where you simply drag and drop web content display portlet in the page.
 
In the admin mode you can see left side + Icon click on the you can get the toggle there in the applications tab you can select Web content Display Portlet simply click on Add Link then blank web content display portlet will be added to page.
 
 
In the blank web content display portlet you can see toggle control in the bottom.
 
 
You can click on Select Web content there you can see list of web content articles.
 

  

Tuesday, 14 October 2014

Embedding Portlet inside Web Content

Step 1: Create a new page by name "Embedded" When new page is ready  add "Web Content Display" portlet onto the right side of the page


Step 2: Click the second icon at the bottom to add a new Web Content. Give a new article id as "PORTLET_HOST", a good title and some good contents. Before click on publish  to save the article , switch to source mode  to insert embedding line in side it .

<runtime-portlet name="library_WAR_libraryportlet"></runtime-portlet>

Here "library_WAR_libraryportlet"is the id of the portlet that we have to embed. You can  get this d from Liferay's  portlet table in the database (select * from portlet;) 

Embedding Web Content in a Portlet

Step 1: Login to portal as administrator. Go to Control Panel--> Liferay --> Wb Content.
  Before we create a new Web Content(article)  for the front page of our portlet, we have to do an important thing.  open "portal-setup-wizard.properties" under PORTAL_HOME

       append this code

     journal.article.force.autogenerate.id=false
     journal.structure.force.autogenerate.id=false
     journal.template.force.autogenerate.id=false

Save and restart the server

Now check the "Web Content" page click on  Add-->Basic Web Content  to create a new article
 now the  form will have a field to manually enter  the article id .this was not the case before.

Step 2: Create a new content with an ID as "WELCOME_MESSAGE"(you can give any meaningful name ), a title and some  contents. and  click on Publish .

Step 3:  In this step we are actually going to consume this Web Content(article) inside our portlet.
Open view.jsp and insert the tag immediately after the import and include statements.

<liferay-ui:journal-article articleId="WELCOME_MESSAGE"
     groupId="<%=themeDisplay.getScopeGroupId()%>">
     </liferay-ui:journal-article>
 
Save and check the front page of our portlet now.

How to appear Portlet In Control Panel

Open  "liferay-portlet.xml"  of your portlet
Insert these two line at the appropriate location (just before "action-url-redirect" )

<control-panel-entry-category>content</control-panel-entry-category>
 <control-panel-entry-weight>3.5</control-panel-entry-weight>

Goto control panel and check  under liferay  menu

Thursday, 2 October 2014

Internationalization(i18n) in liferay

Complete working program





My project name is AUIproj.


In Language.properties which labels or the data we want to translate then we have to write inside this file. Suppose in my AUIproj I just want to change the name of my labels and my title only so we have to follow these steps:
Step 1:
First create a folder inside docroot/WEB-INF/src by the name of content, inside content folder, create a file Language.properties.


Step 2:
copy this content to Language.properties
javax.portlet.title=AUI Portlet
product-name=Product Name
product-serial=Product Serial


Step 3:
right click on project then build language lots of supported language files will create inside your content folder automatically and all files contain the same contents that present in your
Language.properties files.


Step 4:
Now we have to just write that specific labels name on that specific file and change the contents on that place.
Use google translator and paste them suppose for hindi I just wrote in hindi file like
javax.portlet.title=भाषा
product-name=उत्पाद नाम
product-serial=उत्पाद धारावाहिक
The name of hindi Language file is Language_hi_IN.properties.



In init.jsp I declared lots of taglib, lots of java classes by import statements.


init.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.Collections" %>
<%@ page import="com.liferay.portal.kernel.util.HtmlUtil" %>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="com.liferay.portal.kernel.util.CalendarFactoryUtil" %>
<%@ page import="com.liferay.portal.kernel.dao.search.ResultRow" %>
<%@ page import="com.liferay.portal.kernel.dao.search.SearchEntry" %>
<%@ page import="com.liferay.portal.kernel.exception.SystemException" %>
<%@ page import="com.liferay.portal.kernel.util.WebKeys" %>
<%@ page import="com.liferay.portal.security.permission.ActionKeys" %>
<%@ page import="com.liferay.portal.kernel.util.ListUtil" %>
<%@ page import="com.liferay.portal.service.permission.PortalPermissionUtil" %>
<%@ page import="com.liferay.portal.service.permission.PortletPermissionUtil" %>
<%@ page import="javax.portlet.PortletURL" %>
<liferay-theme:defineObjects />




In view.jsp just imported init.jsp
view.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ include file="init.jsp" %>
<portlet:defineObjects />


This is the <b>AUI Portlet</b> portlet in View mode.


<portlet:actionURL name="addProduct" var="addProductURL" />
   <aui:form action="<%= addProductURL.toString() %>" method="post">
       <aui:fieldset>
           <aui:input name="productName" />
           <aui:input name="productSerial" />
           <aui:button-row>
               <aui:button type="submit" />
           </aui:button-row>
       </aui:fieldset>
   </aui:form>


build.xml
<?xml version="1.0"?>
<!DOCTYPE project>


<project name="AUIproj-portlet" basedir="." default="deploy">
   <import file="../build-common-portlet.xml" />
   <target name="build-lang">
   <antcall target="build-lang-cmd">
   <param name="lang.dir" value="docroot/WEB-INF/src/content" />
   <param name="lang.file" value="Language" />
   </antcall>
   </target>
</project>
Paste this line just in portlet.xml just after <supports> tag
<resource-bundle>content.Language</resource-bundle>




Finally at first time  build language and if you change any data on properties files then build language else no need to build language again and again. But some time it is showing some warnings like in future …...properties file will modified so to again build language and this time the contents of hindi properties file will not change.
Finally go to control panel of liferay -&gt; Test test -&gt; my account -&gt; miscellaneous-&gt; display settings -&gt; Language select hindi and you can see the the title and our labels will change into Hindi language.