|
This is a deliberately oversimplified example. I typically hate oversimplified examples, but I think most people reading this blog will be able to extrapolate the useful bits from this sample out into practical uses. Also, Volta is still a CTP and subject to radical change in the future, so I'm not so worried about conforming to best practices yet, since there are none :)
In a typical Ajax application, your goal is often to have the user click something. In response, JavaScript goes out and (through the magic of XML HTTP Requests) obtains data and potentially modifies data on a server as well. Using the returned data, the JavaScript can then directly manipulate the HTML DOM to make it appear to the end user as though things just dynamically happened in a manner very similar to a traditional desktop application.
While there are lots of libraries that enhance and abstract on top of that functionality, that is essentially the core of what Ajax is and why it is so popular. The problem is that everybody's got their own flavor of Ajax library, and some of them require you to write a truckload of JavaScript. Most of the tools for dealing with Ajax, even the most advanced ones, still require the developers to think in terms of multiple paradigms, multiple tiers, and potentially even multiple languages and/or development environments - all just to get a little change to happen to a page without doing a visible refresh. Not worth it, IMHO. I've got better things to be doing, like building application functionality, not twiddling with silly little JavaScript semantics.
So, let's say I have a button that I want to trigger the revealing of a hidden <div>. Sure, it's simple to do in JavaScript, but what I want to show you is how Volta let's you do it all in C#. Here's my contrived HTML:
<body>
Hello. This is Ajaxy!
<button id="btnClick">Click Me to Reveal the hidden text!</button>
<div id="hiddenText" style="visibility:hidden;">
<b>This is a hidden message!</b>
</div>
</body>
So, if I started littering this page with some JavaScript, I could get the div to appear. But, what if I wanted the contents of the div to contain a weather report from some remote web service, complete with gradients and images, etc. Now, what if I want to _debug_ that code, and what if I want that code to be strongly typed and unit testable?? Screw JavaScript, it's not going to get the job done.
Here's the code for my Volta page. You can see it grabs references to HTML DOM elements, sets up a purely C# event handler, and manipulates the DOM directly - all in C#, and no mention of browser cap checking, no mention of tier, and no mention of JavaScript. It's all just pure C# from end to end.
public partial class VoltaPage1 : Page
{
private Button _clickButton;
private Div _hiddenTextDiv;
public VoltaPage1()
{
InitializeComponent();
_clickButton = Document.GetById<Button>("btnClick");
_hiddenTextDiv = Document.GetById<Div>("hiddenText");_clickButton.Click += new HtmlEventHandler(_clickButton_Click);
}
void _clickButton_Click()
{
_hiddenTextDiv.Style.Visibility = "visible";
}
}
When you run this app, and it launches IE pointing at the Volta web server, you can click the button and see it dynamically reveal the contents of the hidden div. Obviously nobody gives a crap about applications that reveal hidden divs. However, if you want absolute control over your DOM, and you want to leverage your C# experience and be able to designate certain blocks of C# code as running on the server tier without worrying about the busywork of getting around the same-origin policy, then Volta might actually be what you're looking for.
If you can think of some samples that are more practical than this (I wanted to do this as an intro before doing more involved samples), please let me know and I'll see what I can come up with.
is "VoltaPage1" supposed to run on the client side?
Yes, in the default Volta configuration, Volta will recompile the page
class and dump the whole thing in JavaScript to the client. You can use the
"RunAtOrigin" attribute to designate that specific C# classes run behind a
service facade and will remain on the server.
"interesting concept"
Yes it is and you have to thank google for that. It is a gwt clone in .net.
GWT clone in .NET? That's a pretty narrow-minded thing to imply. GWT is
solely focused on JavaScript and in-browser paradigms. I can use
tier-splitting to take a C# class in my Windows Forms or WPF application
and shove it off to run as a back-end service. I can multi-tier-split to
cascade services behind subsequent firewalls. GWT isn't even a recompiler.
Before you compare GWT to Volta, you should experiment with Volta first.
GWT is, as its name implies, a Web Toolkit. Volta is a tier-splitting
IL-to-IL recompilation tool that just happens to have JavaScript as one of
the target tiers.
I think you do not know what gwt is when you say "GWT is solely focused on
JavaScript "
also when did "recompiler" become a computer science term? Gwt is indeed
also a compiler with as target javascript.
I have played with GWT before. I never said that "recompiler" was a
computer science term, it's just some word I pulled out of my nether
region. The fact that this blog is not being reviewed by grammar police
allows me to do such things. I realize that GWT targets JavaScript... but
that's _all_ it targets. GWT doesn't allow me to take a Windows application
built as a single monolith and then declaratively split that application
into a smart client and a collection of services that can be distributed
across multiple locations. That is the difference I was trying to clear up
- on the surface GWT and Volta look similar, but Volta is far more
generalized as a tier-splitting tool that can be used for WinForms, WPF, or
Web applications.
I don't want to be the grammar police. I do not even speak english that
well but I am a bit tired of those vendor invented semi-technical/marketing
terms like recompiling or tier-splitting. The basic idea is exactly the
same minus some implementation details and the marketing speak. I must
admit that maybe clone was a to strong word.
Kevin, I'm with you big time. Volta is a big step and tier splitting is way
more than a marketing tem.
I bet volta and silver light will be a great comb as well... at some point.