Using Service Trackers on a JSF portletUsing Service Trackers on a JSF portlethttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1213765312024-03-29T09:31:22Z2024-03-29T09:31:22ZRE: Using Service Trackers on a JSF portlettxapeldot .https://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1213772422022-03-11T16:08:53Z2022-03-11T16:07:58Z<p>Yes, I did. It was due to the fact that on a postgreSQL database (at
least the version I'm working with) it's not allowed to use uppercase
characters to set column names. Instead of 'numProjects' column name,
I changed it to 'numprojects', and then, I changed the content of
service.xml to:</p>
<p><column name="numProjects" type="long"
db-name="numprojects" /></p>
<p>After changing it, and rebuilding Service Builder, it worked as expected.</p>
<p>Silly mistake; that's why I prefered deleting the post.</p>
<p>Thanks.</p>txapeldot .2022-03-11T16:07:58ZRE: RE: Using Service Trackers on a JSF portletRussell Bohlhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1213770672022-03-11T14:49:12Z2022-03-11T14:49:11Z<p>Did you solve the other problem? I'm curious what was wrong because
it wasn't obvious from your service.xml or the service calls you were making.</p>Russell Bohl2022-03-11T14:49:11ZRE: Using Service Trackers on a JSF portlettxapeldot .https://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1213771972022-03-11T14:30:03Z2022-03-11T14:30:03Z<p>Thanks for your reply, Russel.</p>
<p>I've managed to get rid of that 'null' value when calling the
'.getService()' method. Your code is also perfectly valid too.</p>
<p>Thanks.</p>txapeldot .2022-03-11T14:30:03ZRE: Using Service Trackers on a JSF portletRussell Bohlhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1213765932022-03-10T16:22:37Z2022-03-10T16:22:37Z<p>Good catch: I think there was a change made <a
href="https://issues.liferay.com/browse/LPS-124713">here</a> (removing
Service Tracking form the ServiceUtil classes). That said, you should
still be able to track the LocalService services in your code. For
example, this works from the Server Administration > Script console
in my 7.4 U9 portal (but I don't know JSF):</p>
<pre>
<code class="language-java">import com.liferay.journal.model.JournalArticle;
import com.liferay.journal.service.JournalArticleLocalService;
import com.liferay.portal.scripting.groovy.internal.GroovyExecutor;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.osgi.util.tracker.ServiceTracker;
ServiceTracker<JournalArticleLocalService, JournalArticleLocalService> st;
Bundle bundle = FrameworkUtil.getBundle(GroovyExecutor.class);
st = new ServiceTracker(bundle.getBundleContext(), JournalArticleLocalService.class, null);
st.open();
JournalArticleLocalService jaService = st.waitForService(500);
if (jaService == null) {
out.println("The required service 'JournalArticleLocalService' is not available.");
}
else {
java.util.List<JournalArticle>articles = jaService.getArticles();
if (articles != null) {
out.println("Article count: " + articles.size());
} else {
out.println("no articles");
}
}
if (st != null) {
out.println("closing st")
st.close();
}</code></pre>
<p> </p>Russell Bohl2022-03-10T16:22:37ZUsing Service Trackers on a JSF portlettxapeldot .https://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1213765302022-03-10T15:47:31Z2022-03-10T15:47:29Z<p>From a non-bean class lying on a JSF portlet, I'm trying to invoke a
service defined in a Service Builder-created module. What I've read on
the official documentation (Liferay 7.2) is that this task can be
accomplished by using Service Trackers.</p>
<p>The thing is that on a Liferay 7.4 Service Builder generated module,
the '_serviceTracker' property has not been created within the
[Foo]LocalServiceUtil service class, once the 'build service' gradle
task has finished. As a consecuence, when from a non-bean class, which
defines a [Foo]LocalServiceTracker class, lying on a JSF portlet, I
call the method '.getService()', it is always returning a 'null' value.</p>
<p>All I've read about invoking Service Builder based services is
intended for the Liferay 7.2 rele