Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
maryam maryam masoudy
define null date and boolean value in velocity
September 17, 2012 3:44 AM
Answer

maryam maryam masoudy

Rank: Regular Member

Posts: 149

Join Date: October 30, 2011

Recent Posts

hi friend
i am beginner . i am writing template (velocity)
i want to use TagsAssetLocalServiceUtil but i can not pass date and Boolean variable in to method
i write this code:

 1
 2[b]#set ($TagsAssetLocalServiceUtil = $serviceLocator.findService("com.liferay.portlet.tags.service.TagsAssetLocalServiceUtil"))[/b]
 3
 4#set ($entryIds = [36919, 36922, 36924, 36921])
 5#set ($entryIds = [36919, 36922, 36924, 36921])
 6#set ($notEntryIds = [])
 7#set ($classNameIds = [10065])
 8[color=#f30837]#set ($date1="" )
 9#set ($date2="" )[/color]
10
11
12[b]$TagsAssetLocalServiceUtil.getAssets(10226, $classNameIds, $entryIds, $notEntryIds, false, "createDate", "", "", "", [color=#c3e806]false, $date1, $date2,[/color] 1, 10)
13[/b]

i want date1 and date2 was null
but i do not know how do i fill date1 and date2 with null and change type to Date???
getAssets:
getAssets(long groupId, long[] classNameIds, long[] entryIds, long[] notEntryIds, boolean andOperator, String orderbyCol1, String orderbyCol2, String orderbyType1, ,String orderbyType2, boolean excludeZeroViewCount, Date publishDate, Date expirationDate, int start, int end)


i use this code in one portlet and i get response without error but i could not change my code to velocity code :
in portlet:
 1
 2
 3   long entryIds[] = {36919, 36922, 36924, 36921};
 4        long notEntryIds[] = {};
 5        long classNameIds[] = {10065};
 6     [color=#f00c3a]   Date date1 = null;
 7        Date date2 = null;[/color]
 8
 9        List<TagsAsset> tagsAssetList = null;
10        try {
11       [b]     tagsAssetList = TagsAssetLocalServiceUtil.getAssets(10226, classNameIds, entryIds, notEntryIds, false, "createDate", "", "", "", false, date1, date2, 1, 10);[/b]
12            System.out.println(":" + tagsAssetList.get(1).getClassPK());
13          ...
14        } catch (SystemException e) {
15            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
16        }
Bart Simpson
RE: define null date and boolean value in velocity
September 17, 2012 3:55 AM
Answer

Bart Simpson

Rank: Liferay Master

Posts: 523

Join Date: August 29, 2011

Recent Posts

Check if you are able to get the velocity service. As you need to get the service using :
1#set ($TagsAssetLocalServiceUtil = $serviceLocator.findService("com.liferay.portlet.tags.service.TagsAssetLocalService"))

in place of
1 #set ($TagsAssetLocalServiceUtil = $serviceLocator.findService("com.liferay.portlet.tags.service.TagsAssetLocalServiceUtil"))

further details on this can be found on http://www.liferay.com/community/wiki/-/wiki/Main/Access+to+Liferay+services+in+Velocity
Also make sure that serviceLocator is not restricted by adding
1journal.template.velocity.restricted.variables=
to portal-ext.properties
Additionally $dateTool is available in velocity to handle date related things.
maryam maryam masoudy
RE: define null date and boolean value in velocity
September 17, 2012 4:08 AM
Answer

maryam maryam masoudy

Rank: Regular Member

Posts: 149

Join Date: October 30, 2011

Recent Posts

thanks Paul
i write mistake here but in liferay i write
#set ($TagsAssetLocalServiceUtil = $serviceLocator.findService("com.liferay.portlet.tags.service.TagsAssetLocalServiceUtil"))
sorry
and i sure make sure that serviceLocator is restricted by adding
because i call
1
2#set ($TagsAssetLocalServiceUtil = $serviceLocator.findService("com.liferay.portlet.tags.service.TagsAssetLocalServiceUtil"))
3#set ($TagsAssetLocalService = $TagsAssetLocalServiceUtil.getTagsAssets(119,125))////////////////// call method with int valude
4////////////////// getTagsAssets(int start,int  end)

but i donot about null date and Boolean variable

Someone was found and helped me thanks a lot Paul
Jordi Joan Gomez Augustin
RE: define null date and boolean value in velocity
December 11, 2012 9:00 AM
Answer

Jordi Joan Gomez Augustin

Rank: New Member

Posts: 19

Join Date: May 18, 2011

Recent Posts

Hi!

Did u find any solution?

i'm in trouble aswell.

Thx!
Mika Koivisto
RE: define null date and boolean value in velocity
December 11, 2012 12:26 PM
Answer

Mika Koivisto

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1501

Join Date: August 7, 2006

Recent Posts

In velocity if something is null it's the same as that variable being undefined and when ever that variable is references it's just printed as string with value of the variable name. It's been a while I've written velocity but if I remember correctly you just pass null as the parameter that you want to have null value.
Jordi Joan Gomez Augustin
RE: define null date and boolean value in velocity
December 12, 2012 2:25 AM
Answer

Jordi Joan Gomez Augustin

Rank: New Member

Posts: 19

Join Date: May 18, 2011

Recent Posts

Hi,

i must have a mistake but i don't know which one,

I'm trying to search some journal articles.

I did it in a portlet

 1String articleId = null;
 2        Double version = null;
 3        String title = null;
 4        String description = null;
 5        String content = null;
 6        String type = "location";
 7        String structureId = null;
 8        String templateId = null;
 9        Date displayDateGT = null;
10        Date displayDateLT = null;
11        int status = WorkflowConstants.STATUS_APPROVED;
12        Date reviewDate = null;
13        boolean andOperator = true;
14        int start = 0;
15        int end = 1;
16
17        OrderByComparator obc = null;
18
19
20        List<JournalArticle> articlesPrueba = JournalArticleLocalServiceUtil.search(
21            themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(), 0, articleId, version, title, description,
22            content, type, structureId, templateId, displayDateGT,
23            displayDateLT, status, reviewDate, andOperator, start, end, obc);
24


I get 1 object.

I transate it to velocity but i don't retrieve anything, it only prints the variable's name
(i already set my portal-ext.properties with journal.template.velocity.restricted.variables= and i use the servicelocator in other methods and it works)

Here's my code in velocity

1#set($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
2#set($company = $getterUtil.getLong($companyId))
3#set($group = $getterUtil.getLong($groupId))
4#set($type = "location")
5
6#set($journalArticlesList = $journalArticleLocalService.search($company, $group, 0, null, null, null, null, null, $type, null, null, null, null, 0, null, $getterUtil.getBoolean("true"), 0, 1, null))
7
8journalListsize: $journalArticlesList.size()<br>


Could you help me?

Thx!