Using Liferay service builder to access existing tables in a database

I am writing a portlet to be read from a set of tables in a liferay database created by a portlet of another service builder.

I tried just to duplicate service.xml and create a service, and all I get for my problems is this:

BeanLocator is not installed

Is there an easy way to write a second portlet that can be used for these existing tables, and can it be configured to build it, rather than trying to recreate what already exists?

I don’t want to add this to the source portlet, if at all possible, since these tables contain information that may be required to access many other portlets, and having a large number of portlets in one deployment will make the service a headache.

+5
source share
3 answers

To access the same service tables in different portlets, do not recreate the services in each of them. Instead, create the service in one portlet and copy it docroot/WEB-INF/lib/<pluginmame>-portlet-service.jarto the directory of the docroot/WEB-INF/lib/other portlets. Let's see an example.

Suppose you have the following service.xmlin a portlet person-portlet:

<service-builder package-path="br.com.seatecnologia.stackoverflow.person">
    <author>brandizzi</author>
    <namespace>StackOverflowPerson</namespace>

    <entity name="Person" local-service="true" remote-service="false">
        <column name="personId" type="long" primary="true" />

        <column name="name" type="String" />
        <column name="age" type="int" />
    </entity>
</service-builder>

, . , JSP :

<%@page import="br.com.seatecnologia.stackoverflow.person.service.PersonLocalServiceUtil"%>
<%@page import="br.com.seatecnologia.stackoverflow.person.model.Person"%>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>

<portlet:actionURL name="addPerson" var="url" />

<aui:form action="<%= url %>" name="fm" method="POST">
<aui:fieldset>
<aui:input name="name" />
<aui:input name="age" />
<aui:button type="submit" />
</aui:fieldset>
</aui:form>

<ul>
    <% for (Person person : PersonLocalServiceUtil.getPersons(-1, -1)) { %>
    <li><%= person.getName() %> : <%= person.getAge() %></li>
    <% } %>
</ul>

, , - Hello World, . , , multiple-hello-portlet, person-portlet-service.jar person-portlet/docroot/WEB-INF/lib multiple-hello-portlet/docroot/WEB-INF/lib. , _, , person-portlet, multiple-hello-portlet . , multiple-hello-portlet JSP, :

<%@page import="br.com.seatecnologia.stackoverflow.person.service.PersonLocalServiceUtil"%>
<%@page import="br.com.seatecnologia.stackoverflow.person.model.Person"%>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

<% for (Person person :  PersonLocalServiceUtil.getPersons(-1, -1)) { %>
    <div class="portlet-msg-info">
        Hello, <%= person.getName() %>!
        You are <%= person.getAge() %> years old.
    </div>
<% } %>

, BitBucket.

+7

Liferay Hook, (, ).

EXT , Liferay .

+1

, jar .

api jar warlet portlet. , , api jar . , , , "". (. 6)

from: http://www.liferay.com/de/about-us/news/-/blogs/2506216/maximized

+1

All Articles