Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Amit Shukla
Custom field default value programmatically.
July 26, 2012 10:42 PM
Answer

Amit Shukla

Rank: Junior Member

Posts: 92

Join Date: June 7, 2012

Recent Posts

Hi all,

I want to create some custom field with default values (these values will come through database table) for document library .How can I do this programmatically.


Please tell me step so that i can do this task.

Thanks a lot
Amit
Jignesh Vachhani
RE: Custom field default value programmatically.
July 27, 2012 12:02 AM
Answer

Jignesh Vachhani

Rank: Liferay Master

Posts: 780

Join Date: March 10, 2008

Recent Posts

follow this steps :

1) Make TestData table dump in liferay DB
2) create service.xml with te column name you have in your table
and put service.xml in your cutome portlet location (test-portlet/docroot/WEB-INF)
 1
 2<?xml version="1.0"?>
 3<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
 4
 5<service-builder package-path="com.liferay.portlet.journal">
 6    <namespace>test</namespace>
 7    <entity name="TestData" uuid="true" local-service="true" remote-service="true">
 8        <!-- PK fields -->
 9        <column name="id" type="long" primary="true" />
10        <column name="fname" type="String" />
11        <column name="lname" type="String" />
12    </entity>
13
14</service-builder>


3) Now build the service using ant build-service command from portlet
4) Now it will generate some classes and you can check that TestDataLocalServiceImpl class has been generated or not .
5) Now define your method in that class to get data all data even you can get data by promary key and other parameter as well.
 1
 2/**
 3 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 4 *
 5 * This library is free software; you can redistribute it and/or modify it under
 6 * the terms of the GNU Lesser General Public License as published by the Free
 7 * Software Foundation; either version 2.1 of the License, or (at your option)
 8 * any later version.
 9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 */
15
16package com.liferay.portlet.journal.service.impl;
17
18import com.liferay.portal.kernel.exception.SystemException;
19import com.liferay.portlet.journal.model.TestData;
20import com.liferay.portlet.journal.service.base.TestDataLocalServiceBaseImpl;
21import com.liferay.portlet.journal.service.persistence.TestDataUtil;
22
23public class TestDataLocalServiceImpl extends TestDataLocalServiceBaseImpl {
24    public java.util.List<TestData> getData() throws SystemException{
25        java.util.List<TestData> dataList = TestDataUtil.findAll();
26        return dataList;       
27    }
28}


Now in jsp you can write to get all data :

<%=TestDataLocalServiceUtil.getData()%>
Pranay R Patadiya
RE: Custom field default value programmatically.
July 27, 2012 2:03 AM
Answer

Pranay R Patadiya

Rank: Regular Member

Posts: 181

Join Date: February 22, 2010

Recent Posts

Hi,
Expando is also a good solution for you problem.

More on expando : Expando Usage
Jignesh Vachhani
RE: Custom field default value programmatically.
July 27, 2012 2:06 AM
Answer

Jignesh Vachhani

Rank: Liferay Master

Posts: 780

Join Date: March 10, 2008

Recent Posts

Pranay, I think Amit has data already in table and he wants to reuse that table data if i am not wrong.
So in that case use of Expando could not be suitable solution as per my knowledge.
Amit Shukla
RE: Custom field default value programmatically.
July 27, 2012 3:22 AM
Answer

Amit Shukla

Rank: Junior Member

Posts: 92

Join Date: June 7, 2012

Recent Posts

Thanks Jignesh,

I followed the same step but getting the error.

An error occurred at line: 372 in the jsp file: /html/portlet/document_library/edit_file_entry.jsp

TestDataLocalServiceUtil cannot be resolved

Please look into this and suggest me what i have to do?

Thanks
Amit
Jignesh Vachhani
RE: Custom field default value programmatically.
July 27, 2012 3:51 AM
Answer

Jignesh Vachhani

Rank: Liferay Master

Posts: 780

Join Date: March 10, 2008

Recent Posts

Please import below line in jsp:

