2

I am using Play Framework 1.2.5, and trying to use DateTime from Joda Time instead of the usual java.util.Date. I am trying to implement a format method for use in my views.

The Play documentation says I can create my own custom java extensions for use in templates, but it doesn't seem to be working for me. I have followed the example in the docs to no avail.

My custom extension:

package ext;

import org.joda.time.DateTime;
import play.templates.JavaExtensions;

public class DateTimeExtensions extends JavaExtensions {

    public static String format(DateTime datetime, String format) {
        return datetime==null ? "" : datetime.toString(format);
    }
}

My template code:

${subProject?.startDate?.format('yyyy-MM-dd')}

And the error I am receiving:

Exception raised was MissingMethodException : No signature of method: org.joda.time.DateTime.format() is applicable for argument types: (java.lang.String) values: [yyyy-MM-dd]

It looks like Play isn't detecting my custom extension as the documentation says it should. Does anyone have any suggestions on how to make this work?

4

1 回答 1

2

你的扩展类对我来说看起来不错。该文档指出,您必须重新启动应用程序才能使扩展生效。如果这不起作用,请尝试运行play clean. 这样做会删除临时文件,包括缓存的字节码,这有望解决您的问题。

于 2013-08-06T14:12:57.583 回答