cancel
Showing results for 
Search instead for 
Did you mean: 

'Expression space is undefined' in ftl

laurent1050
Champ in-the-making
Champ in-the-making
Hi,

I want to modify the space display in Alfresco Enterprise 3.3.
I have created a template space_detail.ftl that is a copy of http://wiki.alfresco.com/wiki/FreeMarker_Template_Cookbook#Document_Properties_Example, change document by space and save the ftl in classes/alfresco/templates.

Then I've modified the browse.jsp page to add a reference to my template.

<r:template template="/alfresco/templates/space_detail.ftl" />

But when I try to view my page, I've an error message saying "07100059 Error during processing of the template 'Expression space is undefined on line 2, column 18 in alfresco/templates/space_detail.ftl.'. Please contact your system administrator.".

I thought that space was a common root object always provided ??? http://wiki.alfresco.com/wiki/Template_Guide#Default_Model

Any help would be helpful;

Thanks,
Laurent
5 REPLIES 5

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
Hi,
what ever is the prolem you can solve it with custom model

<r:template template="alfresco/templates/example.ftl" model="#{MyBean.templateModel}" />

/**
   * Returns a model for use by a template on the Document Details page.
   *
   * @return model containing current document and current space info.
   */
  public Map getTemplateModel()
  {
     Map<String, Object> model = new HashMap<String, Object>(4, 1.0f);
    
     model.put("document", getDocument().getNodeRef());//you do not have to put this, but it will be null.
     model.put("space", this.navigator.getCurrentNode().getNodeRef());//this is current space
     model.put(TemplateService.KEY_IMAGE_RESOLVER, imageResolver);
    
     return model;
  }

so this works for sure! hope it helps.

laurent1050
Champ in-the-making
Champ in-the-making
Thanks for your answer.

But which class must I extend in my custom bean to access getDocument() or this.navigator ?

And I'm surprised that common objects like document or space are not available.

laurent1050
Champ in-the-making
Champ in-the-making
I will try to make a resume of what I've done:

1- Creation of a template space_detail.ftl

<#– Get a list of all the property names for the space –>
<#assign props = space.properties?keys>
<ul>
   <#list props as t>
      <#– If the property exists –>
      <#if space.properties[t]?exists>
         <#– If it is a date, format it accordingly–>
         <#if space.properties[t]?is_date>
         <li>${t} = ${space.properties[t]?date}</li>
        
         <#– If it is a boolean, format it accordingly–>
         <#elseif space.properties[t]?is_boolean>
         <li>${t} = ${space.properties[t]?string("yes", "no")}</li>
        
         <#– Otherwise treat it as a string –>
         <#else>
         <li>${t} = ${space.properties[t]}</li>
         </#if>
      </#if>
   </#list>
</ul>
2- Adding of the template in browse.jsp

<r:template template="/alfresco/templates/space_detail.ftl"/>

3- Error when I show the page

07110009 Error during processing of the template 'Expression space is undefined on line 2, column 18 in alfresco/templates/space_detail.ftl.'. Please contact your system administrator.


4- space is not recognize, even if it's a default object: http://wiki.alfresco.com/wiki/Template_Guide#Default_Model

5- So I've created a custom object

public class MyCustomBean extends BrowseBean {

   public Map<String, Object> getTemplateModel() {
      Map<String, Object> model = new HashMap<String, Object>(4, 1.0f);
      model.put("document", getDocument().getNodeRef());
      model.put("space", this.navigator.getCurrentNode().getNodeRef());
      return model;
   }
}

Then, I don't know what to do….

6- Must I declare this bean in template-services-context.xml ?

<bean id="templateFicheServiss" parent="baseTemplateImplementation" class="org.alfresco.module.customspace.MyCustomBean">
   <property name="extensionName">
      <value>myBean</value>
   </property>
</bean>

and
<r:template template="/alfresco/templates/space_detail.ftl"  model="#{myBean.templateModel}"/>

But I've an error when starting Alfresco
Could not instantiate bean class [org.alfresco.module.customspace.MyCustomBean]: Constructor threw exception; nested exception is java.lang.NullPointerException


7- Must I declare this bean in faces-config-custom.xml, to override BrowseBean ?

<managed-bean>
      <description>
         The bean that holds folder browse state.
      </description>
      <managed-bean-name>BrowseBean</managed-bean-name>
      <managed-bean-class>org.alfresco.module.customspace.MyCustomBean</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
      <managed-property>
         <property-name>navigator</property-name>
         <value>#{NavigationBean}</value>
      </managed-property>
      <managed-property>
         <property-name>nodeService</property-name>
         <value>#{NodeService}</value>
      </managed-property>
      <managed-property>
         <property-name>searchService</property-name>
         <value>#{SearchService}</value>
      </managed-property>
      <managed-property>
         <property-name>lockService</property-name>
         <value>#{LockService}</value>
      </managed-property>
      <managed-property>
         <property-name>dictionaryService</property-name>
         <value>#{DictionaryService}</value>
      </managed-property>
      <managed-property>
         <property-name>fileFolderService</property-name>
         <value>#{FileFolderService}</value>
      </managed-property>
      <managed-property>
         <property-name>userPreferencesBean</property-name>
         <value>#{UserPreferencesBean}</value>
      </managed-property>
      <managed-property>
         <property-name>multilingualContentService</property-name>
         <value>#{MultilingualContentService}</value>
      </managed-property>
   </managed-bean>

No difference, still the error "Expression space is undefined…"

Any idea ?

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
you must define your bean inside custom-faces-config.xml

like this:
<managed-bean>
      <description>
         The bean that holds folder browse state.
      </description>
      <managed-bean-name>BrowseBean</managed-bean-name>
      <managed-bean-class>org.alfresco.module.customspace.MyCustomBean</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
      <managed-property>
         <property-name>navigator</property-name>
         <value>#{NavigationBean}</value>
      </managed-property>
      <managed-property>
         <property-name>nodeService</property-name>
         <value>#{NodeService}</value>
      </managed-property>
      <managed-property>
         <property-name>searchService</property-name>
         <value>#{SearchService}</value>
      </managed-property>
      <managed-property>
         <property-name>lockService</property-name>
         <value>#{LockService}</value>
      </managed-property>
      <managed-property>
         <property-name>dictionaryService</property-name>
         <value>#{DictionaryService}</value>
      </managed-property>
      <managed-property>
         <property-name>fileFolderService</property-name>
         <value>#{FileFolderService}</value>
      </managed-property>
      <managed-property>
         <property-name>userPreferencesBean</property-name>
         <value>#{UserPreferencesBean}</value>
      </managed-property>
      <managed-property>
         <property-name>multilingualContentService</property-name>
         <value>#{MultilingualContentService}</value>
      </managed-property>
   </managed-bean>

put this inside faces-config-custom.xml should work then
also check what is null (probably is nagivator).

you can get navigator from faceshelper.getmanagedbean("…)