cancel
Showing results for 
Search instead for 
Did you mean: 

display Freemarker in JSP in explorer?

esource
Champ on-the-rise
Champ on-the-rise
I wanted to use Freemarker in JSPs in explorer.  How would I do this?  How would I create a dialog for example?
15 REPLIES 15

targa2000
Champ in-the-making
Champ in-the-making
try:


<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>

<html>
  <body>
 
  <f:view>
    <h:form>
      <r:template template="alfresco/templates/userhome_docs.ftl" />
    </h:form>
  </f:view>
 
  </body>
</html>

esource
Champ on-the-rise
Champ on-the-rise
I tried it but received an error.

I want to use space and companyhome and other named objects, but instead I get the error :

Expression space is undefined

targa2000
Champ in-the-making
Champ in-the-making
you need to use the default model provided by Alfresco.  You are probably not using the default model.

esource
Champ on-the-rise
Champ on-the-rise
Maybe that is the problem.  I have created a dialog and for this dialog want to use freemarker to display the node information in the dialog.  I have created a backing bean for this dialog.  Does that somehow turn off the default named objects as you call them?  Can I use freemarker and the default named objects in a dialog?

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
This works great, check how to define custom model. and specify space and document nodes. this would fix it .

<r:template template="alfresco/templates/example.ftl" model="#{MyBean.templateModel}" />
Example Bean code to return a model:

  /**
   * 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());
     model.put("space", this.navigator.getCurrentNode().getNodeRef()); //define space that you need hire.
     model.put(TemplateService.KEY_IMAGE_RESOLVER, imageResolver);
    
     return model;
  }

esource
Champ on-the-rise
Champ on-the-rise
I'm really having difficulty here.  I am trying to display freemarker in a JSP in explorer. 

my jsp

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>

<html>
  <body>

  <f:view>
    <h:form>
      <r:template template="alfresco/templates/simple.ftl" />
    </h:form>
  </f:view>

  </body>
</html>

simple.ftl

<h1>hello how are you</h1>

I get an error message when I try to display the jsp in a dialog:

javax.faces.FacesException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Stream closed
at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:425)
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory$1.invoke(ChainingSubsystemProxyFactory.java:122)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy187.doFilter(Unknown Source)
at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.alfresco.repo.web.filter.beans.NullFilter.doFilter(NullFilter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory$1.invoke(ChainingSubsystemProxyFactory.java:122)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy187.doFilter(Unknown Source)
at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Stream closed
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
… 40 more
Caused by: javax.servlet.ServletException: javax.servlet.jsp.JspException: Stream closed
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
at org.apache.jsp.jsp.dialog.container_jsp._jspService(container_jsp.java:739)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
… 50 more
Caused by: java.io.IOException: Stream closed
at org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:204)
at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:312)
at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:342)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlResponseWriterImpl.write(HtmlResponseWriterImpl.java:581)
at org.alfresco.web.ui.repo.component.UIDialogButtons.encodeBegin(UIDialogButtons.java:83)
at javax.faces.webapp.UIComponentTag.encodeBegin(UIComponentTag.java:467)
at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:363)
at org.apache.jsp.jsp.dialog.container_jsp._jspx_meth_r_005fdialogButtons_005f0(container_jsp.java:1862)
at org.apache.jsp.jsp.dialog.container_jsp._jspService(container_jsp.java:666)
… 53 more

Would someone have a suggstion as to why I am receiving the error or how I may correct the error?

esource
Champ on-the-rise
Champ on-the-rise
changed my jsp to

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>


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


no more error

esource
Champ on-the-rise
Champ on-the-rise
This works great, check how to define custom model. and specify space and document nodes. this would fix it .

<r:template template="alfresco/templates/example.ftl" model="#{MyBean.templateModel}" />
Example Bean code to return a model:

  /**
   * 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());
     model.put("space", this.navigator.getCurrentNode().getNodeRef()); //define space that you need hire.
     model.put(TemplateService.KEY_IMAGE_RESOLVER, imageResolver);
    
     return model;
  }

Thank you very much for your post!  But where should I get 'getDocument()'?  I get the error that getDocument() is undefined.  I also get the error message that imageResolver cannot be resolved.

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
you can inject Browsebean into your bean and getCurent documetn like:

browsebean.getDocument();

and finally imageres

   
protected TemplateImageResolver imageResolver = new TemplateImageResolver() {
   public String resolveImagePathForName(String filename,
      FileTypeImageSize size) {

       FacesContext context = FacesContext.getCurrentInstance();
       ServletContext servletContext = ((HttpServletRequest) context
          .getExternalContext().getRequest()).getSession()
          .getServletContext();
       return FileTypeImageUtils.getFileTypeImage(servletContext,
          filename, size);
   }
    };

put this into your bean.
hope this helps.