Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7626027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:16:14+00:00 2026-05-31T05:16:14+00:00

I am copying the select tag from playframework to test out creating tags as

  • 0

I am copying the select tag from playframework to test out creating tags as well as fasttags(doing the option as a fasttag). But the only problem is I get this error when it should be looking for the fasttag…

The template tags/alvazan/option.html or tags/alvazan/option.tag does not exist.

My FastTags class is in the app/tags directory and is the following code….

package tags;

import groovy.lang.Closure;

import java.io.PrintWriter;
import java.util.Map;

import play.templates.FastTags;
import play.templates.JavaExtensions;
import play.templates.TagContext;
import play.templates.GroovyTemplate.ExecutableTemplate;

@FastTags.Namespace("alvazan")
public class TagHelp extends FastTags {

        public static void _option(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
            Object value = args.get("arg");
            TagContext ctx = TagContext.parent("alvazanselect");
            Object selectedValue = ctx.data.get("selected");
            boolean selected = selectedValue != null && value != null && (selectedValue.toString()).equals(value.toString());
            out.print("<option value=\"" + (value == null ? "" : value) + "\" " + (selected ? "selected=\"selected\"" : "") + " " + FastTags.serialize(args, "selected", "value") + ">");
            out.println(JavaExtensions.toString(body));
            out.print("</option>");
        }
    }

My html then has this which is not found…

#{alvazan.option/}

The code here implies it would never look up a fasttag(where is the code that looks up fasttags hidden)…

 public void invokeTag(Integer fromLine, String tag, Map<String, Object> attrs, Closure body) {
            String templateName = tag.replace(".", "/");
            String callerExtension = "tag";
            if (template.name.indexOf(".") > 0) {
                callerExtension = template.name.substring(template.name.lastIndexOf(".") + 1);
            }
            BaseTemplate tagTemplate = null;
            try {
                tagTemplate = (BaseTemplate)TemplateLoader.load("tags/" + templateName + "." + callerExtension);
            } catch (TemplateNotFoundException e) {
                try {
                    tagTemplate = (BaseTemplate)TemplateLoader.load("tags/" + templateName + ".tag");
                } catch (TemplateNotFoundException ex) {
                    if (callerExtension.equals("tag")) {
                        throw new TemplateNotFoundException("tags/" + templateName + ".tag", template, fromLine);
                    }
                    throw new TemplateNotFoundException("tags/" + templateName + "." + callerExtension + " or tags/" + templateName + ".tag", template, fromLine);
                }
            }
            TagContext.enterTag(tag);
            Map<String, Object> args = new HashMap<String, Object>();
            args.put("session", getBinding().getVariables().get("session"));
            args.put("flash", getBinding().getVariables().get("flash"));
            args.put("request", getBinding().getVariables().get("request"));
            args.put("params", getBinding().getVariables().get("params"));
            args.put("play", getBinding().getVariables().get("play"));
            args.put("lang", getBinding().getVariables().get("lang"));
            args.put("messages", getBinding().getVariables().get("messages"));
            args.put("out", getBinding().getVariable("out"));
            args.put("_attrs", attrs);
            // all other vars are template-specific
            args.put("_caller", getBinding().getVariables());
            if (attrs != null) {
                for (Map.Entry<String, Object> entry : attrs.entrySet()) {
                    args.put("_" + entry.getKey(), entry.getValue());
                }
            }
            args.put("_body", body);
            try {
                tagTemplate.internalRender(args);
            } catch (TagInternalException e) {
                throw new TemplateExecutionException(template, fromLine, e.getMessage(), template.cleanStackTrace(e));
            } catch (TemplateNotFoundException e) {
                throw new TemplateNotFoundException(e.getPath(), template, fromLine);
            }
            TagContext.exitTag();
        }

2 questions

  1. Why is this not working?
  2. Where is the code in playframework source that looks up the fasttag “class” instead of looking up an html file?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:16:14+00:00Added an answer on May 31, 2026 at 5:16 am

    Why is this not working?

    Okay, I can’t really answer this because in my case your FastTag worked. I wasn’t able to reproduce your error. I only did some minor adjustments like adding a body so I wouldn’t get any errors, but they shouldn’t be the cause of your error. But just to make sure, the proper way to use this tag would be:

    #{select name:'dropdown'}
        #{alvazan.option "valueHere"}This is an option#{/alvazan.option}
    #{/select}
    

    Where is the code in Play! Framework source that looks up the FastTags “class” instead of looking up an html file?

    I think you looked over some code in the endTag() method of the GroovyTemplateCompiler in it’s last catch block you will find the following snippet, which does try to load the FastTags before trying invokeTag(). I’ve also added some extra comments for clarity.

    // Use fastTag if exists
    List<Class> fastClasses = new ArrayList<Class>();
    try {
        // Will contain your TagHelp class
        fastClasses = Play.classloader.getAssignableClasses(FastTags.class);
    } catch (Exception xe) {
        //
    }
    // Add FastTags class in first spot (takes precedence over your fasttags, 
    // so tags with the same name as in the FastTags class won't work)
    fastClasses.add(0, FastTags.class);
    // Will contain the tag method
    Method m = null;
    String tName = tag.name;
    String tSpace = "";
    // Check for namespace
    if (tName.indexOf(".") > 0) {
        tSpace = tName.substring(0, tName.lastIndexOf("."));
        tName = tName.substring(tName.lastIndexOf(".") + 1);
    }
    for (Class<?> c : fastClasses) {
        // Check Namespace Annotation first
        if (!c.isAnnotationPresent(FastTags.Namespace.class) && tSpace.length() > 0) {
            continue;
        }
        if (c.isAnnotationPresent(FastTags.Namespace.class) && !c.getAnnotation(FastTags.Namespace.class).value().equals(tSpace)) {
            continue;
        }
        // Try to find the FastTag
        try {          
            m = c.getDeclaredMethod("_" + tName, Map.class, Closure.class, PrintWriter.class, GroovyTemplate.ExecutableTemplate.class, int.class);
        } catch (NoSuchMethodException ex) {
            continue;
        }
    }
    if (m != null) {
        // If it did find a FastTag (m != null)
        print("play.templates.TagContext.enterTag('" + tag.name + "');");
        print("_('" + m.getDeclaringClass().getName() + "')._" + tName + "(attrs" + tagIndex + ",body" + tagIndex + ", out, this, " + tag.startLine + ");");
        print("play.templates.TagContext.exitTag();");
    } else {
        // If it didn't find any FastTags (m == null)
        // Now it will try to look up an html / tag file
        print("invokeTag(" + tag.startLine + ",'" + tagName + "',attrs" + tagIndex + ",body" + tagIndex + ");");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For testing code I'm copying data from a live database to a test database
I'm copying a file from folder A to folder B and then trying to
If I start copying a huge file tree from one position to another or
I'm copying data from one database to another and massaging the data while I'm
I am copying code from website matplotlib and pasting into the Vim editor in
Im copying data from a ms access db to sql server like this... string
CREATE TABLE foo SELECT * FROM bar copies the table foo and duplicates it
I am copying an VBA code snippet from MSDN that shows me how to
I am copying some user data from one SqlServer to another. Call them Alpha
I am copying an example from XSLT Cookbook: 2nd Edition (O'Reilly: Mangano, 2006) where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.