从 JSTL 访问方法

发布于 2024-08-08 17:25:29 字数 269 浏览 1 评论 0 原文

只是想知道是否有一种方法可以在不创建自定义标记库的情况下访问我的类中的方法。

例子 我有一个提供 4 个方法的类:hasDisplay()、hasCreate()、hasDelete() 和 hasEdit() - 所有这些都只返回一个布尔值。

从我的 jsp 中,我只想

<c:if test="{ar.hasEdit}"></c:if>

但这仅适用于 getter 和 setter 方法,对吗?

just was wondering if there is a way to access a method from my class without creating a custom taglib.

Example
I got a class which provides 4 methods: hasDisplay(), hasCreate(), hasDelete() and hasEdit() - all of them just returning a boolean value.

From my jsp I just want to

<c:if test="{ar.hasEdit}"></c:if>

But this only works with getter and setter methods, am I right?

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

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

发布评论

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

评论(2

给妤﹃绝世温柔 2024-08-15 17:25:29

如果您不想编写自己的标签,您可以为提供“beanish”接口的对象提供一个装饰器。所以你用 isHasEdit() 包装 hasedit() ,这样你的 jsps 就可以保持干净并且仍然使用所需的语法,但你最终会得到“脏”包装器。

我会选择自定义标签库。事情没那么复杂。

If you don't want to write your own tags you could provide a decorator for the object that provides a "beanish" interface. So you wrap hasedit() with isHasEdit() that way cou can keep your jsps clean and still use the desired syntax, but you end up with "dirty" wrappers.

I'd go for a custom taglib. It's not that complicated.

×纯※雪 2024-08-15 17:25:29

正确,JSP EL 只能访问 bean 属性。其他任何东西都需要自定义标签库。虽然还不够好,但已经有了。

Correct, JSP EL can only access bean properties. Anything else needs a custom taglib. It's not good enough, but there it is.

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