Dynamic Data Lists III

Hey all, this is the third post about Dynamic Data Lists ant it's focused on how to write the Lists Templates mentioned on the previous post.

As already said, List Templates provides all the flexibility needed to build your own UI. Within the templates context you will have access to all records and fields of these records for the configured list.
 
We're going to demonstrate this by creating a simple user registation list and then we'll diplay it diffrently using a velocity template.
 
First thing to do is to instantiate the Dynamic Data List Display portlet and create a new list. The definition of this list will have two fields: name (text field) and avatar (file upload field)  (Figure 1).
 
Figure 1 - List creation
 
After that we're ready to populate the list. Figure 2 shows the records added.
 
Figure 2 - User Registration records
 
Finally, in order to create templates click on the "Add List Template" icon (red mark in Figure 2). Then a pop-up will show up and you can either upload the template file or write one using the code editor. Here's the template used for this example:

And here's the end result:

Blogs
Can you do a blog post how you can expose a Dynamic DataList from webcontent velocity template?
wow its working in Liferay 6.1 GA very fine .. Marcellus give some information with velocity template ...
Navin,

I created a new dynamic data list and one detail template and list template also.
When I go to configration section in the portlet to select newly created detail template and list template, I found that list template is not listed there to choose from whereas detail template is there and upon selection its also working fine.

any suggestions would be helpful..
Hi Harish, this issue will be fixed in LPS-25059. Thanks.
I built ddm, ddl and template as Marcellus suggested and I called template1 the list template.
I added a Dynamic Data List Display portlet in My public pages and all works fine.

I created from DDL display portlet a new template just like template1 but without the raw
<img height="100" src='/documents/ddm/${className}/${classPK}/${fileName}' width="100" />
to show the list without images, and I saved it as template2.
I selected template2 but the behaviour of portlet doesn't change.
I can select default template with no problem but if I select template1 or template2 I get the same data visualization with images.

HORRIBLE WORKAROUND
1. In DDL portlet I selected template2 which didn't work
2. shutdown tomcat
3. startup tomcat
DDL portlet now show correct data list without images
If I select template1 or template2 I got the same data visualization without images

The same behaviour if, rather than use another template, remove the images code row from template1.

What have I to do?
Hey Nicola, what version are you running?
Hi,
does anynone know how populate a list of records from an SQL database.
Is it possible to reference methods defined in a Java class thanks to Velocity template ?
Thanks for ur help.
Hey Damien, you can populate your records through the DDL API. DDLRecordSetService allows you to create lists and the DDLRecordService is to be used to create the list records.

Yes. It is. You should only set the classes you want to be visible within the velocity context. Take a look VelocityVariablesImpl.java
Hi Marcellus
sorry for late reply
I've just updated trunk and the problem persist

Nicola
Hi Marcellus,

It's a nice blog, learned a lot.

But when i tried to create list template.

<b>It gives this error -</b>


An error occurred while processing the template.

Invocation of method 'createJSONObject' in class com.liferay.portal.json.JSONFactoryImpl threw exception com.liferay.portal.kernel.json.JSONException: java.lang.NullPointerException at 20null[line 25, column 48]

1## Get the reference of DDL Record Service via serviceLocator, which is automatically set in the context

2

3#set ($ddlRecordService = $serviceLocator.findService('com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService'))

4

5## $reserved_record_set_id is also an object set in the context and it has the value of the list id configured for the portlet instance

6

7#set ($recordSetId = $getterUtil.getInteger($reserved_record_set_id.data, 0))

8

9## call to the retrieve all records of the list

10

11#set ($records = $ddlRecordService.getRecords($recordSetId))

12

13#foreach($record in $records)

14 ## each record has a collection of fields (name and avatar in our case)

15

16 #set ($fields = $record.getFields())

17

18 #set ($nameField = $fields.get("name"))

19

20 #set ($avatarField = $fields.get("avatar"))

21

22 ## the avatar is a file upload field and its value holds a JSON object

23 ## jsonFactoryUtil help us to convert string value into a JSON object

24

25 #set ($avatarJSONObject = $jsonFactoryUtil.createJSONObject($avatarField.value))

26

27 #set ($fileName = $avatarField.getName())

28 #set ($className = $avatarJSONObject.getString("className"))

29 #set ($classPK = $avatarJSONObject.getString("classPK"))

30

31 <div style="padding-top: 10px;">

