Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Gwowen Fu
Liferay Javascript API
March 25, 2013 2:38 PM
Answer

Gwowen Fu

Rank: Expert

Posts: 315

Join Date: December 27, 2010

Recent Posts

Hi,

I was able to use the following code to call my portlet's action, but I need to pass a string array. In my portlet the parameter states becomes one string "'IL', 'CA', 'WA'".

 1   
 2var stateArray = ['IL', 'CA', 'WA'];
 3
 4var resourceURL= Liferay.PortletURL.createResourceURL();
 5resourceURL.setResourceId(methodName);
 6resourceURL.setPortletMode("view");
 7resourceURL.setWindowState("normal");
 8resourceURL.setParameter("states", stateArray);
 9resourceURL.setPortletId("fusion_WAR_learnplugin");


How could this be done?

Thanks!
Gwowen
Hitoshi Ozawa
RE: Liferay Javascript API
March 25, 2013 3:32 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

Can't you just .split() it?
Gwowen Fu
RE: Liferay Javascript API
March 26, 2013 7:04 AM
Answer

Gwowen Fu

Rank: Expert

Posts: 315

Join Date: December 27, 2010

Recent Posts

Hitoshi Ozawa:
Can't you just .split() it?



Yes, I could do that if there is no way for that API to pass an array. Since my portlet handles the same request through jQuery post without any issue, I hope Liferay Javascript API can do the same.

Here is the jQuery post that passes array to my portlet:

 1
 2    $("#refreshTranscript").bind('click', function(event) {
 3        event.preventDefault();
 4        var categoryId = $('#categoryId').val();
 5        var stateArray = [];
 6        var courseIdArray = [59, 60, 61, 62, 10648, 6754, 6753, 10, 1936, 1794, 10392, 11660, 2913, 1541, 1950, 6861, 1869, 1977, 10602, 10159, 10725, 1794, 792, 10603, 10963, 10724, 1295, 10897];
 7   
 8        var posting = $.ajax({
 9          url: '${ refreshTranscript }',
10          type: "POST",
11          data: {'categoryId':categoryId, 'stateArray':stateArray, 'courseIdArray':courseIdArray},
12          dataType: "json",
13          traditional: true
14        });
15       
16        posting.done(function( data ) {
17        });       
18    });
Hitoshi Ozawa
RE: Liferay Javascript API
March 26, 2013 2:32 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

Sorry, I'm only using jQuery for my ajax calls. I don't want to get to dependent of using liferay's functions when it doesn't improve productivity. This is especially true because jQuery is very stable and I'm more sure that they won't change things too much so I'll be able to use it different versions of liferay. Liferay sometimes changes or drops the apis between versions and it'll need to modify the portlets to fit the new version if I used their apis.
Gwowen Fu
RE: Liferay Javascript API
March 29, 2013 12:08 PM
Answer

Gwowen Fu

Rank: Expert

Posts: 315

Join Date: December 27, 2010

Recent Posts

Hitoshi Ozawa:
Sorry, I'm only using jQuery for my ajax calls. I don't want to get to dependent of using liferay's functions when it doesn't improve productivity. This is especially true because jQuery is very stable and I'm more sure that they won't change things too much so I'll be able to use it different versions of liferay. Liferay sometimes changes or drops the apis between versions and it'll need to modify the portlets to fit the new version if I used their apis.


Thanks for you reply. Hope someone has done this before can share the knowledge.