- Created workspace
- Created service builder and added entity
- Created DemoPortlet
- I'am trying to get data from DB and system.out in doView method in DemoPortlet.
- When i use CountryLocalServiceUtil (CountryLocalServiceUtil.getCountriesCount()) - ERROR [http-bio-8080-exec-10][render_portlet_jsp:132] null
I read that I can use CountryLocalService, @Reference etc.? Is this code ok? I can see that my portlet is Active, but it is not showing in Sample widget. Can you provide code, hot to call getCountriesCount() using CountryLocalService?
@Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=category.sample",
"com.liferay.portlet.instanceable=true",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.name=" + DemoPortletKeys.Demo,
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class
)
public class DemoPortlet extends MVCPortlet {
private CountryLocalService countryLocalService;
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
throws IOException, PortletException {
// TODO Auto-generated method stub
System.out.println("********" + getCountryLocalService().getCountriesCount() + " ********************");
super.doView(renderRequest, renderResponse);
}
public CountryLocalService getCountryLocalService() {
return countryLocalService;
}
@Reference(unbind = "-")
public void setCountryLocalService(CountryLocalService countryLocalService) {
this.countryLocalService = countryLocalService;
}
}
<% CountryLocalService countryLocalService = (CountryLocalService) renderRequest.getAttribute("CountryLocalService"); %>
– user2974612 Aug 29 '18 at 09:48