Fóruns

Início » Liferay Portal » English » 6. Portal Framework

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Amit Shukla
Custom field default value programmatically.
26 de Julho de 2012 22:42
Resposta

Amit Shukla

Ranking: Junior Member

Mensagens: 92

Data de entrada: 7 de Junho de 2012

Mensagens recentes

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.
27 de Julho de 2012 00:02
Resposta

Jignesh Vachhani

Ranking: Liferay Master

Mensagens: 780

Data de entrada: 10 de Março de 2008

Mensagens recentes

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.
27 de Julho de 2012 02:03
Resposta

Pranay R Patadiya

Ranking: Regular Member

Mensagens: 181

Data de entrada: 22 de Fevereiro de 2010

Mensagens recentes

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

More on expando : Expando Usage
Jignesh Vachhani
RE: Custom field default value programmatically.
27 de Julho de 2012 02:06
Resposta

Jignesh Vachhani

Ranking: Liferay Master

Mensagens: 780

Data de entrada: 10 de Março de 2008

Mensagens recentes

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.
27 de Julho de 2012 03:22
Resposta

Amit Shukla

Ranking: Junior Member

Mensagens: 92

Data de entrada: 7 de Junho de 2012

Mensagens recentes

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.
27 de Julho de 2012 03:51
Resposta

Jignesh Vachhani

Ranking: Liferay Master

Mensagens: 780

Data de entrada: 10 de Março de 2008

Mensagens recentes

Please import below line in jsp:

<%@page import="com.liferay.portlet.journal.service.TestDataLocalServiceUtil"%>
Amit Shukla
RE: Custom field default value programmatically.
27 de Julho de 2012 04:24
Resposta

Amit Shukla

Ranking: Junior Member

Mensagens: 92

Data de entrada: 7 de Junho de 2012

Mensagens recentes

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.
27 de Julho de 2012 04:35
Resposta

Jignesh Vachhani

Ranking: Liferay Master

Mensagens: 780

Data de entrada: 10 de Março de 2008

Mensagens recentes

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.
27 de Julho de 2012 05:01
Resposta

Amit Shukla

Ranking: Junior Member

Mensagens: 92

Data de entrada: 7 de Junho de 2012

Mensagens recentes

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.
27 de Julho de 2012 05:20
Resposta

Nikhil Nishchal

Ranking: Junior Member

Mensagens: 74

Data de entrada: 21 de Junho de 2012

Mensagens recentes

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.
27 de Julho de 2012 07:01
Resposta

Jignesh Vachhani

Ranking: Liferay Master

Mensagens: 780

Data de entrada: 10 de Março de 2008

Mensagens recentes

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.
27 de Julho de 2012 13:01
Resposta

Jay Patel

Ranking: Regular Member

Mensagens: 116

Data de entrada: 23 de Fevereiro de 2010

Mensagens recentes

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.
27 de Fevereiro de 2013 05:58
Resposta

Amit Shukla

Ranking: Junior Member

Mensagens: 92

Data de entrada: 7 de Junho de 2012

Mensagens recentes

Hi Jignesh,

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

Thanks
Amit