<%@page import="com.liferay.portlet.journal.service.TestDataLocalServiceUtil"%>
Amit Shukla
RE: Custom field default value programmatically.
July 27, 2012 4:24 AM
Answer

Amit Shukla

Rank: Junior Member

Posts: 92

Join Date: June 7, 2012

Recent Posts

Hi Jignesh,
I have already imported the page
--------------------------------------com.liferay.test.cp.service.TestDataLocalServiceUtil ( i am using a hook for make changes in edit_file_entry.jsp)
now i am getting the error
Only a type can be imported. com.liferay.test.cp.service.TestDataLocalServiceUtil resolves to a package

Please u have any idea about it.

Thanks
Amit
Jignesh Vachhani
RE: Custom field default value programmatically.
July 27, 2012 4:35 AM
Answer

Jignesh Vachhani

Rank: Liferay Master

Posts: 780

Join Date: March 10, 2008

Recent Posts

provide your table entity here with all columns so that i can give you exact code here .
Here whatever code i putted is working in my local so you would be following something different way i think.
Amit Shukla
RE: Custom field default value programmatically.
July 27, 2012 5:01 AM
Answer

Amit Shukla

Rank: Junior Member

Posts: 92

Join Date: June 7, 2012

Recent Posts

Hi Jignesh,
I have a table---- Siteinfo which have two coloumn(Siteid,sitedescription).
Siteid----sitedescription
123----->heritage site
345----->iucn information

I have requirement on uploading data each documents have a site id associated with it.

so we have made some changing in edit _file_entry.jsp for this.

Please help me .

Thanks
Amit
Nikhil Nishchal
RE: Custom field default value programmatically.
July 27, 2012 5:20 AM
Answer

Nikhil Nishchal

Rank: Junior Member

Posts: 99

Join Date: June 21, 2012

Recent Posts

You can try as (for liferay 6.1) :
FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(userId, repositoryId, folderId, sourceFileName, mimeType, title, description, changeLog, bytes, serviceContext);
fileEntry.getExpandoBridge().setAttributeDefault("custon-aatibute", defaultValue);


defaultValue can be given by DB.
Jignesh Vachhani
RE: Custom field default value programmatically.
July 27, 2012 7:01 AM
Answer

Jignesh Vachhani

Rank: Liferay Master

Posts: 780

Join Date: March 10, 2008

Recent Posts

Amit,
IF your entity name is Siteino then you may have class name SiteInfoLocalServiceUtil instead of TestDataLocalServiceUti.
If your service builder has generated all classes proper then you can easily find with your eclipse IDE.
SO follow steps properly which i mentioned in my previous post .
Jay Patel
RE: Custom field default value programmatically.
July 27, 2012 1:01 PM
Answer

Jay Patel

Rank: Regular Member

Posts: 116

Join Date: February 23, 2010

Recent Posts

Amit Shukla:
Hi Jignesh,
I have already imported the page
--------------------------------------com.liferay.test.cp.service.TestDataLocalServiceUtil ( i am using a hook for make changes in edit_file_entry.jsp)
now i am getting the error
Only a type can be imported. com.liferay.test.cp.service.TestDataLocalServiceUtil resolves to a package

Please u have any idea about it.

Thanks
Amit


Hi Amit,

If you have created service.xml in some test-portlet under Plugin-SDK then your Util classes by default will not be accessible to your JSP in Hook as those are in different class loader.

If that is the path you want to follow, then you will have to copy your service jar generated by service-builder & paste in to the Global lib directory of your application server (/lib/ext) if you are using Tomcat , remove it from your portlet's lib directory & restart the server.

-Jay.
Amit Shukla
RE: Custom field default value programmatically.
February 27, 2013 5:58 AM
Answer

Amit Shukla

Rank: Junior Member

Posts: 92

Join Date: June 7, 2012

Recent Posts

Hi Jignesh,

Can you provide consultancy for my project? plesae let me know.

Thanks
Amit