Thursday, 9 July 2015

Liferay Custom field and Expando Tables

Creating Extra Field

If you want to add extra field in liferay default table ......
 In 6.2
Admin-------------->control panel--------->Custom Fields---------->User

select entity for ex..User

User-------->Add Custom Field -------->Enter Key &  Type and save it 




Saving The Custom field value

 
in jsp page
 <%
      User currentUser = themeDisplay.getUser();
          %>
          <div class="control-group">
            <label for="reportingManager" class="control-label">Reporting Manager</label>
            <div class="controls">
              <liferay-ui:custom-attribute-list
              className="<%= User.class.getName() %>"
              classPK="<%= currentUser != null ? currentUser.getUserId() : 0 %>"
              editable="<%= true %>" label="false"/>
            </div>
          </div>   
in controller
  ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(),      actionRequest);
    user.setExpandoBridgeAttributes(serviceContext);
    UserLocalServiceUtil.addUser(user);


After creating custom field ,it is available in ExpandoTable and ExpandoColumn

After Saving You can check it in ExpandoValue Table



 

Monday, 6 July 2015

Fetching Last Primary Key From Table

1.     SELECT qualityId FROM `quality_quality`
        ORDER BY qualityId DESC
        LIMIT 1;

2.     select max(qualityId ) from quality_quality"


3. In Liferay
         
          Quality qua = new QualityImpl();
           long siz1 = 0 ;
     try{
          long qualityId = ParamUtil.getLong(renderRequest, "qualityId");
         qua = QualityLocalServiceUtil.getQuality(qualityId);
      if(qualityId > 0)
        siz1 = qua.getQualityId();
}catch(Exception e){
    int size=l.size();
    if(size == 0){
         siz1 = 1;
         //out.print(siz1);
    }else{
          siz1 = ((l.get(size-1).getQualityId())+1) ;
          //out.print(siz1);
      }
}

Monday, 22 June 2015

How to create Folder in Java

import java.io.File;
 
public class CreateFolder
{
    public static void main(String[] args)
    { 
 File file = new File("C:\\Folder");
 if (!file.exists()) {
  if (file.mkdir()) {
   System.out.println("Folder is created!");
  } else {
   System.out.println("Failed to create Folder!");
  }
 }
 
 File files = new File("C:\\Folder1\\Sub1\\Sub-Sub1");
 if (files.exists()) {
  if (files.mkdirs()) {
   System.out.println("Multiple Folders are created!");
  } else {
   System.out.println("Failed to create multiple Folders!");
  }
 }
 
    }
}

Monday, 15 June 2015

Creating File in java

import java.io.File;
import java.io.IOException;

public class WriteInFile {

public static void main(String[] args) {
// TODO Auto-generated method stub
try {
File f = new File("d:\\newfile.txt");       // path to create file

if (f.createNewFile()){
System.out.println("file created");
}else{
System.out.println("file is their");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

Sunday, 14 June 2015

Using custom properties file in jsp and java files for dynamic work(In Liferay 6.2)



 Properties prop = new Properties();
 FileInputStream inputStream = new FileInputStream("/path of the file");
 prop.load(inputStream);


U can keep properties file location src else tomcat bundle

Thursday, 11 June 2015

Embedding One portlet in Another (Liferay 6.2)

Write Below Lines in Jsp Page

<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
 <liferay-portlet:runtime portletName="82" />


Where 82 is portlet Id