cancel
Showing results for 
Search instead for 
Did you mean: 

Chrome

marco_altieri
Star Contributor
Star Contributor
I'm trying to modify the region chrome configured in Web Quick Start.
in the file WEB-INF/surf.xml is configured a default chrome:


<defaults>
   <region-chrome>vanilla</region-chrome>
      <!– Set up our sample login and logout pages –>
      <page-type>
            <id>login</id>
            <page-instance-id>sample/login</page-instance-id>
      </page-type>
      <page-type>
            <id>logout</id>
            <page-instance-id>sample/logout</page-instance-id>
      </page-type>
      <!– User factory for Alfresco 3.2 –>
      <!–
      <user-factory>webframework.factory.user.alfresco32</user-factory>
      –>
      <!– User factory for Alfresco 3.3 –>
      <!–
      <user-factory>webframework.factory.user.alfresco</user-factory>
      –>
</defaults>

The vanilla chrome writes the content of the region without any wrapping. Just as a test, I tried to change the ftl template: tomcat/webapps/wcmqs/WEB-INF/chrome/vanilla/chrome.ftl, adding a div:

<div class="standard-region-chrome">
<@regionInclude/>
</div>


The problem is that this template seems to be completely ignored.

I have also tried to use a the "titled" chrome that is defined in

Unfortunately the jsp ./tomcat/webapps/wcmqs/WEB-INF/chrome/titled/chrome.jsp

cannot be compiled because it uses the class RenderContext that is not available. I tried to use the class RequestContext instead of RenderContext:


<%@ page import="org.springframework.extensions.surf.*" %>
<%@ page import="org.springframework.extensions.surf.types.*"%>
<%@ page import="org.springframework.extensions.surf.render.*" %>
<%@ page buffer="0kb" contentType="text/html;charset=UTF-8" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="surf" uri="http://www.springframework.org/tags/surf" %>
<%
        RequestContext context = (RequestContext) request.getAttribute(RenderContextRequest.ATTRIB_RENDER_CONTEXT);

        // get the component
        String componentId = (String) context.getValue(WebFrameworkConstants.RENDER_DATA_COMPONENT_ID);
        if (componentId != null) {
            System.out.println("componentId = " + componentId);
            System.out.println("context.getObjectService() = " + context.getObjectService());
            System.out.println("context.getObjectService().getComponent(componentId) = " + context.getObjectService().getComponent(componentId));
            Component component = context.getObjectService().getComponent(componentId);

            String title = null;
            if (component != null && component.getTitle() != null)
            {
                    title = component.getTitle();
            }

            if (title != null)
            {
%>
<h2><%=title%></h2>
<%
            }
        }
%>
<surf:componentInclude/>

but it seems that the context is not configured properly: componentId is null and there isn't any RenderService configured in the Spring container.

Could someone help me?

Thank you,
Marco
4 REPLIES 4

ddraper
World-Class Innovator
World-Class Innovator
RenderService was removed from Spring Surf during some refactoring (because it was essentially pointless and did exactly the same thing as RequestContext) - this JSPs usage of it must have slipped through the net. You're right to use RequestContext instead.

For region chrome the WebFrameworkConstants.RENDER_DATA_COMPONENT_ID will not have been set yet (region chrome wraps a region and component chrome wraps a component, this property only gets set once region rendering begins which is not the case when region chrome is being rendered). It's possible that this JSP never actually worked properly or that it only worked due to peculiarities with the Spring Surf framework which have since been fixed.

As for the template version, if your changes are not getting picked up it's possible that either they've not been deployed properly or more likely that the chrome is not actually used.

Unfortunately I don't have very much knowledge about Web Quick Start although I do know a lot about the Spring Surf framework…What exactly is it that you are trying to achieve?

Regards,
Dave

marco_altieri
Star Contributor
Star Contributor
Hi Dave,

thank you very much for your reply.

I understand that I was wrong trying to use the component chrome as a region chrome.

I would like to add to each region (or component) a title and some controls (to remove or close the region for example).
I don't know which is the best place to add these controls: the region or the component?

I think that the changes that I have tried have been deployed correctly because I changed the WCMQS core files directly… (it was only a test).
I have changed the file:
./webapps/wcmqs/WEB-INF/chrome/vanilla/chrome.ftl
and restarted the server.

The chrome is configured in the surf.xml. Do I need to do something else?

ddraper
World-Class Innovator
World-Class Innovator
Looking at the source of the WQS application it looks like that there is no "vanilla" Chrome configured - this could be the cause of the problem.  If you look under the "surf/site/chrome" path you will see XML files defined for the "box" and "titled" Chrome, but nothing defined for "vanilla" (Surf will be looking for a configuration file "vanilla.xml" rather than a FreeMarker file).

The reason that this was working before was that Surf will fall back to the default Chrome if all else fails.

You can create a Chrome configuration file and place it either in the site config tree or in the "WEB-INF/chrome directory". If you wish to use that existing FreeMarker file then the contents of the file should look like this:


<?xml version='1.0' encoding='UTF-8'?>
<chrome>
   <title>Vanilla Chrome</title>
   <processor mode="view">
      <id>webtemplate</id>
      <uri>chrome/vanilla/chrome.ftl</uri>
   </processor>
</chrome>

You can also define WebScript or JSP chrome if you prefer, you can also define additional processors for other modes (but I would imagine that "view" suffices).

There are a few things to be aware of…
1. You should check exactly what the default region chrome is doing. The default Surf region chrome looks like this:

<div id="${htmlid}">
<@regionInclude/>
</div>
…and the id of the div is often used by components for a unique identification prefix.

2. It is possible for regions to explicitly override specified chrome so that either no chrome is rendered or that alternative chrome is rendered.

I don't think it matters much whether or not you make your changes to the component or region chrome. Typically, the component chrome is not used so I would probably stick with just the region chrome as you have been doing.

I hope this helps!

Dave

marco_altieri
Star Contributor
Star Contributor
Hi Dave,

I already did something equivalent some days ago: I copied the files default-component-chrome.xml and default-component-chrome.ftl from the source code of spring surf.
Anyway, yesterday I tried also your suggestion but it didn't work.

I have verified that the  class FTLTemplateProcessor cannot find the template. It executes:

Template template = templateConfig.getTemplate(templatePath);

but this method fails and return null.

After some attempts I realised that the template file is found only if it is copied in the folder:
./tomcat/webapps/wcmqs/WEB-INF/templates/vanilla/chrome.ftl

Thank you again for your help.
Marco