cancel
Showing results for 
Search instead for 
Did you mean: 

Custom models into templates

andrepra
Champ in-the-making
Champ in-the-making
I read in wiki (http://wiki.alfresco.com/wiki/Template_Guide) that custom model could be provided to template component as a Map of object. I don't uderstand how to make available this map to template tag.

jsp page

<%
Map myModel = new HashMap();
myModel.put("prop1", "foo");
%>
<r:template id="t6" template="alfresco/templates/my_test.ftl" model="[b]?????[/b]" />

template

The value of prop1=${prop1}

is it possible?
Thanks
2 REPLIES 2

kevinr
Star Contributor
Star Contributor
The <r:template> component is a JSF (JavaServerFaces) UI component - use of these components cannot generally be mixed with JSP code directly. To supply your model, you need to bind the model value to a getter method on a JSF managed bean. E.g. something like this:

<r:template id="t6" template="alfresco/templates/my_test.ftl" model="#{mybean.model}" />
Where mybean is declared in the "WEB-INF/faces-config-custom.xml" file and model binds to a getter method called getModel() on the bean. Take a look at BrowseBean or similar for examples of this pattern.

Thanks,

Kevin

andrepra
Champ in-the-making
Champ in-the-making
Thanks. I saw that the bean i have to develope is a common bean, i mean that has no inheritance. How can i retrieve something (parameters or attributes) from the http request to pass them to the template?
example:

public Map getTemplateModel() {
     HashMap model = new HashMap(1, 1.0f);

     // retrieving ref from the request
     String nodeRef = [request.getParameter("….")]

     model.put("documentRef", nodeRef);    
     return model;
  }