在 Play 中使用纯 JSP 标签

发布于 2024-11-10 11:16:44 字数 567 浏览 3 评论 0原文

如果这是一个愚蠢的问题,我很抱歉,但是我找不到任何有关此的信息。

我想在我的应用程序视图中使用 JSP 标签(而不是播放“标签”) - 具体来说, Joda Time JSP 标记 用于格式化目的。

我不知道如何调用这些标签 - 在 JSP 中我只需要导入 taglib 就可以了。

  <%@taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %>

我是否错过了一些简单的事情 - 如何在播放视图定义中执行此操作?目前我的 taglib 调用呈现为 HTML。我知道 Play 的视图内容是基于 Groovy 的 - 我也尝试在那里找到相关信息,但没有成功。

谢谢。

编辑 无论如何,我开始怀疑我对这里的情况有很大的误解 - 我的假设是否正确,即 Play 模板引擎没有任何 JSP 是一种替代方案而不是扩展吗?

My apologies if this is a stupid question, however I can't find any information about this.

I would like to use a JSP tag (not play 'tags') in my application views - specifically, the Joda Time JSP tags for formatting purposes.

I can't work out how to call these tags - in JSP I just had to import the taglib and off I went.

  <%@taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %>

Have I missed something simple - how do I do this in Play view definitions? At the moment my taglib calls are rendered as HTML. I understand that Play's view stuff is based on Groovy's - I have tried finding the relevant information there too but haven't been successful.

Thanks.

Edit For what it's worth I'm starting to suspect that I'm very much misunderstanding the situation here - am I correct in my assumption that the Play templating engine has nothing to do with JSP and is an alternative rather than an extension?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

永言不败 2024-11-17 11:16:44

事实上,您不能使用 JSP 标签。 Play 框架使用(默认情况下,尽管有替代模块可以替换渲染引擎)Groovy 模板引擎来创建视图。这些视图负责模板和您将创建的大多数标签。

还有 FastTags 的概念,这可能是公开 JSP 标记库中的 JodaTime 功能的最简单方法。可以在这里找到如何构建 FastTags 的一个很好的示例...

有人可以解释一下如何使用 FastTags

但是,如果您想做的只是整齐地格式化日期,那么您应该看看用于日期格式化的 JavaExtensions。 http://www.playframework.org/documentation/1.2.1/javaextensions#日期。要格式化日期非常简单,您的代码应该如下所示简单(假设您的日期作为 mydate 传递到您的视图中。

${mydate.format('dd MMMM yyyy hh:mm:ss')}

如果 Play 内置了 JavaExtensions,您甚至可以创建自己的 JavaExtensions 。

最后,重要的是要了解 Play 不是 Java EE,它有自己的堆栈、自己的一套规则和自己的一套技术 Java EE 工具,但您几乎肯定会发现游戏方法可以节省您的时间和精力。

Indeed, you cannot use JSP tags. The Play framework uses (by default, although there are alternative modules that can replace the rendering engine) the Groovy templating engine to create the views. It is these views that are responsible for both the templates and for the majority of tags you will create.

There are also the concepts of FastTags, which may be the easiest way for you to expose the JodaTime functionality that you find in the JSP tag library. A good example of how to build FastTags can be found here...

Can someone explain how to use FastTags

However, if all you are trying to do is to neatly format dates, then you should take a look at the JavaExtensions for date formatting. http://www.playframework.org/documentation/1.2.1/javaextensions#date. To format dates is really simple, your code should be as simple as the following (assuming your date is passed into your view as mydate.

${mydate.format('dd MMMM yyyy hh:mm:ss')}

You can even create your own JavaExtensions if the ones built-in to Play don't offer everything you need.

Finally, It is important to understand that Play is not Java EE. Play has its own stack, its own set of rules and its own set of technologies. It can be difficult at first to separate yourself from the Java EE tools, but you almost certainly find that the Play approach saves you time and effort.

中二柚 2024-11-17 11:16:44

是的你是对的。 Play 模板基于 Groovy。这就是为什么语法与 jsp 标签完全不同的原因。因此,我认为不可能使用 jsp 或用 Jsp 系统替换 groovy 系统。

Yes, you are right. Play templates are based upon Groovy. That is why the syntax is altogether very different from jsp tags. And thus, I don't think it is possible to use jsp or replace the groovy system with a Jsp sytem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文