cancel
Showing results for 
Search instead for 
Did you mean: 

Change a Associated Files Selector

agey
Champ in-the-making
Champ in-the-making
Hi all,

I want to change the associated file selector used when edit properties of a node that it has a defined associated. I want to change it by another like ajaxFileSelector, user can navigate for spaces to select a file. Can anybody point me how can I do it?

Thanks in advance,
2 REPLIES 2

agey
Champ in-the-making
Champ in-the-making
Hi all,

At the end I solved it using the same method to select categories: a multiValueSelector and ajaxFileSelector to browse spaces and select files. ajaxFileSelector allows specify the mimetype of files to select. I want to specify the type of files too, so I created UIAjaxFileAssocPicker and AjaxFileAssocSelectorTag class to add a new param to specify the type of files of the selector. Now, the problem is the new param is always null. This is my implementation:

UIAjaxFileAssocPicker class:

public class UIAjaxFileAssocPicker extends BaseAjaxItemPicker
{
   /** list of mimetypes to restrict the available file list */
   private String mimetypes = null;
   private String type = null;
  
   @Override
   public String getFamily()
   {
      return "org.alfresco.faces.AjaxFileAssocPicker";
   }
  
      /**
    * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
    */
   public void restoreState(FacesContext context, Object state)
   {
      Object values[] = (Object[])state;
      super.restoreState(context, values[0]);
      this.mimetypes = (String)values[1];
      this.type = (String)values[2];
   }
  
   /**
    * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
    */
   public Object saveState(FacesContext context)
   {
      Object values[] = new Object[] {
         super.saveState(context),
         this.mimetypes,
         this.type};
      return values;
   }

   @Override
   protected String getServiceCall()
   {
      return "EditContentPropertiesDialog.getFileFolderNodes";
   }

   @Override
   protected String getDefaultIcon()
   {
      // none required - we always return an icon name in the service call
      return null;
   }
  
   @Override
   protected String getRequestAttributes()
   {
      String mimetypes = getMimetypes();
      String type = getType();
      String string = null;
      if (mimetypes != null)
      {
         string = "mimetypes=" + URLEncoder.encode(mimetypes);
      }
      if (type != null)
      {
         if(string != null && string.length() > 0){
            string += " types=" + URLEncoder.encode(type);
         }else{
            string = " types=" + URLEncoder.encode(type);
         }
      }
      return string;
   }
  
  
   // ——————————————————————————
   // Strongly typed component property accessors
  
   /**
    * @return Returns the mimetypes to restrict the file list.
    */
   public String getMimetypes()
   {
      ValueBinding vb = getValueBinding("mimetypes");
      if (vb != null)
      {
         this.mimetypes = (String)vb.getValue(getFacesContext());
      }
     
      return this.mimetypes;
   }
  
   /**
    * @param mimetypes The mimetypes restriction list to set.
    */
   public void setMimetypes(String mimetypes)
   {
      this.mimetypes = mimetypes;
   }
  
   public String getType()
   {
      ValueBinding vb = getValueBinding("type");
      if (vb != null)
      {
         this.type = (String)vb.getValue(getFacesContext());
      }
     
      return this.type;
   }
  
   public void setType(String type)
   {
      this.type = type;
   }
}

AjaxFileAssocSelectorTag class

public class AjaxFileAssocSelectorTag extends AjaxItemSelectorTag
{
   /**
    * @see javax.faces.webapp.UIComponentTag#getComponentType()
    */
   public String getComponentType()
   {
      return "org.alfresco.faces.AjaxFileAssocPicker";
   }
  
   /**
    * @see javax.faces.webapp.UIComponentTag#setProperties(javax.faces.component.UIComponent)
    */
   protected void setProperties(UIComponent component)
   {
      super.setProperties(component);
      setStringProperty(component, "mimetypes", this.mimetypes);
      setStringProperty(component, "type", this.type);
   }
  
   /**
    * @see org.alfresco.web.ui.common.tag.HtmlComponentTag#release()
    */
   public void release()
   {
      super.release();
      this.mimetypes = null;
      this.type = null;
   }
  
