Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Luca kk
Create new page
August 11, 2011 1:37 AM
Answer

Luca kk

Rank: Regular Member

Posts: 242

Join Date: December 7, 2010

Recent Posts

Hi all,
is it possible to create a new page, as a dynamic page,
from java class of a portlet liferay, and not from the liferay
administartion panel?
Thanks,
Luca
KK rajput
RE: Create new page
August 11, 2011 3:13 AM
Answer

KK rajput

Rank: Expert

Posts: 266

Join Date: April 10, 2008

Recent Posts

Below is the code to add layout :
ServiceContext serviceContext = new ServiceContext();

Layout layout = LayoutLocalServiceUtil.addLayout([$user_Id$],[$group_Id$],[$is_private_layout$],
[$parent_layout_id$], "[$title$]", "[$description$]", "[$layout_type$]", "[$is_hidden$]",
"[$friendly_url$]", serviceContext);

LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());

text within [$$] is variable.

HTH
Luca kk
RE: Create new page
August 11, 2011 4:02 AM
Answer

Luca kk

Rank: Regular Member

Posts: 242

Join Date: December 7, 2010

Recent Posts

Hi kk rajput,
thanks for response.
How can I get "group_Id", "parent_layout_id", "layout_type" and "friendly_url"?
Luca
Sagar A Vyas
RE: Create new page
August 11, 2011 4:27 AM
Answer

Sagar A Vyas

Rank: Liferay Master

Posts: 655

Join Date: April 17, 2009

Recent Posts

Luca kk:
Hi kk rajput,
thanks for response.
How can I get "group_Id", "parent_layout_id", "layout_type" and "friendly_url"?
Luca


group_Id = themeDisplay.getScopeGroupId()
parent_layout_id = themeDisplay.getLayout().getParentLayoutId()
friendly_url = /anyuniquekeyword

Thanks,
Sagar Vyas
Luca kk
RE: Create new page
August 11, 2011 6:25 AM
Answer

Luca kk

Rank: Regular Member

Posts: 242

Join Date: December 7, 2010

Recent Posts

Hi Sagar,
Thanks for reply.
In the method:

1public static Layout addLayout(long userId, long groupId, boolean privateLayout, long parentLayoutId, String name, String title, String description, String type, boolean hidden, String friendlyURL, ServiceContext serviceContext)


userId is a "long" type but the method:

1String userId = request.getRemoteUser();


returns a String!
Do you know how to get "userId"?

Luca
Sagar A Vyas
RE: Create new page
August 11, 2011 11:44 AM
Answer

Sagar A Vyas

Rank: Liferay Master

Posts: 655

Join Date: April 17, 2009

Recent Posts

Hi Luca,

You have tow choice here.

1st) You can directly get user from themeDisplay.getUser().
2nd) You can parse this string into Long and just pase like
Long.parseLong(str);

Thanks,
Sagar Vyas
Luca kk
RE: Create new page
August 12, 2011 2:51 AM
Answer

Luca kk

Rank: Regular Member

Posts: 242

Join Date: December 7, 2010

Recent Posts

Hi Sagar,
thanks for support.
In "DoView" method I try as:

 1ServiceContext serviceContext = new ServiceContext();
 2ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
 3long userId = Long.valueOf(request.getRemoteUser());
 4long groupId = themeDisplay.getScopeGroupId();
 5long parentLayoutId = themeDisplay.getLayout().getParentLayoutId();
 6try {
 7       [b]Layout layout = LayoutLocalServiceUtil.addLayout(userId, groupId, true, parentLayoutId, "Test", "Test", "Test", "Test", true, "/test", serviceContext);[/b]
 8       LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
 9       LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
10      }
11     catch (PortalException ex) {
12             Logger.getLogger(LiferayPortletThree.class.getName()).log(Level.SEVERE, null, ex);
13     } catch (SystemException ex) {
14             Logger.getLogger(LiferayPortletThree.class.getName()).log(Level.SEVERE, null, ex);
15    }
16
17response.setContentType("text/html");
18PortletRequestDispatcher dispatcher =
19[b]getPortletContext().getRequestDispatcher("/WEB-INF/jsp/LiferayPortletThree_view.jsp");[/b]
20dispatcher.include(request, response);


How can I redirect to the page layout created?
Luca