Foros de discusión

Create Page Programmatically

Nived Rajan, modificado hace 11 años.

Create Page Programmatically

Junior Member Mensajes: 36 Fecha de incorporación: 2/05/12 Mensajes recientes
how to create liferay public page in Programmatically?
thumbnail
Vitaliy Koshelenko, modificado hace 11 años.

RE: Create Page Programmatically

Expert Mensajes: 319 Fecha de incorporación: 25/03/11 Mensajes recientes
Something like this:

    long userId = themeDisplay.getUserId();
    long groupId = themeDisplay.getScopeGroupId();
    ServiceContext serviceContext = new ServiceContext();
    LayoutLocalServiceUtil.addLayout(
            userId,
            groupId,
            false, //not private
            0,     //has no parent layout
            "some_name",
            "some_title",
            "some_description",
            "portlet",   //type
            false,       //not hidden
            "/new-page", //friendly URL
            serviceContext    
    );


..but I have not tested it yet.
thumbnail
Enrique Valdes Lacasa, modificado hace 8 años.

RE: Create Page Programmatically

Junior Member Mensajes: 92 Fecha de incorporación: 29/07/14 Mensajes recientes
Using Liferay Layouts APIs, here is the code that works for me in 6.2:

ServiceContext serviceContext = new ServiceContext();
Layout myPage =  LayoutLocalServiceUtil.addLayout(userId, groupId, false, 
                                        0, "My Page", "Products", "My sample page", 
                                        LayoutConstants.TYPE_PORTLET, false, "/myPage", serviceContext);


userId: user adding the page
groupId: the id of the site
false: specifies it as a public page
LayoutConstants.TYPE_PORTLET: the type of page (in this case, a portlet page)
/myPage: the friendly URL selected for that page
serviceContext: allows us to specify more attributes for the page

Let's say you want to apply a page template for the page you create. Well, the serviceContext allows you to specify the page template (or layout prototype) in an attribute, according to the LayoutLocalServiceUtil.addLayout() documentation, where the method is well described. That would be done like this:

Note how you will need the page template Uuid for that, which is a lengthy String to identify page templates
LayoutPrototype pageTemplate = LayoutPrototypeLocalServiceUtil.getLayoutPrototype(layoutPrototypeId);
String templateUuid = pageTemplate.getUuid();

ServiceContext serviceContext = new ServiceContext();
serviceContext.setAttribute("layoutPrototypeUuid", templateUuid);
serviceContext.setAttribute("layoutPrototypeLinkedEnabled", true);

Layout myPage = LayoutLocalServiceUtil.addLayout(userId, groupId, false, 
                                         0, "My Page", "Products", "My sample page", 
                                         LayoutConstants.TYPE_PORTLET, false, "/myPage", serviceContext);
Sanat D, modificado hace 3 años.

RE: Create Page Programmatically

New Member Mensajes: 17 Fecha de incorporación: 8/09/20 Mensajes recientes
i can create widget page by using above code. but can anyone tell me how can I create a content page by programmatically? should i have change any parameter type of the page and if yes then which type should I can use to create content page?  Please reply.
Thanks in advance.
thumbnail
Mohammed Yasin, modificado hace 3 años.

RE: Create Page Programmatically

Liferay Master Mensajes: 591 Fecha de incorporación: 8/08/14 Mensajes recientes
Hi,
You can use LayoutConstants.TYPE_CONTENT type for creating content page.
thumbnail
Olaf Kock, modificado hace 3 años.

RE: Create Page Programmatically

Liferay Legend Mensajes: 6403 Fecha de incorporación: 23/09/08 Mensajes recientes
Sanat D:

i can create widget page by using above code. but can anyone tell me how can I create a content page by programmatically? should i have change any parameter type of the page and if yes then which type should I can use to create content page?  Please reply.
On top of Mohammed's hint: This portlet might help with figuring out several settings.