Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For accessing the same tables of a service in different portlets, do not recreate the services in each one. Instead, create the service in one portlet and copy its <code>docroot/WEB-INF/lib/&lt;pluginmame&gt;-portlet-service.jar</code> to the <code>docroot/WEB-INF/lib/</code> directory of the other portlets. Let us see an example.</p> <p>Suppose you have the following <code>service.xml</code> in a portlet called <code>person-portlet</code>:</p> <pre><code>&lt;service-builder package-path="br.com.seatecnologia.stackoverflow.person"&gt; &lt;author&gt;brandizzi&lt;/author&gt; &lt;namespace&gt;StackOverflowPerson&lt;/namespace&gt; &lt;entity name="Person" local-service="true" remote-service="false"&gt; &lt;column name="personId" type="long" primary="true" /&gt; &lt;column name="name" type="String" /&gt; &lt;column name="age" type="int" /&gt; &lt;/entity&gt; &lt;/service-builder&gt; </code></pre> <p>You generate the services and use it in the original portlet, as usual. For example, you can create a JSP with a form for person registration and person listing:</p> <pre><code>&lt;%@page import="br.com.seatecnologia.stackoverflow.person.service.PersonLocalServiceUtil"%&gt; &lt;%@page import="br.com.seatecnologia.stackoverflow.person.model.Person"%&gt; &lt;%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %&gt; &lt;%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %&gt; &lt;portlet:actionURL name="addPerson" var="url" /&gt; &lt;aui:form action="&lt;%= url %&gt;" name="fm" method="POST"&gt; &lt;aui:fieldset&gt; &lt;aui:input name="name" /&gt; &lt;aui:input name="age" /&gt; &lt;aui:button type="submit" /&gt; &lt;/aui:fieldset&gt; &lt;/aui:form&gt; &lt;ul&gt; &lt;% for (Person person : PersonLocalServiceUtil.getPersons(-1, -1)) { %&gt; &lt;li&gt;&lt;%= person.getName() %&gt; : &lt;%= person.getAge() %&gt;&lt;/li&gt; &lt;% } %&gt; &lt;/ul&gt; </code></pre> <p>Now, suppose you need another portlet, some kind of Hello World which presents a greeting message to all registered persons. You create a new portlet plugin - called, let us say, <code>multiple-hello-portlet</code> - and then copies the file <code>person-portlet-service.jar</code> from the <code>person-portlet/docroot/WEB-INF/lib</code> directory to <code>multiple-hello-portlet/docroot/WEB-INF/lib</code>. <em>If you have both</em> portlets deployed in the same portal_, you can use the services created for <code>person-portlet</code> in the <code>multiple-hello-portlet</code> too. For example, your <code>multiple-hello-portlet</code> can have the following JSP <em>and there is no need of reimplementing services</em>:</p> <pre><code>&lt;%@page import="br.com.seatecnologia.stackoverflow.person.service.PersonLocalServiceUtil"%&gt; &lt;%@page import="br.com.seatecnologia.stackoverflow.person.model.Person"%&gt; &lt;%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %&gt; &lt;% for (Person person : PersonLocalServiceUtil.getPersons(-1, -1)) { %&gt; &lt;div class="portlet-msg-info"&gt; Hello, &lt;%= person.getName() %&gt;! You are &lt;%= person.getAge() %&gt; years old. &lt;/div&gt; &lt;% } %&gt; </code></pre> <p>I created two runnable portlets with these examples, that you can find in <a href="https://bitbucket.org/brandizzi/shared-service-builder-example/src">BitBucket</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload