如何在 Scala 中开发 ajax Web 应用程序?
我正在寻找一个面向对象的 Web 框架来在 Scala 中开发 Ajax 应用程序。 因此,理想情况下,我希望拥有类似 GWT 的东西,但不混合 Java(客户端代码)和 Scala(服务器代码)。
下面是 Scala 如何创建带有标签和列表的垂直布局的简短示例:
val label = new Label("nothing selected")
val list = new ListView("item1", "item2") onSelection { value => label.text = value }
pageContent = VerticalLayout(label, list)
实际上,这几乎是 Scala Swing 代码。但为什么不为 Web 应用程序选择相同的语法呢?
对于问题Scala可以用来编写GWT应用程序吗?臭氧建议使用scalagwt 项目。该项目看起来非常有前途。然而,它仍处于早期阶段,还不支持客户端-服务器通信(据我所知)——我的 Web 应用程序所依赖的功能。
其他人建议使用 lift 框架,我想知道 lift 是否允许以类似于 GWT 的面向对象方式开发 Ajax 应用程序。我不需要将客户端代码编译为 Java 脚本的功能,这样客户端应用程序甚至可以完全运行而无需与服务器通信。相反,我不介意浏览器中的每个操作都会导致对服务器的 Ajax 请求,并且服务器执行相应的操作并将 JavaScript 命令发送回客户端以更新网页的部分内容(例如,用内容填充表 X)是)。一个设计良好的由多个 UI 组件组成的 API 不仅可以用来向用户隐藏这些组件的 HTML 定义,还可以隐藏当用户在 Scala 代码中更新 UI 组件时在后台执行的 JS 更新命令(例如lable.text = ...
)。是否有用于 lift 的模块或替代的 Web 框架提供这种面向对象的 Web 应用程序定义?
I'm looking for an object oriented web framework to develop Ajax applications in Scala.
So, ideally I would like to have something like GWT but without mixing Java (client code) and Scala (server code).
Here is a short example of how Scala could create a vertical layout with a label and a list:
val label = new Label("nothing selected")
val list = new ListView("item1", "item2") onSelection { value => label.text = value }
pageContent = VerticalLayout(label, list)
Actually, this is nearly Scala Swing code. But why not choosing the same syntax for web applications?
For the question Can Scala be used to write GWT applications? ozone suggested to use the scalagwt project. The project looks very promising. However, it is still in an early stage and does not yet support a client-server communication (as far as I know) - I feature my web application depends on.
Other people suggested to use the lift framework and I'm wondering if lift allows to develop Ajax applications in a similar object oriented fashion as it is possible with GWT. I do not need the feature that client code is compiled into Java Script so that the client applications may even run completely without communication to the server. Instead I would not mind if every action in the browser leads to an Ajax request to the server and the server performs the corresponding operation and sends back JavaScript commands to the client in order to update parts of the webpage (e.g. to fill table X with content Y). A well designed API consisting of several UI components could be used to not only hide the HTML definitions of these components from the user but also the JS update commands that are performed in the background when the user updates an UI component in the Scala code (e.g. lable.text = ...
). Is there a module for lift or an alternative web framework providing such a object oriented definition of web applications?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您应该看看 Vaadin (一个基于 GWT 的框架,具有丰富的 UI 组件),特别是它的Scala 支持此处。
Maybe you should take a look at Vaadin (a GWT-based framework with rich UI components), and in particular to its Scala support here.
我也将 Vaadin 与 Scala 一起使用 - 它运行得很好。
I use Vaadin with Scala, too - it works very well.