2012-03-11 13 views
2

playframeworkからselectタグをコピーして、fasttagと同様にタグの作成をテストします(オプションをファストタグとして実行しています)。しかし、唯一の問題は、それがfasttagを探してしなければならないとき、私はこのエラーを取得...私のplayframeworkファストタグが何らかの理由でピックアップされていない

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

マイFastTagsクラスは、アプリ/ tagsディレクトリにあり、次のコードです....

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/} 

ここのコードは、それは...(ここで、隠されたfasttagsを検索するコードがある)fasttagを見上げることはない意味

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質問

  1. は、なぜこれが動作しませんか?
  2. htmlファイルを検索するのではなく、fasttag "class"を検索するplayframeworkソースのコードはどこですか?

答えて

3

これはなぜ機能しないのですか?

私の場合、あなたのFastTagが機能したので、これは本当に答えられません。あなたのエラーを再現できませんでした。私は体を追加するような小さな調整しかしなかったので、エラーは出ませんでしたが、エラーの原因ではありません。しかし、念のため、このタグを使用する適切な方法は、次のようになります。

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

プレイのコードがあります! htmlファイルを検索する代わりにFastTags "class"を検索するフレームワークソース?

は、私はそれはあなたがinvokeTag()をしようとする前にFastTagsをロードしようとしない、次のスニペットを、見つける最後のcatchブロックだ中であなたがGroovyTemplateCompilerendTag()方法でいくつかのコードの上に見えたと思います。わかりやすくするためにいくつかのコメントを追加しました。

// 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

ありがとう、なぜそれが見つからなかったのか把握するために私はそれをデバッグする必要があります....ありがとう、それは私がうずまきを乗り越えるのを助けるはずです。 –

2

私は同じ問題がありました。以前は同じ名前のカスタムタグがありましたが、views/tagsディレクトリにHTMLファイルとして実装されていました。私はもう少し複雑なことをしたいので、タグをFastTagサブクラスとして再実装しました。私はあなたがしたエラーを得た。

解決策は単純にplay cleanを実行することでした。 PlayはHTMLタグテンプレートをクラスファイルとしてキャッシュしていたと思います...(?)

+0

+1これも私の問題でした。私はFastTagをモジュールに移しました。私はPlay cleanを走らせるまで、Playでピックアップを止めました。 –

関連する問題