Java Portlet 的优点和缺点?

发布于 2024-07-27 19:05:00 字数 151 浏览 4 评论 0 原文

我有一个项目,我的客户要求我使用 portlet 1.0 规范和 Websphere Portal Server 6.0。 我以前没有使用过 portlet,但我听到的关于它们的批评总是很糟糕。 除了使用它们的明显原因之外,还有哪些原因? 如果没有理由,我可以用什么论据来避免它们?

I have a project in which my client is asking me to use portlets 1.0 spec and Websphere Portal Server 6.0. I haven't worked with portlets before but what I've heard of them always have been bad critiques. What are the reasons besides the obvious of using them? If not reasons, what arguments could I use to avoid them?

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

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

发布评论

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

评论(3

不念旧人 2024-08-03 19:05:00

作为一个曾从事过开发 Java portlet 的多项工作(包括我目前的工作)的人,我建议不要使用它们。

问题是:

如果您只想使用所选门户的现有功能,那么请使用门户。

如果您使用 portlet 只是为了构建一个小型、轻型、主要只读的基于 Web 的仪表板,您可以在其中快速查看不同的信息,那么这很好。

但是,如果您(或更可能是组织结构图上的更高层的人)认为 portlet 是一种将一堆不同的 Web 应用程序放在一个页面上并使其“正常工作”的方法,那么您将走向一个充满伤害的世界。 Portlet 是高度受限、独立的功能岛,而不是页面上小方块中的 Web 应用程序。

我的每一项基于 portlet 的工作都犯过这个错误,而且隧道尽头没有光明。 作为一名 Portlet 开发人员,这里列出了您习惯于在常规 Web 应用程序中执行但在 Portlet 中无法可靠执行的一小部分操作:

  • 生成其他页面的 URL。 您需要一种特定于供应商的方法来执行此操作,因为 Portlet API 只允许您生成针对生成它们的 Portlet 的 URL。
  • 读取并设置 HTTP 标头或设置 HTTP 响应代码(因此无需重定向或 HTTP 缓存,因为您不拥有将放置 portlet 的页面)
  • 必须为生成的页面中的所有标识符命名。 这意味着 HTML id 属性和 JavaScript 函数名称。 由于命名空间必须在运行时确定以确保唯一性,因此您不能将这些 Javascript 函数驻留在单独的浏览器可缓存文件中,它们必须位于 Portlet 的响应正文中。

Portlet 感觉好像它们是为 90 年代中后期(AJAX 之前)的 Web 开发状态而设计的。 但它们不适合当今的 Web 开发环境(AJAX、单页富 Web 应用程序等),这些环境假设您可以完全控制请求/响应周期。

As someone who has had several jobs (including my current one) developing Java portlets, I'd say don't use them.

Here's the problem:

If you just wanted to use the pre-existing functionality of the portal you are choosing, then use a portal.

If your use of portlets is just to construct a small, light, primarily read-only web-based dashboard where you can quickly look at disparate information, then that's fine.

But if you (or more likely someone higher up on the org chart) thinks of portlets as a way to put a bunch of different web apps on a page and have it all "just work", then you are headed for a world of hurt. Portlets are highly-restricted, self-contained islands of functionality, not web apps in tiny squares on a page.

Every one of my portlet-based jobs has made this mistake, and there's no light at the end of the tunnel. As a portlet developer, here's a small list of things you're used to doing in regular web apps, that you can't reliably do in portlets:

  • Generate URLs to other pages. You'll need a vendor-specific way to do that, since the Portlet API only allows you to generate URLs that target the portlet that generated them.
  • Read and set HTTP headers or set the HTTP response code (so no redirects or HTTP caching, since you don't own the page your portlet will be placed on)
  • Having to namespace all identifiers in the generated page. This means HTML id attributes and JavaScript function names. Since the namespace has to be determined at runtime to ensure uniqueness, you can't have these Javascript functions reside in a separate browser-cachable file they have to be in the response body for your portlet.

Portlets feel as if they were designed for the state of web development as it was in the mid to late 90s (pre-AJAX). But they are ill-suited for today's web development environments (AJAX, single-page rich web apps, etc.) that assume you have complete control of the request/response cycle.

-柠檬树下少年和吉他 2024-08-03 19:05:00

我在 portlet 方面遇到的问题让我想起了与 EJB 相同的问题——portlet

  • 要求您编写只能在特殊服务器上托管和运行的特殊代码;
  • 每个 Portlet 服务器供应商都有自定义扩展/配置/附加功能,因此更改服务器供应商并非易事;
  • portlet 似乎过于复杂,无法涵盖 90% 想要使用它的人不需要的功能

我建议类似 Google Gadgets 作为 Hibernate 到 portlet 的 EJB -

  • Javascript 框架 - 服务器端部分可以用任何语言编写,托管在任何服务器上。
  • 使用更简单
  • 许多门户服务器都支持它,并且它在供应商之间更可移植,因为它不那么复杂,并且它不是供供应商实施(和扩展)的规范

The problems I have with portlets remind me of the same problems as EJBs-

  • portlets require you to write special code that can only be hosted and run in a special server;
  • every portlet server vendor has custom extensions/configurations/additional abilities so it's not trivial to change server vendors;
  • portlets seem to be overly complex to cover functionality that 90% of people wanting to use it don't need

I'd suggest something like Google Gadgets as the Hibernate to portlet's EJB -

  • Javascript framework - server-side pieces can be written in any language, hosted on any server.
  • simpler to use
  • lots of portal servers support it, and it's more portable across vendors because it's not as complex, and it's not a spec for vendors to implement (and extend)
爱的十字路口 2024-08-03 19:05:00

Portlet 对企业很有吸引力,因为它承诺灵活性,允许客户调整和重新排列页面上的组件,如果您主要提供内容,那么它们是实现这一目标的有效方法。

在我看来,门户网站非常适合聚合纯内容、功能独立或简单相关的 portlet(例如,当您从一个 portlet 的列表中选择一项时,您会更新另一个 portlet 以显示详细信息)。
Portlet 还可以实现重用,因为您可以相当简单地将它们配置到多个页面/位置。

当您尝试通过多个步骤和交互来分解复杂的业务功能时,就会出现问题。 在这种情况下,确定 Portlet 的粒度与其说是一门科学,不如说是一门艺术,并且需要仔细考虑 Portlet 之间的交互。

您还需要考虑 UI 的灵活性。 如果您有一组 Portlet 构建块,您的企业需要清楚他们可以重新排列这些块,但在 Portlet 之间移动项目需要重写。 例如,将提交按钮从一个 portlet 移至页面底部并非易事。

总而言之,我想这取决于您想要做什么以及您期望组件的重用程度。 通过创建 IT 构建到 servlet 中的技术组件来管理重用可能会更简单,或者 portlet 可能非常适合您的业务。 没有正确的答案,你只需要仔细考虑你想要实现的目标。 如果您确实决定使用 portlet,则需要接受整个生命周期,并避免任何绕过它们的诱惑,您很快就会发现自己处于一个糟糕的境地,因为 portlet 的所有开销和限制,而无法实现其优势。

Portlets are attractive to a business because of the promise of flexibility, you an allow customers to tweak and rearrange components on the page, and if you are primarily serving content then they are an effective means of doing that.

In my opinion portals are well suited to aggregating portlets that are either pure content, functionally independent or simply related (e.g when you pick an item from a list in one portlet, you update another to show the details).
Portlets can also enable reuse, because you can configure them into multiple pages/locations fairly simply.

Where the problems can start is when you are trying to decompose complex business functions with multiple steps and interactions. In this scenario determining the granularity of the portlets is more of an art than a science, and careful consideration needs to be given to the interactions between the portlets.

You also need to consider the flexibility of the UI. If you have a set of portlet building blocks your business need to be clear that they can rearrange those blocks, but moving items between portlets involves a rewrite. For example moving the submit button from one portlet to the bottom of the page is not trivial.

So in summary, I guess it depends on what you are trying to do and how much reuse you anticipate of the components. It may be simpler to manage the reuse by creating technical components that IT build into servlets, or it may be that portlets are perfect for your business. There's no right answer, you just need to carefully consider what you are trying to achieve. If you do decide on portlets, you need to embrace the full lifecycle, and avoid any temptation to work around them, you can quickly find yourself in a bad place with all the overheads and restrictions of portlets, without being able to realise the advantages.

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