no.sesat.search.view.velocity
Class JsonDataModelDirective

java.lang.Object
  extended by org.apache.velocity.runtime.directive.Directive
      extended by no.sesat.search.view.velocity.AbstractDirective
          extended by no.sesat.search.view.velocity.JsonDataModelDirective
All Implemented Interfaces:
Cloneable, org.apache.velocity.runtime.directive.DirectiveConstants

public final class JsonDataModelDirective
extends AbstractDirective

Convert sections (datamodel.includes) of the context's DataModel into a JSON object. This allows client javascript to use the datamodel exactly like JSP and velocity templates do.

For example, adding to any tab (in views.xml) the following

       
           
           
       
 
allows the javascript to access after a request to this tab with the addition URL parameter "layout=json" to access datamodel.getSearches() datamodel.getNavigation() datamodel.getQuery() but will exclude any bean properties, at any level, named "configuration". Or what to serialise can be passed into the directive as named argument pairs. For example:
#jsonDataModel('yellow' $datamodel.getSearch('yellow').results 'yellow' $datamodel.getSearch('yellow').results)

Add prettyJson=true to the url to get the output in pretty format.

This class was inspired by Karl Øie's work in MapJSONDirective.java

Version:
$Id: JsonDataModelDirective.java 7225 2009-04-09 00:32:20Z ssmiweve $

Field Summary
 
Fields inherited from class org.apache.velocity.runtime.directive.Directive
rsvc
 
Fields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants
BLOCK, LINE
 
Constructor Summary
JsonDataModelDirective()
           
 
Method Summary
 String getName()
           
 int getType()
           
 boolean render(org.apache.velocity.context.InternalContextAdapter context, Writer writer, org.apache.velocity.runtime.parser.node.Node node)
           
 
Methods inherited from class no.sesat.search.view.velocity.AbstractDirective
getArgument, getDataModel, getObjectArgument
 
Methods inherited from class org.apache.velocity.runtime.directive.Directive
getColumn, getLine, init, setLocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonDataModelDirective

public JsonDataModelDirective()
Method Detail

getName

public String getName()
Specified by:
getName in class org.apache.velocity.runtime.directive.Directive

getType

public int getType()
Specified by:
getType in class org.apache.velocity.runtime.directive.Directive

render

public boolean render(org.apache.velocity.context.InternalContextAdapter context,
                      Writer writer,
                      org.apache.velocity.runtime.parser.node.Node node)
               throws IOException,
                      org.apache.velocity.exception.ResourceNotFoundException,
                      org.apache.velocity.exception.ParseErrorException,
                      org.apache.velocity.exception.MethodInvocationException
Specified by:
render in class org.apache.velocity.runtime.directive.Directive
Throws:
IOException
org.apache.velocity.exception.ResourceNotFoundException
org.apache.velocity.exception.ParseErrorException
org.apache.velocity.exception.MethodInvocationException


Copyright © 2005-2009 Schibsted ASA. All Rights Reserved.