Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
How do I add a portlet to a layout(page) using Liferay's web services? Ian Gratton February 16, 2010 11:11 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Amos Fong February 16, 2010 4:09 PM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Ian Gratton February 17, 2010 12:40 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Ian Gratton February 17, 2010 4:36 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Ian Gratton February 17, 2010 7:50 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Amos Fong February 17, 2010 10:08 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Ian Gratton February 18, 2010 3:34 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Ian Gratton February 22, 2010 2:22 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Ian Gratton February 22, 2010 8:55 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Ian Gratton February 23, 2010 7:56 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Ian Gratton February 24, 2010 4:52 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Ian Gratton March 8, 2010 8:04 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Massimiliano Assante March 31, 2010 8:55 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Luca Andreatta August 30, 2010 7:33 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Ritabrata Mukherjee October 4, 2013 11:30 AM
RE: How do I add a portlet to a layout(page) using Liferay's web servi Ritabrata Mukherjee October 18, 2013 2:42 AM
Ian Gratton
How do I add a portlet to a layout(page) using Liferay's web services?
February 16, 2010 11:11 AM
Answer

Ian Gratton

Rank: New Member

Posts: 17

Join Date: February 10, 2010

Recent Posts

Hi folks,

I'm very new to Liferay - but I'm figuring it out bit by bit.

I'm currently involved in a project where i need to dynamically create new communities (group) and pages (layout) in response to events ocurring in another system. I'll explain how far I have got with using the web services in case it helps others as some of the web service documentation seems a little sparse.

so far I can:

  • Create the Community (Group)
  • Create the page (layout) and associate it with the Community (group)

So to be able to do the above your client Java application needs to have built Axis web service client stubs to:

  • Portal_GroupService
  • Portal_LayoutService

(Obviously you can use Eclipse's web service client wizard or the Apache Axis WSDL2JAVA tool to generate your client stubs)

This is how you do it:

1. Creating the new Community (Group)

A Community is just a Group - but with a specific type of '2' which denotes it as a community. If you want to create a new Community inside of Liferay using the web services this is the code you would use:

 1
 2GroupServiceSoapService groupSvc = new GroupServiceSoapServiceLocator();
 3GroupServiceSoap groupService = groupSvc.getPortal_GroupService(new URL("http://liferayhost:8080/tunnel-web/axis/Portal_GroupService"));
 4                   
 5// --------------------------------------------------------------------------------
 6// Set up user Credentials
 7// --------------------------------------------------------------------------------
 8
 9((Portal_GroupServiceSoapBindingStub)groupService).setUsername(LIFERAY_USERNAME);
10((Portal_GroupServiceSoapBindingStub)groupService).setPassword(LIFERAY_PASSWORD);
11            
12System.out.println("Calling Portal_GroupService.addGroup()");
13            
14GroupSoap group = groupService.addGroup("MySecureGroup", "This is a restricted Community created via web service calls.", 2, "/MySecureGroup", true, null);
15            
16if(group != null)
17{
18  System.out.println("New Group Id is " + group.getGroupId());
19}

So the parameters to addGroup are as follows:

  • name - the Groups name
  • description - the textual description of the Group
  • type - this is the type of group you are creating (2 denotes a Community)
  • friendlyURL - obviously the URL part that users would use to navigate straight to the community
  • active - true if you want the new group to be activated, false if not
  • ServiceContext - This is an object not a plain type - but I'm not sure what it's used for

When you invoke groupService.addGroup() it returns you a GroupSoap object. This contains all the attributes of the group that was created. To be able to add layouts (pages) to the Community (group) you need to obtain the ID of the group that was created by accessing group.getGroupId() as shown in the above example.

2. Adding a layout (page) to the Community (group)

Obviously from calling groupService.addGroup() we now have a Community (Group) and we know it's Id. The next thing we can do is add a layout (page) into the group. To do this you do the following:

 1
 2LayoutServiceSoapService layoutSvc = new LayoutServiceSoapServiceLocator();
 3LayoutServiceSoap layoutService = layoutSvc.getPortal_LayoutService(new URL("http://liferayhost:8080/tunnel-web/axis/Portal_LayoutService"));
 4
 5// --------------------------------------------------------------------------------
 6// Set up user Credentials
 7// --------------------------------------------------------------------------------
 8
 9((Portal_LayoutServiceSoapBindingStub)layoutService).setUsername(LIFERAY_USERNAME);
10((Portal_LayoutServiceSoapBindingStub)layoutService).setPassword(LIFERAY_PASSWORD);
11            
12System.out.println("Calling Portal_LayoutService.addLayout()");
13            
14LayoutSoap layout = layoutService.addLayout(communityId, true, 0, "TestPage1", "Test Page 1", "This is a test page that was added via a web service call", "portlet", false, "/TestPage1");
15            
16if(layout != null)
17{
18  System.out.println("Layout Id was " + layout.getLayoutId());
19}            }