   /**
    * Set the mimetypes
    *
    * @param mimetypes     the mimetypes
    */
   public void setMimetypes(String mimetypes)
   {
      this.mimetypes = mimetypes;
   }
  
   public void setType(String type)
   {
      this.type = type;
   }


   /** the mimetypes */
   private String mimetypes;
   private String type;
}

Component in faces-config.xml

<component>
      <component-type>org.alfresco.faces.AjaxFileAssocPicker</component-type>
      <component-class>org.alfresco.module.assocSelector.ui.UIAjaxFileAssocPicker</component-class>
</component>

Tag in repo.tld

<tag>
      <name>ajaxFileAssocSelector</name>
      <tag-class>org.alfresco.module.assocSelector.ui.tag.AjaxFileAssocSelectorTag</tag-class>
      <body-content>JSP</body-content>
     
      <attribute>
         <name>id</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
      </attribute>
     
      <attribute>
         <name>binding</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
      </attribute>
     
      <attribute>
         <name>rendered</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
      </attribute>
     
      <attribute>
         <name>style</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
      </attribute>
     
      <attribute>
         <name>styleClass</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
      </attribute>
     
      <attribute>
         <name>value</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
      </attribute>

      <attribute>
         <name>label</name>
         <required>true</required>
         <rtexprvalue>true</rtexprvalue>
      </attribute>

      <attribute>
         <name>initialSelection</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
      </attribute>
     
      <attribute>
         <name>singleSelect</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
      </attribute>
     
      <attribute>
         <name>disabled</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
      </attribute>
     
      <attribute>
         <name>height</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
      </attribute>
     
      <attribute>
         <name>mimetypes</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
      </attribute>
     
      <attribute>
         <name>type</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
      </attribute>
   </tag>

I have add in edit-content-properties.jsp

<h:panelGrid columns="2" style="padding-top: 4px; padding-bottom: 4px;"
             width="100%">
            
      <h:outputLabel for="multi-associations-selector" value="#{msj.frasRelacionadas}"/>

      <r:multiValueSelector id="multi-associations-selector"
                               value="#{DialogManager.bean.associations}"
                               lastItemAdded="#{DialogManager.bean.fileAssocAdded}"
                               selectItemMsg="#{msj.select_fras_assoc}"
                               selectedItemsMsg="#{msj.selected_fras_assoc}"
                               noSelectedItemsMsg="#{msg.no_selected_fras}"
                               styleClass="multiValueSelector">
            <f:subview id="associationSelector">
               <r:ajaxFileAssocSelector id="associations"
                  value="#{DialogManager.bean.fileAssocAdded}"
                  label="#{msj.select_fras_assoc}"
                  initialSelection="#{NavigationBean.currentNode.nodeRefAsString}"
                  mimetypes="application/pdf"
                  type="{InvoiceModel.model}invoice"
                  styleClass="selector"
                  singleSelect="true"
                  height="105px" />
          
            </f:subview>
      </r:multiValueSelector>
   </h:panelGrid>

The selector works fine and show like I want but the type param of ajaxFileAssocSelector tag is always null. I specify that it´s type="{InvoiceModel.model}invoice" but when I retrive it in EditContentPropertiesDialog.getFileFolderNodes(), it´s always null. Can somebody point me what is the problem? Is implementation right?

EditContentPropertiesDialog.getFileFolderNodes():


         Set<String> types = null;
         String typeParam = (String)params.get("type");
         System.out.println("typeParam " + typeParam); //always is null!!!!
         if (typeParam != null && typeParam.length() != 0)
         {
            // convert to a set of types to test each file against
            types = new HashSet<String>();
            for (StringTokenizer t = new StringTokenizer(typeParam, ","); t.hasMoreTokens(); /**/)
            {
               types.add(t.nextToken());
            }
         }



Thanks a lot in advance,

agey
Champ in-the-making
Champ in-the-making
Hi all,

I found the problem. It´s in getRequestAttributes() method of UIAjaxFileAssocPicker class. I have to return a string with the params: mimetypes and type but I don´t know how the string has to be. Mimetypes param can have several values separate by comma, so the real type param value is got like a value of mimetypes param and type param value is set null. Can somebody point me what getRequestAttributes() method should return?

Thanks a lot in advance,