15 Replies Latest reply on Jul 22, 2014 1:43 PM by MarkoSelf Branched to a new case.

    PluginTemplateDefinition JavaScript Issue

    Advanced

      I've been trying to get the Extending Jive with Plugin Template Definitions implementation working in Jive 7, but the soy files never load for some reason.  I've even set "supports" to return true and load the JS on every page, but with no luck.  I'm hoping someone can find an issue in the code:

       

      ViewDocumentTemplateDefinition.java

      public class ViewDocumentTemplateDefinition implements PluginTemplateDefinition {
      
          private PermissionChecker permissionChecker;
         
          public void setPermissionChecker(PermissionChecker permissionChecker) {
              this.permissionChecker = permissionChecker;
          }
      
          @Override
          public boolean supports(ActionDescriptor actionDescriptor) {
              return true;
              /*if (actionDescriptor.getAction() instanceof DocumentAction) {
                  DocumentAction documentAction = (DocumentAction) actionDescriptor.getAction();
                  Document document = documentAction.getDocument();
                  if (document != null && document.isTextBody() == false) {
                      return permissionChecker.isDownloadingRestrictedFor(document.getJiveContainer());
                  }
              }
             
              return false;*/
          }
      
          @Override
          public String getHeadTemplateName() {
              //return "jive.teletech.download.removeDownloadLinksCSS";
              return null;
          }
      
          @Override
          public String getBodyTemplateName() {
              return "jive.teletech.download.removeDownloadLinks";
          }
      
          @Override
          public Object getModel(ActionInvocation ai, Object actionModel) {
              return null;
          }
      
      }
      
      
      

       

      restricted-download.soy

      {namespace jive.teletech.download}
      
      /**
      *
      */
      {template .removeDownloadLinks}
      
          {call jive.shared.soy.resourceInlineJs}
              {param code}
                  $j(function() {lb}
                      $j("div.jive-wiki-body-download").remove();
                  {rb});
              {/param}
          {/call}
         
      {/template}
      
      
      /**
      *
      */
      {template .removeDownloadLinksCSS}
           <link rel="stylesheet" href="{resourceUrl('/plugins/place-permissions/resources/styles/restricted-download.css')}" type="text/css" media="all" />
      
         
      {/template}
      
      

       

      spring.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:util="http://www.springframework.org/schema/util"
             xsi:schemaLocation="
              http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
              http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
             default-autowire="no" default-init-method="init" default-destroy-method="destroy">
      
          <bean class="com.jivesoftware.teletech.permissions.PlacePermissionsPlugin"/>
         
          <bean id="teletechPermissionChecker" class="com.jivesoftware.teletech.permissions.PermissionCheckerImpl"/>
         
          <bean parent="pluginTemplateDefinitions" class="com.jivesoftware.community.util.spring.MergeableCollection">
              <property name="source">
                  <util:list>
                      <bean class="com.jivesoftware.teletech.permissions.web.soy.ViewDocumentTemplateDefinition"/>
                  </util:list>
              </property>
          </bean>
      
         
      </beans>
      
      
      

       

      Folder Structure

        • Re: PluginTemplateDefinition JavaScript Issue
          Novice

          Are you sure that supports method is correct? I use this definition:

           

          @Override

           

          public boolean supports(Action action) { return action instanceof XXAction; }


            • Re: Re: PluginTemplateDefinition JavaScript Issue
              Advanced

              HiAndrew Cornell,

               

              I believe they changed it in Jive 7 to use ActionDescriptor instead of Action, but I'm very new to Java and Jive plugin development.  Are you familiar with this change?

               

              /*
               * $Revision$
               * $Date$
               *
               * Copyright (C) 1999-2012 Jive Software. All rights reserved.
               *
               * This software is the proprietary information of Jive Software. Use is subject to license terms.
               */
              package com.jivesoftware.community.web.soy.plugins;
              
              import com.opensymphony.xwork2.Action;
              import com.opensymphony.xwork2.ActionInvocation;
              
              /**
               * Represents the things necessary to render a head and/or a body template for a given action or set of actions.
               *
               * @since Jive SBS 7.0
               */
              public interface PluginTemplateDefinition {
              
                  /**
                   * Should this template be rendered as part of the result of the given action, or not?
                   *
                   * @param actionDescriptor A class describing the action that has just executed.
                   * @return true if this definition supports this action, false otherwise.
                   */
                  public boolean supports(ActionDescriptor actionDescriptor);
              
                  /**
                   * The name of the template to in the head of the page.
                   * <p/>
                   * NOTE: this template should include any meta information or CSS to be included in the page.
                   *
                   * @return a fully qualified template name, or null if no template should be rendered in the head.
                   */
                  public String getHeadTemplateName();
              
                  /**
                   * The name of the template to in the body of the page.
                   * <p/>
                   * NOTE: this template should include any javascript to be included on the page.  The script should be included
                   * using the {jive.shared.soy.resourceInlineJs} template mechanism and MUST use the "plugins" id to be included
                   * properly.
                   *
                   * @return a fully qualified template name, or null if no template should be rendered in the body.
                   */
                  public String getBodyTemplateName();
              
                  /**
                   * The model to pass to the head and body template at render time.
                   *
                   * @param ai          the current ActionInvocation.
                   * @param actionModel The model of the currently executing action.  If the action is not
                   *                    {@link com.jivesoftware.community.web.soy.SoyModelDriven} then this will be a reference to the
                   *                    action itself.
                   * @return an object that will be used to render the template(s).
                   */
                  public Object getModel(ActionInvocation ai, Object actionModel);
              }
              
              
            • Re: PluginTemplateDefinition JavaScript Issue
              Novice

              You could change your soy code to this:

               

               

              {template .removeDownloadLinks}

               

                <script type="text/javascript">

                    $j('div.jive-wiki-body-download').remove(); 

                </script>

              {/template}

               

              This is the way I call JavaScript in my soy templates.

              • Re: PluginTemplateDefinition JavaScript Issue
                gdinning Novice

                Looks fine to me as well - try sticking a breakpoint in the supports() method to see if it's getting hit.  If not, try putting in a zero-argument constructor with a call to super() and stick a breakpoint on that.  If neither of those is hit, it's probably a problem with your Spring file.  If they do get hit, I would guess that it doesn't like getting null back from the getModel() method.  As Andrew Cornell mentioned, try returning new HashMap<String, Object>().

                 

                I find that I see a lot more in sbs.log than in sbs.out.  If you have a problem with your Soy template, you should see something in there.

                1 person found this helpful
                • Re: PluginTemplateDefinition JavaScript Issue
                  gdinning Novice

                  This shouldn't be causing the problem now because you've commented out the relevant code, but don't forget to inject your PermissionChecker into the ViewDocumentTemplateDefinition when you add it to the MergeableCollection.  Hopefully that will save you one cargo restart down the road

                  1 person found this helpful