5 Replies Latest reply on Sep 29, 2008 7:13 PM by kenstern

    Problems with helloworld widget in version2

      Hi,

       

        Im exploring the HelloWorldWidget in version 2 after installing the widget when i try to place it in community page im getting

        "Failed to render this widget. An unexpected error has occurred." why is this unexpected behavior is this a bug?

       

        im using the same code provided in version 2 docs...

       

      package com.jivesoftware.clearspace.plugin.example.widget;
      
      import com.jivesoftware.community.annotations.PropertyNames;
      import com.jivesoftware.community.widget.*;
      
      import java.util.Map;
      
      // The WidgetTypeMarker annotation tells Clearspace which kinds of pages this
      // widget can be used on. This widget will show up in the widget list
      // on the Clearspace home page (the one seen by everyone) and a community overview
      // page. Other supported values include WidgetType.PERSONALIZEDHOMEPAGE and WidgetType.PROJECT.
      @WidgetTypeMarker({WidgetType.HOMEPAGE, WidgetType.COMMUNITY})
      @PropertyNames("greetUser")
      public class HelloWorldWidget extends BaseWidget {
      
          // FreeMarker template for rendering preview and published widget.
          private static final String FREEMARKER_FILE = "/plugins/example/resources/hello-world.ftl";
      
          // To hold the value of a custom property.
          private boolean greetUser = false;
      
          /**
           * Called by Clearspace to get the description that should be displayed for
           * the widget when the user hovers over it in the "customize" mode list of
           * widgets.
           *
           * @param widgetContext
           *            Context in which the widget instance is executing.
           */
          public String getDescription(WidgetContext widgetContext) {
              return "Displays a 'Hello World' message.";
          }
      
          /**
           * Called by Clearspace to get the widget's default title. The user will be
           * able to change this. If they do, their new title will be set with a call
           * to the final method BaseWidget.setCustomTitle.
           *
           * @param widgetContext
           *            Context in which the widget instance is executing.
           */
          public String getTitle(WidgetContext widgetContext) {
              return "Hello World Widget";
          }
      
          /**
           * Called by Clearspace to get the value for the greetUser property.
           *
           * @return true if the user should be greeted; false to greet the world.
           */
          public boolean getGreetUser() {
              return greetUser;
          }
      
          /**
           * Called by Clearspace to set the value for the greetUser property.
           *
           * @param greetUser
           *            true to greet the user; false to greet the world.
           */
          public void setGreetUser(boolean greetUser) {
              this.greetUser = greetUser;
          }
      
          /**
           * Called by Clearspace to get the HTML used to display the widget when it's
           * previewed or published.
           *
           * @param widgetContext
           *            Context in which the widget instance is executing.
           * @param containerSize
           *            An enum constant representing the size of the widget
           *            instance's current container: LARGE or SMALL.
           */
          public String render(WidgetContext widgetContext,
                  ContainerSize containerSize) {
              // Process the included FTL file to render the HTML for display.
              return applyFreemarkerTemplate(widgetContext, containerSize,
                      FREEMARKER_FILE);
          }
      
          /**
           * Called by Clearspace to get properties for use in your FTL file. These
           * will be added to the FreeMarker context.
           *
           * @param widgetContext
           *            Context in which the widget instance is executing.
           * @param containerSize
           *            An enum constant representing the size of the widget
           *            instance's current container: LARGE or SMALL.
           * @return A map of the properties and their values.
           */
          protected Map<String, Object> loadProperties(WidgetContext widgetContext,
                  ContainerSize containerSize) {
              // First load existing properties.
              Map<String, Object> properties = super.loadProperties(widgetContext,
                      containerSize);
      
              // Get the name of the community this instance is in, then add it as a
              // property.
              String communityName = ((CommunityWidgetContext)widgetContext).getCommunity().getName();
              String userName = widgetContext.getUser().getName();
              properties.put("communityName", communityName);
              properties.put("userName", userName);
              properties.put("greetUser", greetUser);
      
              return properties;
          }
      }
      

       

      Thank you,

      bala.

        • Re: Problems with helloworld widget in version2

          Hi,

           

          I found the solution ....

           

          Thank you,

          bala.

          • Re: Problems with helloworld widget in version2

            Hi,

            I am having the same problem with 'Hello World Widget'.  COuld you please tell me what your solution was.

            Thank you.

              • Re: Problems with helloworld widget in version2

                Hi Rupesh,

                 

                   There are two ways to deploy a plug in

                 

                   1. create a plugin jar file and copy it to JiveHome/plugins dir implicitly

                   2. use clearspace admin tool to deploy the plugin under System->Plugins

                 

                when i posted this issue i used option one from above and i had different names for my jar file and plug in name i defined in plugin.xml and i changed the plug in name in plugin.xml to my jar file name which solved my problem.

                 

                Hope this helps...

                 

                Thank you,

                bala.

                  • Re: Problems with helloworld widget in version2

                    Thank you bala. That worked.

                    --Rupesh

                    • Re: Problems with helloworld widget in version2

                      I also had to make sure names matched up in my widget plugin. I made the name in plugin.xml match the jar filename. Also, there is a FREEMARKER path defined in the Java class, so I had to make that the same as my plugin name or the widget would not work, because the render method just applies the freemarker template.

                       

                      Also, the widget errored out because the code I downloaded did not properly cast the WidgetContext to the proper subclasses. There is an example somewhere. See http://www.jivesoftware.com/community/message/93957 for part of the solution. I wanted to make the widget work on the main page, a personalized homepage, in a community, or even in a project. I put code like this in my loadProperties():

                       

                              if (widgetContext.getWidgetType() == WidgetType.PROJECT) {
                                  communityName = ((ProjectWidgetContext) widgetContext).getProject().getName();
                              }
                              else if (widgetContext.getWidgetType() == WidgetType.COMMUNITY) {
                                  communityName = ((CommunityWidgetContext) widgetContext).getCommunity().getName();
                              }
                              else if (widgetContext.getWidgetType() == WidgetType.PERSONALIZEDHOMEPAGE) {
                                  communityName = ((PersonalizedHomepageWidgetContext) widgetContext).getUser().getName() + " home page";
                              }
                              else if (widgetContext.getWidgetType() == WidgetType.HOMEPAGE) {
                                  communityName = "top level home page";
                              }
                              else {
                                  communityName = "non-community";
                              }

                       

                      I hope this helps someone.