Tea Trove   SourceForge.net Logo  
 Project
   Home
   FAQ
   License
   SourceForge
   Subversion
 Products
   Tea
   TeaServlet
   Kettle
   BeanDoc
   Trove
 Documentation
   Javadoc
   Document Links
Frequently Asked Questions 


About Tea
Template Questions
Other Tea Questions
TeaServlet Questions
Kettle Questions

What is the difference between Tea vs. WebMacro?


    Tea runs through a compiler that has a strict type-checking phase. With WebMacro, a hashtable is supplied to the template. It cannot be determined until runtime if a property is misspelled or the wrong one is requested. This makes debugging templates more difficult. In Tea, these errors are reported at compile time.

    Tea is compiled to Java byte code and runs in the JVM. WebMacro runs in an interpreter and is slower than Tea. In addition, WebMacro accesses properties from objects using reflection calls, which can have an initial overhead 10 to 100 times slower than ordinary method calls because they can't be inlined. Although WebMacro caches the result of introspecting beans, it cannot fully eliminate this runtime overhead.


Return to top

Seems that Tea and JSP are very similar. Both have the goal of separating presentation from business logic. What are the advantages/disadvantages of Tea vs. JSP?


    Some of the differences are outlined in the documentation on the Tea language. Tea is simpler than JSP, easier to customize (functions are easier to write than taglibs) and it enforces separation. JSP can only encourage it.

Return to top

Is there support for regular expressions in Tea?


    No, there is no regex support in Tea.

Return to top

What is the easiest way to execute a template, but write the output to a file, to be used as static HTML.


    The Tea Template Language document has a section titled "Java Integration". The SimpleTea example shows how to integrate with the Tea compiler and runtime. This example outputs to a String, but it can easily be adapted to write to files.

Return to top

How do I call another tea template within a tea template?


    Template calls must be preceded with the keyword, "call".

Return to top

Is there a way to access variables of a calling template from the called template?


    Templates can return values; however, only the calling template can access this value.

Return to top

How can I "escape" single-quotes so I can use javascipt in my templates?


    Just use the backslash (\) to escape characters.

Return to top

In the tea function dateFormat is there a format syntax to display days/months in Spanish?

    Call setLocale with language code and optional country code. For example:

        //Default locale
        currentDate()
        dateFormat("EEEE, MMM dd, yyyy")
        currentDate()

        //Spanish
        setLocale("es", "")
        currentDate()
        dateFormat("EEEE, MMM dd, yyyy")
        currentDate()

        //Portugese
        setLocale("pt", "")
        currentDate()
        dateFormat("EEEE, MMM dd, yyyy")
        currentDate()


Return to top

Is there a way in Tea that I can loop through a collection and write out files with different content depending on the object in that collection?


    Try something like this:
        foreach (m in obj.collection) {
          if (m isa site.content.CollegeSports) {
            writeTo(m.name & ".html") {
              m.name
            }
          }
        }

Return to top

I need to cycle through a collection that may vary in number each time. How can I do this in my tea template?

    You can determine the number of items in your collection by querying the ".length" property of the collection. From there, you should be able to loop through the items in the collection.

Return to top

Can I loop through the Hashtable object inside the tea template?


    You can't loop through the elements in a hashtable. The ordering would be more or less random, and not very useful.

Return to top

Help me understand the life cycle of a TeaServlet.

    A new instance of the context class is created for every request. An instance of the application class is created only on startup and stays there for all the requests.

    The life cycle of a TeaServlet application includes calls to four methods: the init method, the getContextType method, the createContext method, and the destroy method. Specific information on these methods can be found in the TeaServlet Tutorial.


Return to top

How can I reload specific templates?

    To reload the templates, you need to call the admin function with appropriate arguments.

    You cannot reload an individual template. All templates are loaded in a single ClassLoader, and a ClassLoader does not allow its classes to be reloaded. A new ClassLoader must be created in order to reload classes.


Return to top

Is it bad to pass the Response object to the context class?

    Don't use the Response object that the template has access to. This is designed just so that the template can access certain properties. Instead, save the ApplicationRequest object (HttpServletRequest) in your context instance.

Return to top

How can I access a header in the http request (like HTTP_REFERER) from Tea?

    CGI-style names are not understood; you need to use the actual header names outline in the HTTP specs.

    referrer = getHeaders()["Referer"]
      or
    headers = getHeaders() referrer = headers["Referer"]


Return to top

How do you redirect to another page inside a tea template? Do I have to rely on javascript or HTTP headers to do that?

    Use the sendRedirect function, which creates a response that forces the browser to redirect to the given URL. For information on the sendRedirect function and other TeaServlet functions that aid in accessing request parameters and controlling responses, refer to the TeaServlet User Manual.

Return to top

Is there a version of Kettle that will run on Linux?

    The current release of Kettle is Java compliant and has been tested on Windows and Linux platforms. We recommend Java 1.3.0.

Return to top

How can I reload specific templates in Kettle?

    Although Kettle can be used to test templates for correctness, it doesn't actually create the .class files. The only way to reload specific templates is to reload all templates. This can be accomplished directly from the TeaServlet admin pages or in Kettle by using the template reload button. (The template reload button is only available when TeaServlet integration is setup properly.)

Return to top