Chapter 6. Page
6.1. Retrieving Pages
A specific page can be retrieved by its
PageId . The PageId is constructed by passing either the name for a standard site, the group for a group space or the user for a user dashboard, and the name of the page. Alternatively it can be constructed by passing the SiteId and name of the page.
Example 6.1. Retrieving Specific Pages
This example shows how to retrieve specific pages of a portal.
Page standardSitePage = portal.getPage("classic", "home");
Page groupSpacePage = portal.getSite(new Group("platform", "administrators"), "grouppage");
Page userDashboardPage = portal.getSite(new User("john", "johnspage"));
It is also possible to query for pages using the
PageQuery . The PageQuery supports filtering, sorting and pagination when querying for pages.
Example 6.2. Retrieve Pages Using Filtering, Sorting, and Pagination
This example finds pages with a display name that starts with
"A".
PageQuery.Builder qb = new PageQuery.Builder(); qb.withSiteType(SiteType.SITE).withFilter(new Filter<Page>() { public boolean accept(Page page) { return page.getDisplayName().startsWith("A"); } }); List<Page> pages = portal.findPages(qb.build());
6.2. Creating a Page
Creating a page uses the following workflow:
- Create a new page through the
Portal. - Set the configuration for the page (such as localized display names).
- Save it using
Portal.
Example 6.3. Create a Page
This example creates a new page in the classic site with the name mypage and a non-localized display name.
The page is not visible (or persisted) until
portal.savePage is invoked.
Page page = portal.createPage(new PageId("classic", "mypage")); page.setDisplayName("My Page"); portal.savePage(page);
6.2.1. Setting Permissions for a Page
Associated with a page is an access permission and an edit permission, which controls what users and groups are allowed to access and edit the page respectively.
Example 6.4. Set Permissions for a Page
This example makes a page accessible to everyone, but only editable by users in the
/platform/administrators group.
The changed permissions do not take affect until
savePage is invoked.
page.setAccessPermission(Permission.everyone()); page.setEditPermission(Permission.any("platform", "administrators")); portal.savePage(page);
6.3. Page Composition
Red Hat JBoss Portal allows you to add applications and containers to a Page. Applications and containers represent blocks of content visible on a page.
There are three types of application:
- Portlet
- WSRP Portlet
- Gadget
The template for containers renders children in the user interface. The Portal API provides a container with two basic templates for rendering children in rows and columns. A container can hold the following child elements: other containers, and applications.
Example 6.5. Page Containing a Single Application
PageBuilder pageBuilder = portal.newPageBuilder(); Application calculator = portal.getApplicationRegistry().getApplication("Gadgets/Calculator"); Page page = pageBuilder.child(calculator).siteName("classic").siteType("portal").name("awesome").build();
Example 6.6. Container Template Using Two Column Containers Nested in a Row Container
PageBuilder pageBuilder = portal.newPageBuilder(); ApplicationRegistry appRegistry = portal.getApplicationRegistry(); Page page = pageBuilder .newRowsBuilder() .newColumnsBuilder() .child(appRegistry.getApplication("Gadgets/Calculator")) .child(appRegistry.getApplication("Gadgets/rssAggregator")) .buildToParentBuilder() .newColumnsBuilder() .child(appRegistry.getApplication("Gadgets/Calendar")) .child(appRegistry.getApplication("Gadgets/Todo")) .buildToParentBuilder() .buildToTopBuilder() .siteName("classic") .siteType("portal") .name("awesome_" + UUID.randomUUID().toString()) .displayName("Awesome page") .showMaxWindow(false) .accessPermission(Permission.everyone()) .editPermission(Permission.any("platform", "administrators")) .moveAppsPermission(Permission.everyone()) .moveContainersPermission(Permission.everyone()) .build();
The
PageBuilder.build() method returns a page object. The page object is an argument for Portal.savePage() method to persist the page.
Note
It is not mandatory to add children initially to a page. A page can be stored without content, and children added later through the JBoss Portal UI or API.
6.5. Application
An application is a read-only representation of a gadget, portlet or a WSRP portlet. Application is used to compose pages.
Application can be accessed through the user interface by clicking Application Registry.
To access the complete list of application use the following code:
ApplicationRegistry registry = portal.getApplicationRegistry(); List<Application> applications = registry.getApplications();
In case you know the ID of an application use the following code:
ApplicationRegistry registry = portal.getApplicationRegistry(); Application gadgetRss = registry.getApplication(applicationIdFromPreviousInteraction):