1 Reply Latest reply on Jun 30, 2013 4:12 PM by sonny.lau

    How to display list of documents in a container using custom widget(development)

    karthikodc

      Hi,

       

       

      I am new to Jive development, learning and working on custom widget development. I have developed a custom widget which shows all documents in the container.

      My issue is not able to display list of documents on FTL and please explain me how to use existing FTL template's in custom widgets.

      I'm getting values(Logger) from Java but not able to render on FTL template.

       

       

      Can anyone help me to fix this issue and also help me to use use existing FTL template's

       

       

      Java Code:

      import java.util.Map;

      import com.jivesoftware.base.UnauthorizedException;

      import com.jivesoftware.community.CommunityManager;

      import com.jivesoftware.community.Document;

      import com.jivesoftware.community.DocumentManager;

      import com.jivesoftware.community.DocumentResultFilter;

      import com.jivesoftware.community.JiveContainer;

      import com.jivesoftware.community.JiveIterator;

      import com.jivesoftware.community.ResultFilter;

      import com.jivesoftware.community.annotations.PropertyNames;

      import com.jivesoftware.community.widget.BaseWidget;

      import com.jivesoftware.community.widget.CommunityWidgetContext;

      import com.jivesoftware.community.widget.ProjectWidgetContext;

      import com.jivesoftware.community.widget.SocialGroupWidgetContext;

      import com.jivesoftware.community.widget.WidgetCategory;

      import com.jivesoftware.community.widget.WidgetCategoryMarker;

      import com.jivesoftware.community.widget.WidgetContext;

      import com.jivesoftware.community.widget.WidgetType;

      import com.jivesoftware.community.widget.WidgetTypeMarker;

       

       

      import org.apache.log4j.LogManager;

      import org.apache.log4j.Logger;

       

       

      @WidgetCategoryMarker(WidgetCategory.OTHER)

      @WidgetTypeMarker({WidgetType.SOCIALGROUP,WidgetType.COMMUNITY})

       

       

      public class ShowDowumentsWidget extends BaseWidget {

         protected static final Logger log = LogManager.getLogger(ShowDowumentsWidget.class);

        private static final String FREEMARKER_FILE = "/plugins/showdocuments/resources/templates/showdocuments.ftl";

        public static final String WIDGET_DESC = "widget.document.desc";

        public static final String WIDGET_TITLE = "widget.document.title";

       

        private CommunityManager communityManager;

        private DocumentManager documentManager;

        private DocumentResultFilter filter;

       

        JiveIterator<Document> documents= null;

       

        public void setFilter(DocumentResultFilter filter) {

        this.filter = filter;

        }

       

       

        public void setDocumentManager(DocumentManager documentManager) {

              this.documentManager = documentManager;

          }

       

        public void setCommunityManager(CommunityManager communityManager) {

        this.communityManager = communityManager;

        }

       

        @Override

        public String getTitle(WidgetContext widgetContext) {

        // TODO Auto-generated method stub

        return getLocalizedString(WIDGET_TITLE, widgetContext);

        }

       

       

      @Override

        public String getDescription(WidgetContext widgetContext) {

        // TODO Auto-generated method stub

        return getLocalizedString(WIDGET_DESC, widgetContext);

        }

       

       

        @Override

        public String render(WidgetContext widgetContext, ContainerSize size) {

        // TODO Auto-generated method stub

        return applyFreemarkerTemplate(widgetContext, size, FREEMARKER_FILE);

        }

       

       

        protected Map<String, Object> loadProperties(WidgetContext widgetContext,

        ContainerSize size) {

        //Replace the return method with logic from the lab for populating the widget's properties

        Map<String, Object> properties = super.loadProperties(widgetContext, size);

        JiveContainer container = communityManager.getRootCommunity();

         try {

                  if (widgetContext.getWidgetType() == WidgetType.PROJECT) {

                      container = ((ProjectWidgetContext)widgetContext).getProject();

                  } else if (widgetContext.getWidgetType() == WidgetType.SOCIALGROUP) {

                      container = ((SocialGroupWidgetContext) widgetContext).getSocialGroup();

                  }else if (widgetContext.getWidgetType() == WidgetType.COMMUNITY) {

                  container  = ((CommunityWidgetContext) widgetContext).getCommunity();

                  } else if (widgetContext.getContainer() != null) {

                      container = widgetContext.getContainer();

                  }

              }

              catch (UnauthorizedException e) {

                  // ignore

              }

        log.info("******************************containerType"+ container.getObjectType() + "containerID"+container.getID());

        documents = documentManager.getDocuments(container,filter);

       

        for(Document document: documents){

        log.error("document.getID:" + document.getDocumentID());

        log.error("document.getID:" + document.getPlainSubject());

      }

      log.info("*********"+container);

        properties.put("documentList", documents);

        properties.put("container", container);

        properties.put("numOfDocs", documentManager.getDocumentCount(container));

       

        return properties;

       

        }

       

       

      }

       

       

      FTL:

      <#-- Render for display in a small area. -->

      <#if containerSize == enums['com.jivesoftware.community.widget.Widget$ContainerSize'].SMALL>

          <p class="getsmall">There are currently ${numOfDocs} Documents:</p>

          <#list documentList as document>

              <b>${document.title}</b> 

          </#list>

      <#-- Render for display in a large area. -->

      <#else>

          <p class="gobig">There are currently ${numOfDocs} Documents:</p>

        <#list documentList as document>

                  <b>${document.title}</b> 

          </div>

          </#list>

      </#if>