The parametes to addLayout are as follows:
  • groupId - the Identifer of the Community (Group) this layout is for (obviously obtained from adding the group in the example above)
  • privateLayout - true if this is to be a private page, false if its a page for public access
  • parentLayoutId - if the page is a sub-page of another you would add the id of the parent layout here. If this is a top-level page supply 0.
  • name - the Name of the page
  • title - the HTML title the page will have
  • description - the textual description for the page
  • type - the kind of page we want - in our case we specify 'portlet' because we want to place porlets into the page (see the liferay docs for a list of what types are available)
  • hidden - true if the page should be hidden - false if not
  • FriendlyURL - the friendly URL that will be used to access the page in the context of the community/group (i.e. the friendly URL for the community may be /MyCommunity - the friendly URL for the layout may be /TestPage making the full friendly url /MyCommunity/TestPage

After invoking the webservice the LayoutSoap object will contain all the attributes of your new layout. When you need to interact with the layout you can determine its unique id by referencing layout.getLayoutId().

What I need to do next...

Now obviously using the above code its pretty straight forward to create a new group for my Community - and also very easy to add a new layout to serve as a private page within the community.

The next thing I need to do is use the Liferay web services to add portlets onto the layout. I'm really struggling to see what services you would need to call to perform this operation.

When I look in the liferay database I can see that the Layout.typeSettings column for pages that have been created interactively via the portal contain things like

1
2layout-template-id=1_2_columns_ii
3column-3=58,
4column-2=1_WAR_workflowportlet,29,
5column-1=47,


This is obviously using one of the row/column-based layout templates and placing portlet instances inside of them.

Does anyone know what web services I would need to call to:

  • Create a new portlet instance (say for example a Wiki)
  • Place the newly created portlet instance into my layout and then save it


Any advice you guys may have would be greatly appreciated.
Amos Fong
RE: How do I add a portlet to a layout(page) using Liferay's web servi
February 16, 2010 4:09 PM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1843

Join Date: October 7, 2008

Recent Posts

Hi Ian,

You are very close. You can see UpdateLayoutAction.java for a good example of adding/moving/deleting portlets from a layout.

All you should need to do is:

1LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet)layout.getLayoutType();
2
3layoutTypePortlet.addPortletId(userId, portletId);
Ian Gratton
RE: How do I add a portlet to a layout(page) using Liferay's web servi
February 17, 2010 12:40 AM
Answer

Ian Gratton

Rank: New Member

Posts: 17

Join Date: February 10, 2010

Recent Posts

Thanks Amos,

I'll give that a try when I get into the office shortly.

I guess the Liferay web services expose that method so a similar technique can be used from outside of Liferay instance ?

I'll take a look at the class you suggest and see how things transpose into WS calls from outside of Liferay.

Ian.
Ian Gratton
RE: How do I add a portlet to a layout(page) using Liferay's web servi
February 17, 2010 4:36 AM
Answer

Ian Gratton

Rank: New Member

Posts: 17

Join Date: February 10, 2010

Recent Posts

Hi again Amos,

few more questions for you - hope you don't mind.

Obviously when you look at some of the methods that are exposed via the portal web services (obviously looking at the response from http://portalhost:8080/tunnel-web/secure/axis)I can't see some of the methods you suggest I may need to call.

Do I need to bring some of the jar files that are within the lib/ext directory of the Liferay Portal installation back into my Java client ?

Once of the other questions I have is how to you derive the information that would go into the typeSettings column of the Layout row ?

Initially typeSettings looks like this:

1layout-template-id=2_columns_ii


If I interact with the portal and drag a portlet (in this case the Page Comments portlet) onto my freshly created layout I see the typeSettings change from being empty to:

1layout-template-id=2_columns_ii
2column-2=[b]107[/b]


I am guessing the 107 bit is actually a reference to a portlet instance? I managed to find a reference to it in the PortletPreferences table - the row contains values like:

1plid=11932, portletId=107 preferences=<portlet-preferences/>


plid is obviously the layout id - this matches exactly against my newly created Layout(page) in the Layout table so its easy to work out that association.

For the bits that get bolted into the columns of the layout I have determined serveral things:
  • When only a single instance of a portlet can appear on a page (i.e. the Page Comments portlet) you only see an id. For example the portlet id for page comments appears to be 107
  • When a multiple instances of certain types of portlet are added into the page (e.g. A Web Content Display portlet) you see things like 56_INSTANCE_F1o0 appear in the typeSettings column. I can only imagine that 56 is the kind of portlet (in this case Web Content Layout) and the _INSTANCE_F1o0 is something to uniquely identify that instance of a type 56 portlet.

One thing I can't seem to get my head round is how you would derive these values ? Obviously when you look at the PortletPreferences table you see references to them - so if out page contains 3 Web Content Display portlets and one Page Comments portlet I will find 4 rows in PortletPreferences with have a plid that matches that of my layout - and then the portletids that match what appears in the layout.typeSettings column.

I guess what I am looking for is some other table in the Liferay database that associates these id values (i.e. 107) with the actual portlet type and also defines if multiple instances of them can be created in a single layout. I've not had any luck finding this so could you provide any pointers ?

I am also wondering if some of what I am trying to do is maybe simply not possible via the web services ?

Regards

Ian.
Ian Gratton
RE: How do I add a portlet to a layout(page) using Liferay's web servi
February 17, 2010 7:50 AM
Answer

Ian Gratton

Rank: New Member

Posts: 17

Join Date: February 10, 2010

Recent Posts

Hi Amos,

I think I have maybe answered my own question with regard to portlet ids etc.

I took a look down in webapps/ROOT/WEB-INF/ and came across the following 2 files:

  • liferay-portlet.xml
  • liferay-display.xml

liferay-portlet.xml obviously contains the definitions of all portlets that are in Liferay (be they standard integral portlets or ones that have been installed). The <portlet-name> element contains the portlets id - and this is the value that gets placed into the layout.typeSettings field when you drag a portlet onto the page interactively. If the <instanceable> element is present and contains 'true' it indicates that multiple instances of the portlet can exist in the same context (i.e. a Layout). This explains the difference between a 'Page Comments' portlet which can only have one instance per layout (i.e. the <instanceable> element will not be present) and the 'Web Content Display' portlet which allows you to create multiple instances within the scope of a layout.

the liferay-display.xml file logically groups portlets into categories. This is probably used to build the hierarchy of portlets you see when you use the 'Add Application' functionality within the portal itself.

Does that sound about right ?

Are there any web services you can call from outside of the portal to get a list of available portlets back ? There isn't anything immediately obvious here.
Amos Fong
RE: How do I add a portlet to a layout(page) using Liferay's web servi
February 17, 2010 10:08 AM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1843

Join Date: October 7, 2008

Recent Posts

Ian Gratton:

liferay-portlet.xml obviously contains the definitions of all portlets that are in Liferay (be they standard integral portlets or ones that have been installed). The <portlet-name> element contains the portlets id - and this is the value that gets placed into the layout.typeSettings field when you drag a portlet onto the page interactively. If the <instanceable> element is present and contains 'true' it indicates that multiple instances of the portlet can exist in the same context (i.e. a Layout). This explains the difference between a 'Page Comments' portlet which can only have one instance per layout (i.e. the <instanceable> element will not be present) and the 'Web Content Display' portlet which allows you to create multiple instances within the scope of a layout.


Yup, you answered your own question correctly =)


the liferay-display.xml file logically groups portlets into categories. This is probably used to build the hierarchy of portlets you see when you use the 'Add Application' functionality within the portal itself.


Also correct.


Are there any web services you can call from outside of the portal to get a list of available portlets back ? There isn't anything immediately obvious here.


I don't see any exposed methods that will give the list of portlets. Locally, you would use PortletLocalService.getPortlets().
Ian Gratton
RE: How do I add a portlet to a layout(page) using Liferay's web servi
February 18, 2010 3:34 AM
Answer

Ian Gratton

Rank: New Member

Posts: 17

