Liferay – Recipes Portlet Design

This is some approach base on personal experiences, whenever you design a custom portlet which contain the configuration will store into a custom table. Remember add the following scripts and table columns to avoid the dirty data.


If you have experience to develop a custom portlet, you must notice there are some “data redundancy”. What i mean data redundancy is base on scenario as describe in below:

1) You have a portlet, when you drag and drop into a page. By default it will auto generate a Id in table portletpreferences with random number. Example: Id=12345
2) Start adding record into this porlet.
3) Next, deleted this portlet.
4) Repeat step 2, now you got a new portlet Id=56789
5) Finally in the same page you have an unused portlet and you will never able to removed it. Unless you remove it from portletpreferences table.

You can avoid the above mention with the following portlet sql design.

Solution

During the design, you can include these 2 fields in your sql
1) `portletPreferencesId` bigint(20) NOT NULL,
2) `plid` bigint(20) NOT NULL,

Alter existing SQL scripts

  1.  
  2. ALTER TABLE example
  3. add CONSTRAINT fk_portletpreferences_id
  4. FOREIGN KEY (portletPreferencesId) REFERENCES
  5. portletpreferences(portletPreferencesId) ON DELETE CASCADE
  6. ON UPDATE NO ACTION;
  7.  

Conclusion

So, whenever you repeat the step mention on above, and once you have delete/remove any portlet it will also remove the redundancy record from portletpreferences table.

You can leave a response, or trackback from your own site.

Leave a Reply

Security Code: