9 Replies Latest reply on Dec 19, 2008 12:44 PM by mrostan

    Universal per portlet instance configuration for all users

    michaelchan

      When portlet preference is enabled, difference preferences are stored for admin and normal user, for example, I have an attribute called "name" in portlet.xml, when changing the name as an admin user, the changes wouldn't be reflected to normal users. So basically normal user and admin user uses different set of preferences for each portlet instance. How do I overcome that? What I want to achieve is that by changing preferences in admin mode, normal users could also see those changes.

        • 1. Re: Universal per portlet instance configuration for all use
          theute

          Portlet preferences at the instance level are shared by anyone, there is no scoping per role.

          There are 3 scopes:
          - portlet
          - portlet instance
          - user

          • 2. Re: Universal per portlet instance configuration for all use
            michaelchan

            How do I specify which preference to which scope? I just want to do portlet instance scope. I know for sure that different portlet instances of the same portlet definition can have different preferences. But those preferences varies for different users......thanks and please help

            • 3. Re: Universal per portlet instance configuration for all use
              theute
              • 4. Re: Universal per portlet instance configuration for all use
                michaelchan

                I have already tried to do that, but nothing really work the way i wanted.

                e.g. in the news portlet, i have set it to read rss feed from yahoo, in admin mode. But when i logout, the news portlet return to default. So i edit security settings..... but nothing helps....

                • 5. Re: Universal per portlet instance configuration for all use
                  theute

                  If you go to the instances tab of the admin portlet change the preference, all users will see that new preference unless they overrided the value by a personal (user scope) preference.

                  • 6. Re: Universal per portlet instance configuration for all use
                    michaelchan

                    Good, i finally get it now, I used edit mode before, and I think that's why. I did not use the instances tab. Thanks very much!!!!!

                    • 7. Re: Universal per portlet instance configuration for all use
                      michaelchan

                      What if i need some logic to translate information from database into human readable form??

                      say if I want a portlet to display some user in a usergroup, I cannot ask the admin to input the groupID directly, a drop down box should be there to provide such selection. With edit and admin mode, the preference are not stored on a per / portlet instance basis. It only happens if i use the instance configuration in the admin portlet..... can anyone help??

                      • 8. Re: Universal per portlet instance configuration for all use
                        mrostan

                        Hi, somebody knows a way to solve this ?
                        I mean, how can I customize the editor to set the preferences for all the users?

                        Thanks in advance
                        Martin

                        • 9. Re: Universal per portlet instance configuration for all use
                          mrostan

                          Hi,
                          we have implemented a new CustomizationManager (by extending the default CustomizationManagerService), we have defined "scopes" associated to the instances, if the scope is 'window' the customization is associated to the window (and not the user), so you can edit the preferences (with the customized portlet editor) for a window, and everybody that access that window will see the portlet customized with the same preferences.

                          We need this feature to allow portal managers to define portlets (and portals) that will be accessed by anonymous users.

                          Here is our code:

                          public class ScopeCustomizationManager extends CustomizationManagerService {
                           @Override
                           public Instance getInstance(Window window, User user) throws IllegalArgumentException {
                           if (window == null) {
                           throw new IllegalArgumentException("No window provided");
                           }
                          
                           Content content = window.getContent();
                          
                           String instanceId = ((PortletContent) content).getInstanceRef();
                           if (instanceId == null) {
                           return null;
                           }
                          
                           Instance instance = getInstanceContainer().getDefinition(instanceId);
                           if (instance != null) {
                           String scope = null;
                           try {
                           Object scopePropertyValue = instance.getProperties().get("sharingScope");
                           if (scopePropertyValue != null && (scopePropertyValue instanceof List)) {
                           List valuesList = (List) scopePropertyValue;
                           if (valuesList.size() > 0) {
                           Object v = valuesList.get(0);
                           if (v instanceof String) {
                           scope = (String) v;
                           }
                           }
                           }
                           } catch (PortletInvokerException e) {
                           e.printStackTrace();
                           }
                           if (scope == null || scope.equals("user")) {
                           return super.getInstance(window, user);
                           }
                          
                           if (user != null && isDashboard(window, user)) {
                           String dashboardId = window.getId().toString();
                          
                           instance = instance.getCustomization(dashboardId);
                           } else if (scope.equals("window")) {
                           instance = instance.getCustomization(window.getId().toString());
                           } else if (scope.equals("portal")) {
                           instance = instance.getCustomization(window.getPage().getPortal().getId().toString());
                           } else {
                           instance = super.getInstance(window, user);
                           }
                           }
                          
                           return instance;
                           }
                          
                          }
                          


                          Maybe somebody on the JBoss Portal Team may give us an opinion about this feature, and our implementation, we think it's a very important feature for an enterprise portal.

                          Thanks in advance,
                          Martin