Building the Web Front-End
Step 4 of 11
To use your Service Builder-generated back-end in your front-end, you must tell your front-end project that the back-end exists and where to find it.
For the web module to access the generated services, you must make it aware of the API and service modules:
-
Open
guestbook-web
’sbuild.gradle
file and add these dependencies:compileOnly project(":modules:guestbook:guestbook-api") compileOnly project(":modules:guestbook:guestbook-service")
-
Save the file. Right-click on the
guestbook-web
project and select Gradle → Refresh Gradle Project. -
Now you must add references to the Service Builder services you need. To do this, add them as class variables with
@Reference
annotations on their setter methods. OpenGuestbookPortlet
and add these references to the bottom of the file:@Reference private GuestbookEntryLocalService _guestbookEntryLocalService; @Reference private GuestbookLocalService _guestbookLocalService;
Note that it’s Liferay’s code style to add class variables this way. The
@Reference
annotation causes Liferay’s OSGi container to inject references to your generated services so you can use them. -
Press Ctrl-Shift-O to add the import you need:
org.osgi.service.component.annotations.Reference
Now you’re ready to begin building your front-end.