没有 JavaScript 的 GWT?
我正在研究 GWT。 看起来不错,但是我们的软件必须在没有 JS 要求的情况下工作。 是否可以?
I was looking into GWT. It seems nice, but our software have the must work without JS requirement. Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,不是。 GWT 提供了一个专门设计用于在客户端而非服务器上运行的窗口工具包。 降级(例如非 JavaScript)代码需要将完整的 HTML 传递给浏览器,而 GWT 根本不这样做。 它将您的 java 代码编译为 javascript 文件,然后将其交付给客户端,并通过客户端上的 DOM 操作构建 UI。 然后是一些与服务器对话的代码,一些是隐式的,一些是您自己编写的。 该模型不太适合优雅地降级。
稍微优雅地降级的唯一方法是提供第二个非 JavaScript UI 或使用另一个不在客户端上呈现前端但提供 HTML 的工具包。 对不起。
No, it isn't. GWT provides a windowing toolkit that is specifically designed to run on the client, not on the server. Degraded (e.g. non-javascript) code would need to deliver complete HTML to the browser, which GWT simply does not do. It compiles your java code to a javascript file that is delivered to the client and builds the UI by DOM-manipulation on the client. Then there's some code to talk back to the server, some implicit, some written by you yourself. This model does not lend itself well to degrading gracefully.
The only way to degrade somewhat gracefully is to provide a second, non-javascript UI or use another toolkit that doesn't render the frontend on the client but delivers HTML. Sorry.
您可以通过创建一个“足够好”的 html 结构(带有表单帖子、链接菜单等)来优雅地降级,然后将 GWT 附加到该结构的每个部分,增强其行为。 例如,使 HTML 下拉列表动态化,用打开灯箱的组件替换指向另一个页面的链接,或者用 XML http 请求替换指向另一个页面的链接以执行相同的操作(例如投票)。
我已经为客户做过很多次了。
这与大多数 GWT 的开发方式相反,但它可以工作。
You could degrade gracefully by creating an html structure that is just 'good enough' (with form posts, linked menus, etc) and then have GWT attach to each part of that structure, augmenting its behavior. For example, make an HTML drop down dynamic, replace a link to another page with a component that opens a lightbox, or replace a link to another page with an XML http request to do the same thing (e.g. cast a vote).
I've done this a number of times for clients.
It's the opposite way that most GWT gets developed, but it can work.
我在设计网站时自己也在考虑这个问题。 GWT 并不比仅仅编写 Javascript 文件更好,因为它们的语法几乎相同。 当您共享客户端和服务器库时,真正的好处就会出现。 希望您在过去两年中已经解决了这个问题,但无论如何,这里有一些您可能会发现有用的示例。
创建 Gmail:使用 GWT,您可以在共享包中创建一个 EmailFormatter,用于执行电子邮件列表标记,这样您的服务器就不需要这样做。 然后,您可以通过在服务器端使用相同的 EmailFormatter 类来添加对旧版浏览器(“旧版本”)的支持。
表单验证:虽然从安全角度来看,服务器端验证用户输入是绝对必要的,但对于大多数用户来说,在提交表单之前让 Javascript 检查表单会更方便。 您可以使用与 GWT 相同的 Java 代码来执行此操作。
I was looking at this issue myself when designing my website. GWT isn't really any better than just writing Javascript files in that their syntax is almost identical. The true benefit comes when you share client and server libraries. Hopefully you've resolved this issue in the last two years, but at any rate here are a couple examples that you may find useful.
Creating Gmail: With GWT, you can create an EmailFormatter in a shared package that does the email listing markup so that your server doesn't have to. You could then add support for legacy browsers ("older version") by using the same EmailFormatter class on the server side.
Form verification: While is is absolutely necessary from a security perspective to validate user input server side, it is more convenient for most users to have Javascript check a form before it is submitted. You can use the same Java code with GWT to do this.