Join Date: February 10, 2010

Recent Posts

Hi Amos,

thanks for the clarification on that.

I've solved the problem of getting the portlets onto the page now emoticon I figured I'd continue on and document this as I'm sure somebody else could find this useful.

Immediately After I've created the layout I can now do something like (layout is the LayoutSoap object returned from the call to addLayout()):

 1
 2// --------------------------------------------------------------------------------
 3// Build up the typeSettings for the new layout including portlets
 4// --------------------------------------------------------------------------------
 5
 6String typeSettings;
 7                               
 8typeSettings = "layout-template-id=1_2_columns_i\n";
 9typeSettings += "column-1=" + generatePortletInstanceName("56") + ",\n";
10typeSettings += "column-2=107,\n";
11typeSettings += "column-3=" + generatePortletInstanceName("1_WAR_googlemapsportlet") + ",";               
12                               
13layout.setTypeSettings(typeSettings);
14
15// --------------------------------------------------------------------------------
16// Update the layout with the newly defined typeSettings
17// --------------------------------------------------------------------------------
18
19layoutService.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());

Picking the layout type

So when you set the typeSettings value firstly you describe the layout the page can have through layout-template-id. This can be one of the following values based upon the layouts that are available in Liferay (and the names of the layouts are pretty easy to map). I don't believe there is a nice way to obtain these values ? maybe from some sort of layout enumeration (none of the web services expose this - but maybe if you were directly within the portal there is?)

  • 1_column - gives you a single column layout
  • 2_columns_i - gives you two columns split 50/50
  • 2_columns_ii - gives you two columns split 30/70
  • 2_columns_iii - gives you two columns split 70/30
  • 3_columns - gives you three columns
  • 1_2_columns_i - gives you one top initial row, followed by 2 columns split 30/70
  • 1_2_columns_ii - gives you one top initial row, followed by 2 columns split 70/30
  • 1_2_1_columns - gives you one top initial row, followed by a row with 2 columns 50/50 split, followed by another row
  • 2_2_columns - gives you one row with 2 columns 70/30 split followed by another row with 2 columns 30/70 split.
(Note: this obviously does not cover any additional Layout Template Plugins that may have been included into the Portal by the user - these are just the defaults)

How to place a Portlet into one of the columns of the layout

Once you have selected the layout you want its just a case of placing the portlets into the columns. A complete typeSetting value would be specified in the following way:

layout-template-id=<layout-template>
column-<n>=<portlet-id>,[<portlet-id>,]
column-<n>=<portlet-id>,[<portlet-id>,]

where:

<layout-template> is one of the named templates above
<n> - is the column number
<portlet-id> - is a a portlet identifier, be it a single reference to a portlet id for a non-instancable portlet, or <id>_INSTANCE_<unique-value> for a Portlet that can appear multiple times in a layout.

Columns appear to be specified in descending order - the highest column number is the bottom-right of the layout, the lowest column number is the top-left of the layout.

Here is a typeSetting example based upon using the 1_2_columns layout including a Web Content Display, Google Maps and a Page comments portlet

1layout-template-id=1_2_columns_ii
2column-3=107,
3column-2=1_WAR_googlemapsportlet_INSTANCE_X5Ug,
4column-1=56_INSTANCE_ZZZZ,


As none of the web services appear to offer a mechanism for generating portlet instance ids - you'll have to do this yourself. From the testing I've done I thought I could use a UUID - But this seems to cause problems with some of the longer portlet ids (e.g. the google maps portlet above) and the portlet ends up not appearing on the page emoticon

For now I have decided to take the first 4 characters from a generated UUID - obviously this does not guarantee uniqueness - but its a start. A simple method ilke this will do it:

1
2private String generatePortletInstanceName(String portletId)
3{
4   return portletId + "_INSTANCE_" + UUID.randomUUID().toString().substring(0, 4);
5}


Maybe it would be nice if future versions of Liferay web services included a mechanism for doing this.

What About Portlet preferences ?

The Liferay web services do not seem to offer a means of interacting with Portlet preferences when a new portlet instance has been created (Look at Portal_PortletPreferencesService - this is where that functionality should maybe exist?)

Fortunately the first time you visit the new page Liferay creates the appropriate PortletPreferences row in the database. The problem here is what if you want to pre-configure the porlet in some way before anyone makes access to it ?

The next thing I need to understand is how I would be able to interact with the preferences for a given portlets via the web services. For example, if I use a '1_WAR_googlemapsportlet' (The Google Maps Portlet) how am I able to pre-configure this portlet to look at a specific point on the map ? Portlet preferences are obviously just a straightforward JSR <portlet-preferences> XML structure made up of preference names and groups of values like this:

 1<portlet-preferences xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
 2    <preference>
 3        <name>bar</name>
 4        <value>foo</value>
 5        <value>foo2</value>
 6    </preference>
 7    <preference>
 8        <name>foo</name>
 9        <value>bar</value>
10    </preference>
11</portlet-preferences>


so what I need is a get/set mechanism for a Porlet's preferences. Is there anything that will allow me to do this from outside of liferay via web services ?
Ian Gratton
RE: How do I add a portlet to a layout(page) using Liferay's web servi
February 22, 2010 2:22 AM
Answer

Ian Gratton

Rank: New Member

Posts: 17

Join Date: February 10, 2010

Recent Posts

OK,

I think its fairly safe to say after doing more research there are no web service interfaces for getting at Portlet preferences externally from the portal. Because of this I'm going to download the Ext environment for Liferay and attempt to build myself a plugin service that can expose some of its functionality via the tunnel-web web service interface.

I'm thinking once I am running within the context of Liferay itself I'll have access to PortalLocalService which will maybe give me some mechanisms to expose getPortletPreferences() and setPortletPreferences() via my own web service?

portal-service.jar appears to have the following within it:

com.lireray.portal.model.PortletPreferencesSoap

This implies there is already some sort of soap bindings placed upon PortletPreferences - its just maybe they are not made visible by tunnel-web ?

It appears to have getter/setter methods for each of the attributes present in the PortletPreferences table in the database (i.e OwnerId, OwnerType, Plid, PortletId, Preferences)

Anyone else come across this ?
Ian Gratton
RE: How do I add a portlet to a layout(page) using Liferay's web servi
February 22, 2010 8:55 AM
Answer

Ian Gratton

Rank: New Member

Posts: 17

Join Date: February 10, 2010

Recent Posts

After more research it seems the services I need to interact with are based in:

com.liferay.portal.service.PortletPreferencesLocalService

specifically:

  • getPortletPreferences(long plid, java.lang.String portletId) - Obviously in my above examples I know the plid value as I've just created the layout and I know the portletId as I've just generated it. Calling this method would obviously give me back a PortletPreferences bean which gives me getters and setters for all the attributes on the PortletPreferences row from the Liferay database.
  • updatePortletPreferences(PortletPreferences portletPreferences) - obviously once I call getPortletPreferences I can simply call the setPreferences() method to update the <portlet-preferences> XML with specific parameters and values.
(I guess if I am going to the trouble of exposing those methods I may as well expose the rest as its only a bridge method call).

So I guess I'm looking for some pointers for how I can get at this really. None of the formal liferay web services expose them - the closest you can get to anything even closely related to PortletPreferences is the Portal_PortletPreferencesService web service. This service only exposes the method deleteArchivedPreferences. I took a look at the implementation of this and in actual fact PortletPreferencesService actually exposes 3 methods (deleteArchivedPreferences, restoreArchivedPreferences and updateArchivePreferences). The only reason that restoreArchivedPreferences and updateArchivedPreferences do not appear callable is because of the definition down in Liferay's server-config.wsdd. It has no <operation> entries for the other two methods.

So what I'm thinking is I need to use the Ext environment to build myself a custom web service to be exposed via tunnel-web that pretty much maps in all the methods of PortletPreferencesLocalService (These each become <operation> entries under the service I expose).

Once I've done this I guess I need to obtain a reference to PortletPreferencesLocalServiceUtil (PortletPreferencesLocalService is just an interface) so I can simply invoke its methods directly with parameters passed into the web service call and map the outputs back into the returns from the methods.

One of the areas of concern I have here is that the javadoc for PortletPreferencesLocalService it says


This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.


So if I'm making calls via my own web service am I correct in thinking tunnel-web will have already managed the authentication part ?

Does the above sound like I'm going in the right direction ? Has anyone else tried to do this ?
Ian Gratton
RE: How do I add a portlet to a layout(page) using Liferay's web servi
February 23, 2010 7:56 AM
Answer

Ian Gratton

Rank: New Member

Posts: 17

Join Date: February 10, 2010

Recent Posts

OK,

I have ext up and running now after a fair amount of hacking about to make it work. It seems there is lots of out-of-date documentation that points back to older versions of liferay no one single concise guide for 5.2.

I have managed to get the sample reports portlet deployed into my liferay instance and I've also made changes to /ext-impl/build-parent.xml to include a section like this

1<target name="build-wsdd-portlet-reports">
2  <antcall target="build-wsdd">
3    <param name="service.file" value="src/com/ext/portlet/reports/service.xml" />
4  </antcall>
5</target>

so that it makes use of the following files:

  • ext-impl\src\com\ext\portlet\reports\service\http\ReportsEntryService_deploy.wsdd
  • ext-impl\src\com\ext\portlet\reports\service\http\ReportsEntryService_undeploy.wsdd
and merges them with the main tunnel-web/WEB-INF/server-config.wsdd

When I fire up the Liferay instance and access tunnel web I can see that the Axis service Portlet_Reports_ReportsEntryService now appears. Obviously it doesn't expose any methods as the ReportEntryService_deploy.wsdd file doesn't describe any operations.

So am I correct in thinking that if I only need to implement some services (i.e something a user would never interact with) I am forced to build a portlet just so that I can have the service ?

We have purchased the Liferay Portal 5.2 Systems Development paper-based book in the office and it really doesn't say very much about implementing web services (pages 498-499 - very brief indeed - the book is more oriented towards portlets and layout type stuff).

Has anyone managed to implement some a plain web service that is able to expose itself via tunnel-web and interact with com.liferay.portal.service.PortletPreferencesLocalService ?

We are obviously trying to help ourselves as much as possible but I think we are starting to exhaust our own ideas and thoughts about how we can make this work.
Ian Gratton
RE: How do I add a portlet to a layout(page) using Liferay's web servi
February 24, 2010 4:52 AM
Answer

Ian Gratton

Rank: New Member

Posts: 17

Join Date: February 10, 2010

Recent Posts

I've been playing about with the ext environment and I've managed to make the sample ReportService expose some methods via tunnel-web emoticon

So here is what I did:

In a default fresh ext installation com.ext.portlet.reports.service.impl.ReportsEntryServiceImpl does not implement any methods. This is obviously the 'service' part of the portlet and the place where you would place code if you wanted your Porlet (as I mentioned above it seems the only way to have services to is have a portlet - somebody please prove me wrong!) to provide some externally callable functionality.

So I implemented a simple method in ReportsEntryServiceImpl like so

1public String testMethod()
2{
3    return "test";
4}

Then I ran the following ant targets from the ext-impl directory:

1ant build-service-portlet-reports
2ant build-wsdd-portlet-reports

Once I've done this I can look in ext-service/src and see the following changes have taken place (I can only assume that ServiceBuilder is generating this behind the scenes):

The interface com.ext.portlet.reports.service.ReportsEntryService now has a method that looks like:

1public java.lang.String testMethod();

The class com.ext.portlet.reports.service.ReportsEntryServiceUtil now has a method that looks like:

1public static java.lang.String testMethod() {
2    return getService().testMethod();
3}

And importantly ReportsEntryService_deploy.wsdd has updated by ServiceBuilder to include the following operation to match the method I have just created

1
2<operation xmlns:operNS="urn:http.service.reports.portlet.ext.com" xmlns:rtns="http://www.w3.org/2001/XMLSchema" name="testMethod" qname="operNS:testMethod" returnQName="testMethodReturn" returnType="rtns:string" soapAction=""> </operation>

So now I did an ant clean deploy directly from the ext directory to re-deploy the Reports portlet back into my liferay instannce. When I fire up the liferay instance and look at tunnel-web/secure/axis I can now see that the new service appears like so:

1Portlet_Reports_ReportsEntryService (wsdl)
2    * testMethod

This is evidence enough it worked - but I built a simple Axis java client and was able to call the web service without issue.

So may next experiment will be to see what happens when I try and expose some of the functionality from com.liferay.portal.service.PortletPreferencesLocalServiceUtil from a web service method.

I imagine I will run into some WSDL binding problems as some of the beans (i.e PortletPreferences) won't map over correctly. I've seen this before and it will no doubt lead to some xs:any types appearing in the WSDL which is not good.

I'll take a look at this when I get back from lunch. I hope the lengthy nature of my posts (and examples) will prove useful to other forum members in the future.

I still need some guidance from a LifeRay expert with regard to exposing 'services' without having to build a 'portlet'. Can somebody maybe confirm my thoughts on this.

Regards

Ian.
Ian Gratton
RE: How do I add a portlet to a layout(page) using Liferay's web servi
March 8, 2010 8:04 AM
Answer

Ian Gratton

Rank: New Member

Posts: 17

Join Date: February 10, 2010

Recent Posts

Hmmmm...

still very quiet on this thread - being able to interact with an instanceable portlet's preferences seems to me like something people would want to do frequently with liferay automation tasks so I find it quite hard to believe that nobody appears to know how to do this.

For now I think I'm going to switch of hibernate caching in portal-ext.properties and go at the portletPreferences table in the database myself. Its not very SOA-like thats for sure - but it may help me make some progress (I don't like not making progress)

Obviously I have some concern about the sequence numbers that are being generated by hibernate - its configured to not strictly adhere to database dialect so even though we are running against a SQL Server 2005 database it makes no use of IDENTITY columns (I can understand why you don't let hibernate manage this as there are some database platforms that have no ID generation model for hibernate to use under the covers)

Are the liferay/hibernate sequence numbers stored in one of the db tables somewhere ? if not where else are they likely to be ?

Regards

Ian.
Massimiliano Assante
RE: How do I add a portlet to a layout(page) using Liferay's web servi
March 31, 2010 8:55 AM
Answer

Massimiliano Assante

Rank: Junior Member

Posts: 47

Join Date: March 4, 2010

Recent Posts

I cannot answer your questions right now though just wanted to add I've run in the same problem and this thread been extremely useful. I'll clearly report anything could be useful too if I found out something more on this topic.

Massi
Luca Andreatta
RE: How do I add a portlet to a layout(page) using Liferay's web servi
August 30, 2010 7:33 AM
Answer

Luca Andreatta

Rank: Junior Member

Posts: 28

Join Date: February 16, 2009

Recent Posts

Hi Ian,
I was trying to do what, I hope, you have already done: I'm trying to expose the method PortletPreferencesLocalServiceUtil.getPortletPreferences through Web Service.

I moved PortletPreferencesServiceSoap in ext and starting do do some changes, but client side I don't know how to deal to the oject returned from it, could you post some code?

This is the method that I added in PortletPreferencesServiceSoap:
 1
 2    public static PortletPreferencesSoap[] getPortletPreferences(long plid, String portletId) throws RemoteException {
 3        try {
 4            
 5            List<com.liferay.portal.model.PortletPreferences> list = PortletPreferencesLocalServiceUtil.getPortletPreferences(plid, portletId);
 6            return PortletPreferencesSoap.toSoapModels(list);
 7
 8        } catch (Exception e) {
 9            _log.error(e, e);
10            throw new RemoteException(e.getMessage());
11        }
12    }


How can I transform PortletPreferencesSoap client side?
Ritabrata Mukherjee
RE: How do I add a portlet to a layout(page) using Liferay's web servi
October 4, 2013 11:30 AM
Answer

Ritabrata Mukherjee

Rank: Junior Member

Posts: 26

Join Date: March 3, 2009

Recent Posts

Would these work as well in case a user wants to (programatically) add portlets to a his or her customized page (Liferay 6.1) ? Any other API calls required regarding using this in conjunction with Page Customization ?

LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet)layout.getLayoutType();
layoutTypePortlet.addPortletId(userId, portletId);
Ritabrata Mukherjee
RE: How do I add a portlet to a layout(page) using Liferay's web servi
October 18, 2013 2:42 AM
Answer

Ritabrata Mukherjee

Rank: Junior Member

Posts: 26

Join Date: March 3, 2009

Recent Posts

We implemented this feature using the methods present in Layout and LayoutTypePortlet classes from a portlet.

The only issue encountered at this point (using Liferay 6.1.20 EE GA2) was, the above portlet can only update the current layout where it is currently present. It cannot update a remote layout (for example, if the above portlet is in page 2, then it cannot add or remove portlets from page 1). Though the API supports retrieving a remote layout using its friendly URL, Liferay throws a null exception when trying to add a portlet there.

We hope this issue will be solved in 6.2.