Posts

Registering custom objects for WebContent Templates with TemplateContextContributor

Registering custom objects for WebContent Templates with TemplateContextContributor Sometimes you may need additional data to be available in the web content template. TemplateContextContributor  can help in this case: Create class, that implements  com.liferay.portal.kernel.template.TemplateContextContributor . Add  @Component  annotation to rigister it as OSGi-component. Override  com.lif.app.display.contributor.AppDisplayContributor.prepare(Map<String, Object> contextObjects, HttpServletRequest request)  method and put required object into  contextObjects  map. Deploy module with template context contributor. Use registered context in FTL template for web content. Example: @Component ( immediate = true , property = "type=" + TemplateContextContributor. TYPE_GLOBAL , service = TemplateContextContributor. class ) public class AppDisplayContributor implements TemplateContextContributor { private ...

Personalized Experience for Asset Publisher with Content Sets

Image
Personalized Experience for Asset Publisher with Content Sets Introduction This tutorial explains how to create personalized experience for users with Asset Publisher portlet and Content Sets. We'll create demo categorized Web Content, Users and UserGroups, Segments for each UserGroup, and ContentSet with Variations for each Segment. For demo purposes we'll use the following categories: "Sports", "Cars", "Dogs" and "Cats". Configuration 1 - Create a Site Create new site "Personalization-Demo". Add public page "Personalized-News". 2 - Create Categories Inside created site add vocabulary "News"; Add the categories to "News" vocabulary: "Sports", "Cars", "Dogs", "Cats": 3 - Create Sample Content Create sample Web Content articles, and associate them with categories: (add article for each category) 4 - Create UserGroups ...

Custom Fields management with ExpandoBridge

Custom Fields management with ExpandoBridge Sometimes you may need to work with custom fields from Java code (for example, to set so read custom field).   ExpandoBridge   should help you in this case. Each model with custom fields support has   public ExpandoBridge getExpandoBridge();   method inherited from   com.liferay.portal.kernel.model.ClassedModel . With the ExpandoBridge you may: create custom field:   public void addAttribute(String name) throws PortalException; set custom fields value:   public void setAttribute(String name, Serializable value); read custom field value:   public Serializable getAttribute(String name); . This utility class encapsulates custom fields management logic: public class ExpandoHelper { private static final boolean SECURED = false ; public static void setCustomField(ClassedModel model, String fieldName, int fieldType, Serializable fieldValue) { try { if (!model.getExpa...

Liferay 7.2 - MySQL connection

Image
Liferay 7.2 - MySQL connection To connect Liferay to MySQL DB - add the following lines to   portal-setup-wizard.properties   file: jdbc.default.driverClassName=com.mysql.cj.jdbc.Driver jdbc.default.url=jdbc:mysql://localhost:3306/my_liferay_db?serverTimezone=Europe/Istanbul&useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false jdbc.default.username=root jdbc.default.password=my_root_password Replace   my_liferay_db   with your database name and   my_root_password   with your root's MySQL password. Hints Use   com.mysql.cj.jdbc.Driver   MySQL driver, as old one will not work 7.2; serverTimezone   parameter should be specified (as in sample above); you may use the same connection string for MySQL connection in IntelliJ IDEA:  

AUI Liferay Popup Example

AUI Liferay Popup Example Here is sample code, which shows popup window on click: AUI().ready('aui-base', function(A){ A.one('#my-btn-selector').on('click', function() { Liferay.Util.openWindow( { dialog: { //cssClass: 'aui-popup-example', destroyOnHide: true, height: 600, width: 800 }, dialogIframe: { //bodyCssClass: 'custom-css-class' }, title: 'My Popup Title', uri: '' } ); } ); }); Enjoy  😏

Liferay Keycloak integration

Image
Liferay Keycloak integration using OpenID Overview This tutorial explains how to configure OpenID SSO between Liferay 7.2 and Keycloak 7.0.1 Installation instructions KeyCloak Configuration 1. Install and startup Keycloak server Download latest Keycloak server:  https://www.keycloak.org/downloads.html Unzip keycloak-7.0.1.zip folder. Run  keycloak-7.0.1/bin/standalone.sh  (or  keycloak-7.0.1/bin/standalone.bat ) file. Keycloak should be started on 8080 port:  http://localhost:8080 2. Create default admin user: and sign in to Admin Console. 3. Check OpenID configuration Click on "OpenID Endpoint Configuration": JSON configuration should appear, like this: { "issuer": "http://localhost:8080/auth/realms/master", "authorization_endpoint": "http://localhost:8080/auth/realms/master/protocol/openid-connect/auth", "token_endpoint": "http://localhost:8080/auth/realms/master/protocol/openid-con...

Fix Gradle workspace for OSGi configuration modules

If you are using Gradle workspace for Liferay 7.2 and developing a module with OSGi configuration, for example: @ExtendedObjectClassDefinition ( category = ConfigurationKeys. CATEGORY_KEY , scope = ExtendedObjectClassDefinition .Scope. COMPANY ) @Meta.OCD ( id = ConfigurationKeys. REST_CONFIGURATION , localization = "content/Language" , name = "rest-configuration" ) public interface RestConfiguration {     @Meta.AD ( deflt = "https://lifedev.com/api/v1" , name = "rest-endpoint" )     public String restEndpoint();     @Meta.AD ( deflt = "0 * * ? * *" , name = "cronjob-expression" )     public String cronjobExpression(); } , you may notice that your configuration does not appear in Control Panel, even if code/configuration seems to be correct. The issue may be related to gradle plugins workspace version. Check "com.liferay.gradle.plugins.workspace" property in settin gs. gradle file....

Include JQuery plugin into theme

To include jQuery plugin to a theme the following “magic trick” is required (here is an example for OwlCarousel): < script >    Liferay .Loader. define . _amd = Liferay .Loader. define . amd ;    Liferay .Loader. define . amd = false ; </ script > < script type ="text/javascript" src =" ${ javascript_folder } /owl-carousel/owl.carousel.js"  /> < script >    Liferay .Loader. define . amd = Liferay .Loader. define . _amd ; </ script > (add this code in ‘head’ section of portal_normal.ftl file) After this you can you your jQuery plugin in theme. For this example: var $slider = $( '#slider' ); $slider . owlCarousel ({     items : 1 ,     loop : true ,     margin : 10 ,     autoplay : true ,     autoplayTimeout : 3000 ,     autoplayHoverPause : true ,     pagination : true }); ...