我從playframework複製選擇標記來測試創建標籤以及fasttags(做一個fasttag選項)。但唯一的問題是我得到這個錯誤時,應該尋找fasttag ...我的playframework快速標記沒有被拾取出於某種原因
The template tags/alvazan/option.html or tags/alvazan/option.tag does not exist.
我FastTags類是在app /標籤目錄下,下面的代碼....
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>");
}
}
我的HTML,然後有這個未找到......
#{alvazan.option/}
這裏的代碼意味着它永遠不會查找一個fasttag(這裏是查找隱藏fasttags代碼)...
個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個問題
- 這是爲什麼不工作?
- playframework source中的代碼在哪裏查找fasttag「class」而不是查找html文件?
謝謝,我將不得不在那裏調試它然後找出爲什麼它沒有被發現....謝謝,這應該幫助我克服駝峯,我會回來。 – 2012-03-15 13:50:38