How to pass formInstanceId parameter into embed web form portlet?

Elena Stefanova, modified 6 Years ago. Junior Member Posts: 42 Join Date: 8/24/15 Recent Posts
Hi there!

Currently I'm using Liferay Portal CE 7.1 GA2 for my new project and I need to embed the web form portlet with preselected formInstanceId passed as a configurational parameter.  I need to do this into a web content template. Do you think that it is possible?

I tried something like that:
<#assign preferencesMap = { "formInstanceId": "333" } />
<@liferay_portlet["runtime"]
         portletName="com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet"    
         defaultPreferences=freeMarkerPortletPreferences.getPreferences(preferencesMap)
         instanceId="123"
 />       
but unfortunately the desired form is not loaded inside the embed portlet.

Any help or advice will be much appreciated!

Thanks in advance,

Eli
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Eli,
Yes,  it should be possible.  I have a few questions --1. Do you get an error at all when you try this?2. Have you checked to make sure that this is in fact the preference key?3. Are there maybe any other preferences that you need to add as well?Normally when I need to do something like this I start by dropping the runtime in with no auto configuration. I then configure it manually on the page. At that point, when I see that it is rendering properly, I go to the database and look up the preferences XML string in the PortletPreferences table and go back to the template and build the preferences map. Remember though, embedded preferences are not updated automatically when you make changes to them later. You need to remove delete the preferences for that item from the DB to have them reset (and don't forget to clear the DB cache before you reinitialize the portlet by reloading the page)
Elena Stefanova, modified 6 Years ago. Junior Member Posts: 42 Join Date: 8/24/15 Recent Posts
Hi Andrew and thanks for the fast reply!Your post  made me recheck and fix my code. And yes, formInstanceId is a default portlet preference indeed. I want an auto configuration of the embed web form because like that it will be more efficient for the site editors to manage one specific type of web articles that I'm currently implementing . However, it seems that the code above does not set formInstanceId in a proper way. So I changed it with this working one  ( of course resetting portlet preferences for each instance as you reminded me ).

<#assign VOID = freeMarkerPortletPreferences.setValue("formInstanceId", "333") />
<@liferay_portlet["runtime"]
      portletName="com_liferay_dynamic_data_mapping_form_web_portlet_DDMFormPortlet"    
      defaultPreferences="${freeMarkerPortletPreferences}"
      instanceId="${.vars['reserved-article-id'].data}"
/>
<#assign VOID = freeMarkerPortletPreferences.reset() />
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Elena,Very interesting -- I am curious, if you have a minute to try it, try using your original solution, but putting the map inline in the defaultPreferences attribute. I use that approach often and it has always worked for me.
Elena Stefanova, modified 6 Years ago. Junior Member Posts: 42 Join Date: 8/24/15 Recent Posts
Hi, Andrew!I tested your solution and it is working  too. Thank you!Greetings