32 <img height="100" src='/documents/ddm/${className}/${classPK}/${fileName}' width="100" />

33

34 <span style="padding-left: 5px;">

35 $nameField.getValue()

36 <span>

37 </div>

38#end

Please let me know, if there is any work around.
Thanks,
Vipin Bardia
#set ($portalBeanLocator = $portal.getClass().forName('com.liferay.portal.kernel.bean.PortalBeanLocatorUtil'))
#set ($jsonFactoryUtil = $portalBeanLocator.locate('com.liferay.portal.kernel.json.JSONFactoryUtil'))
Thanks Marcellus. Great work!

I was trying to find out how to combine the use of List template as you explained above with drill down to detail view/edit. In other words, I would like to display content in a custom manner and at the same time be able to perform actions on the displayed records. Secondly, is there a way to make some fields non-editable?

Kindly advice? Thank you in advance.
Hi Marcellus,

Could you show me how to link to record details view in your list template?

Thanks

Danny
hi guys,
i created dynamic data list exactly as shown image is not displaying
other data is displaying how to resolve it plz help i am new to liferay
I've managed it to get it to work with the following code. It seems that with at least 6.1 the JSON names are changed. I've printed out the value of the imagefield and the fields are recordId, name, path.

#set ($titleImageField = $record.getField("titleimage"))
#set ($titleImageValue = $titleImageField.getValue())

#set ($imageJSONObject = $jsonFactoryUtil.createJSONObject($titleImageField.value))

#set ($imageFieldName = $titleImageField.getName())
#set ($imageRecordId = $imageJSONObject.getString("recordId"))

<img src='/documents/ddl/${imageRecordId}/${imageFieldName}' width="100" />

Very annoying is a bug, which requires a restart after changing the template, else you will see the result of the previous template definition. So make sure to have a working template before deploying it into a production environment, to minimize downtime of your production server.
If is use the same velocity code, how could I show a same list on another page?
I need to show the same information but in different page.

And how to add the default row of "Actions"
Thanks
I know it was asked above (Danny Jiang) - but no-one answered.

How do you link (create the link in the VM of the List Template) a record on a List Template to open the record using a specific Detail Template - very similar to Asset Publisher does with Table option?

Thanks.
Thanks for interesting post, it's very useful.
Could someone please tell me where is the DDL data located? I'm talking about uploaded files and "documents and media" objects.
Is it in DB or somewhere in filesystem?
And yes, how can I render standard "actions" button in my custom list?
Can anyone please explain me what is the advantage of this List Templates?

I ask this because on one hand we can customize the presentation, but on the other hand, the capability of performing actions over the records is lost...It must be....otherwise there would be an answer not only to me in the forum (http://www.liferay.com/community/forums/-/message_boards/message/15599617) but also to the other three people that have asked this same question in this very same comment list.
Hi,

Try this solution: http://webapplicationdeveloper.blogspot.be/2012/10/liferay-dynamic-data-lists-record.html for displaying the record actions.
Stijn,

Thanks for posting this. It was very useful - but it looks like the URL to your post may have changed: http://webapplicationdeveloper.blogspot.be/2012/10/liferay-dynamic-data-list-detail.html was where I found it. Thanks!
Hi Ben,

I actually made 2 posts:

http://webapplicationdeveloper.blogspot.be/2012/10/liferay-dynamic-data-list-detail.html for going to a detail page

and

http://webapplicationdeveloper.blogspot.be/2012/10/liferay-dynamic-data-lists-record.html to dosplay the actions on a record.
Hi Marcellus

In the following line:
#set ($recordSetId = $getterUtil.getInteger($reserved_record_set_id.data, 0))

I removed the ".data" to work in Liferay 6.2.10 EE
Nice article!
is it possible to filter records (using DDLRecordLocalService.getRecords or something) ?
Hi Marcelus!
Nice explanation emoticon

It is possible to get the portlet id where the dynamic list is shown with velocity?

Many thanks for your work and explanations!
emoticon why ? using code in vesion 6.2 CE not working.

help me
On LR6.2GA4

#set ($DDLRecordLocalService = $serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService"))

#set ($recordSetId = $getterUtil.getLong($reserved_record_set_id))
#set ($records = ${DDLRecordLocalService.getRecords($recordSetId)})

#if (!$records.isEmpty())
#foreach ($cur_record in $records)
$cur_record.getFieldValue("myFieldValue", $locale)
#end
#end