2010/8/25 Johannes Höchstädter <[email protected]>:
>  Hi everybody,
>
> as described in subject, I want to create a page and add portlets to it
> programmatically by java api. A portlet should do this for me. Is this
> possible on jetspeed-2? Can anybody show a good how-to to me? I don't want
> to use any AJAX-Api if possible.

Of course in addition to the Ajax APIs, there are also Java APIs. The
Ajax APIs all rely on the Java APIs in the end. You will want to start
by looking at the Jetspeed Page Manager API, the javadocs are here:

http://portals.apache.org/jetspeed-2/apidocs/org/apache/jetspeed/page/PageManager.html

There are examples of adding pages and fragments (portlet instances)
to a page in the unit test cases of Jetspeed, and in the REST and Ajax
APIs, and in the administrative portlets.

There is also the Jetspeed tutorial -- where there is a lesson to do
exactly what you want to do:

http://portals.apache.org/jetspeed-2/tutorial/04/jetspeed-service.html

See the modifyPages and createSharedPages lessons. This is something I
wrote up a while ago that should get you started. Hope Im not giving
too much of the lesson away :)

   private String modifyPages()
     {
         // using the users init param, modify pages with the
PageManager service.
         // If the page doesnt exist, dont create it. Modifications:
for user1, create a 1 column collection of 1 portlet,
         // for user2, create a 2 column collection of 2 portlets,
for user3 create a 3 column collection of 3 portets
         int count = 0;
         Iterator users = this.newUsers.iterator();
         while (users.hasNext())
         {
             String username = (String)users.next();
             try
             {
                 if (!pageManager.folderExists(Folder.USER_FOLDER +
username))
                 {
                     Folder folder = pageManager.newFolder
(Folder.USER_FOLDER + username);
                     folder.setTitle("Home");
                     pageManager.updateFolder(folder);
                     Page page = pageManager.newPage
(Folder.USER_FOLDER + username + Folder.PATH_SEPARATOR + "home.psml");
                     Fragment root = pageManager.newFragment();
                     root.setName("jetspeed-
layouts::VelocityOneColumn");
                     Fragment portlet = pageManager.newPortletFragment
();
                     portlet.setName("app::portletname");
                     root.getFragments().add(portlet);
                     page.setRootFragment(root);
                     pageManager.updatePage(page);
                     count++;
                 }
             }
             catch (Exception e)
             {
                 // ....
                 break;
             }
         }

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to