简体   繁体   English

没有JavaScript的GWT?

[英]GWT without JavaScript?

I was looking into GWT. 我正在研究GWT。 It seems nice, but our software have the must work without JS requirement. 看起来不错,但我们的软件必须在没有JS要求的情况下工作。 Is it possible? 可能吗?

No, it isn't. 不,不是。 GWT provides a windowing toolkit that is specifically designed to run on the client, not on the server. GWT提供了一个窗口工具包,专门设计用于在客户端上运行,而不是在服务器上运行。 Degraded (eg non-javascript) code would need to deliver complete HTML to the browser, which GWT simply does not do. 降级(例如非javascript)代码需要向浏览器提供完整的HTML,GWT根本不这样做。 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. 它将您的java代码编译为传递给客户端的javascript文件,并通过客户端上的DOM操作构建UI。 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. 降级有点优雅的唯一方法是提供第二个非JavaScript用户界面或使用另一个不在客户端呈现前端但提供HTML的工具包。 Sorry. 抱歉。

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. 您可以通过创建一个“足够好”的html结构(使用表单帖子,链接菜单等)来优雅地降级,然后将GWT附加到该结构的每个部分,从而增强其行为。 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 (eg cast a vote). 例如,使HTML下拉动态,用打开灯箱的组件替换指向另一页面的链接,或用XML http请求替换另一页面的链接以执行相同的操作(例如投票)。

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开发的方式相反,但它可以工作。

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. GWT并不比编写Javascript文件更好,因为它们的语法几乎相同。 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. 创建Gmail:使用GWT,您可以在共享包中创建一个EmailFormatter,用于执行电子邮件列表标记,以便您的服务器不必这样做。 You could then add support for legacy browsers ("older version") by using the same EmailFormatter class on the server side. 然后,您可以通过在服务器端使用相同的EmailFormatter类来添加对旧版浏览器(“旧版本”)的支持。

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. 表单验证:从安全角度来看,确保用户输入服务器端是绝对必要的,对于大多数用户来说,在提交表单之前让Javascript检查表单会更方便。 You can use the same Java code with GWT to do this. 您可以使用与GWT相同的Java代码来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM