组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Amit Shukla
Custom field default value programmatically.
2012年7月26日 下午10:42
答复

Amit Shukla

等级: Junior Member

帖子: 92

加入日期: 2012年6月7日

最近的帖子

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.
2012年7月27日 上午12:02
答复

Jignesh Vachhani

等级: Liferay Master

帖子: 772

加入日期: 2008年3月10日

最近的帖子

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.
2012年7月27日 上午2:03
答复

Pranay R Patadiya

等级: Regular Member

帖子: 179

加入日期: 2010年2月22日

最近的帖子

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

More on expando : Expando Usage
Jignesh Vachhani
RE: Custom field default value programmatically.
2012年7月27日 上午2:06
答复

Jignesh Vachhani

等级: Liferay Master

帖子: 772

加入日期: 2008年3月10日

最近的帖子

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.
2012年7月27日 上午3:22
答复

Amit Shukla

等级: Junior Member

帖子: 92

加入日期: 2012年6月7日

最近的帖子

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.
2012年7月27日 上午3:51
答复

Jignesh Vachhani

等级: Liferay Master

帖子: 772

加入日期: 2008年3月10日

最近的帖子

Please import below line in jsp:

<%@page import="com.liferay.portlet.journal.service.TestDataLocalServiceUtil"%>
Amit Shukla
RE: Custom field default value programmatically.
2012年7月27日 上午4:24
答复

Amit Shukla

等级: Junior Member

帖子: 92

加入日期: 2012年6月7日

最近的帖子

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.
2012年7月27日 上午4:35
答复

Jignesh Vachhani

等级: Liferay Master

帖子: 772

加入日期: 2008年3月10日

最近的帖子

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.
2012年7月27日 上午5:01
答复

Amit Shukla

等级: Junior Member

帖子: 92

加入日期: 2012年6月7日

最近的帖子

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.
2012年7月27日 上午5:20
答复

Nikhil Nishchal

等级: Junior Member

帖子: 74

加入日期: 2012年6月21日

最近的帖子

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.
2012年7月27日 上午7:01
答复

Jignesh Vachhani

等级: Liferay Master

帖子: 772

加入日期: 2008年3月10日

最近的帖子

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.
2012年7月27日 下午1:01
答复

Jay Patel

等级: Regular Member

帖子: 115

加入日期: 2010年2月23日

最近的帖子

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.
2013年2月27日 上午5:58
答复

Amit Shukla

等级: Junior Member

帖子: 92

加入日期: 2012年6月7日

最近的帖子

Hi Jignesh,

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

Thanks
Amit