liferayliferay-6liferay-themeliferay-velocity

Liferay: Dynamically populate 'select' structure field


I am building a liferay theme, which has two columns side by side. The right column is where the web contents will be displayed.

My implementation aims to build a menu (left column) that gets the titles from the web content titles and builds hierarchy (parent, child) based on a 'select' structure field that I added to each web content.enter image description here

So far I was able to build this system using

Liferay.Service('/journalarticle/get-articles'...)

and some javascript coding.

Now the 'select' fields i use in my structure have predefined hard coded options.enter image description here

How can i populate dynamically this option list so that whoever is managing content will automatically have all titles from all web contents available to choose a 'parent' from?
So far a developer has to update this option list each time there is a new web content added.


Solution

  • @chadct : AFAIK Liferay not provide this default functionality, this is not good practice to populate dynamically value in structure field. But you wanted to achieve that functionality, then there are 4 solution :

    1. Add one text field in structure which contains articleId of your parent web content.
    2. You can add related article for that web content and write some sort of code to get article which consider as a parent of that web content.
    3. Create Select DOM options form template which hold the list of article according to groupId and render on web content view mode, then you can select parent content from there and update content expando with articleId of parent webcontent. Remember this contains AJAX post request. and only show that control who is admin or loggedin user or depends on Role. Refer AJAX post calling
    4. Hook edit_structure.jsp and add your logic here as you want.

    Note : last one is worst but also a solution, Remember you need to modify your current solution.