The Source for Java Technology Collaboration
User: Password:



John Reynolds

John Reynolds's Blog

Pragmatic Web Forms: WebForms2

Posted by johnreynolds on February 20, 2005 at 05:31 PM | Comments (10)

I recently came across a discussion of WebForms2, and after checking out the links I've come away pleasantly optimistic that building form-centric web applications is about to get simpler.

The WebForms2 proposal is a product of WhatWG (the Web Hypertext Application Technology Working Group). WhatWG is a loose consortium of browser manufacturers who have banded together to make the development of web applications easier. Rather then pursuing proprietary browser-specific solutions, they are developing technologies that can either be used by existing browsers, or can be implemented by all future browsers. Proprietary is a dirty word with this group.

The WebForms2 proposal specifically targets the question:

"How can we make it easier for developers to create sophisticated web forms?"

For example, how can we make it easier for an HTML author to add an input field to a form which will only accept a date that falls within a specific range?

WhatWG’s answer is not new technology; their answer is to define standard labels that add type and validation information to existing HTML tags and to distribute JavaScript libraries that utilize these labels.

Here's how it works: When a form is submitted the WebForms2 JavaScript parses the DOM, looking for the standard labels. If an <input> element is encountered that contains an attribute "type=number", then the input text will be checked to verify that it is numeric. If the parser encounters additional attributes such as "min=" and "max=" then further validation will kick in. This is really a quite simple technique that has been used for years... but now it's being "standardized".

Here’s an example from the WebForms2 documentation (I have underlined some of the standard labels):

<form action="..." method="post" onsubmit="verify(event)">
 <p>
  <label>
   Quantity:
   <input name="count" type="number" min="0" max="99" value="1" />
  </label>
 </p>
 <p>
  <label for="time1"> Preferred delivery time: </label>
  <input id="time1" name="time1" type="time" min="08:00" max="17:00" value="08:00" /> —
  <input id="time2" name="time2" type="time" min="08:00" max="17:00" value="17:00" />
 </p>
 <script type="text/javascript">
  function verify(event) {
    // check that time1 is smaller than time2, otherwise, swap them
    if (event.target.time1.value >= event.target.time2.value) { 
       // ISO 8601 times are string-comparison safe.
      var time2Value = event.target.time2.value;
      event.target.time2.value = event.target.time1.value;
      event.target.time1.value = time2Value;
    }
  }
 </script>
</form>

Some XForms proponents argue that the WebForm2 approach is just a band-aid since it only handles simple forms. That's a valid concern, but sometimes a band-aid is all that you need. WebForms2’s approach is limited, but it should work on any browser that supports JavaScript DOM navigation.

Why does this matter to Java developers?

If you use any of the Java Web Component Frameworks (such as JSF, Tapestry, and Echo) then WebForms2 should be on your radar screen.

For example: What would be the result of mixing and matching Tapestry components and WebForms2 labels on the same page?

On a very basic level, there’s no relationship between Tapestry components and WebForms2 labels. WebForms2 is strictly client-side behavior, and won't have any effect on Tapestry’s server-side processing. The only possible collisions are between the text that Tapestry injects on the page and the labels recognized by WebForms2.

On a deeper level, for the Web Page and Web Component authors the implications of WebForms2 on Tapestry become apparent at design time.

Design of a Tapestry page begins with the creation of an HTML template. Labels are then added to HTML elements to “transform them” into Tapestry components (all HTML elements with the jwcid label are replaced by Tapestry generated output).

With WebForms2 on the scene, HTML Authors will be much more likely to incorporate WebForms2 labels within thier HTML tags. If Tapestry components don’t recognize the standard WebForms2 labels and map them properly, key information might be overlooked. If WebForms2 becomes prevalent takes off, it will make sense to re-work some of the Tapestry components.

I'm not familiar enough with writing JSF components to know if WebForms2 will have a similar impact. The "IDE centric" nature of JSF application development could very likely make any potential issues moot. Any decent IDE can easily "pick out" the WebForms2 labels when an HTML file is imported, and map this information for any JSF equivalent components.

In any case, I am pleased with WhatWG's WebForms2 proposal and approach. They have come up with a pragmatic solution (both technically and politically) for a well understood problem. Adoption of WebForms2 requires very little effort from Web Page Authors, doesn't require buy-in from browser vendors, and promotes simplified HTML authoring.

Simplifying things is good.

Update: Mozilla and Opera published the following: Position Paper for the W3C Workshop on Web Applications and Compound Documents.

Their philosphy is summed up by the following statement:

"Any solution that cannot be used with the current high-market-share user agent without the need for binary plug-ins is highly unlikely to be successful."

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • This would be nice to see on the scene.

    However, free libraries like this are already in existence. If we're going to be enacting change, I'd rather see some new technology (XForms), to make my life easier.

    Posted by: heaththegreat on February 22, 2005 at 06:05 AM

  • Shouldn't we pushing for xforms?

    Posted by: smartinumcp on February 22, 2005 at 06:59 AM

  • However, free libraries like this are already in existence.

    Can you name a few?

    Posted by: dog on February 22, 2005 at 09:07 AM

  • In response to "Shouldn't we be pushing for xforms?"

    I don't see WebForms2 and XForms as either/or... although if XForms had really taken off WebForms2 probably wouldn't have appeared.

    From the specification:

    "This specification is in no way aimed at replacing XForms 1.0 [XForms], nor is it a subset of XForms 1.0."

    "XForms 1.0 is well suited for describing business logic and data constraints. Web Forms 2.0 aims to simplify the task of transforming XForms 1.0 systems into documents that can be rendered on HTML Web browsers that do not support XForms"

    I believe that the problem with XForms adoption has a lot to do with lack of support by Microsoft. If IE doesn't natively support XForms, it won't excite many retailers. I am aware that there are some IE plugins available for XForms, but until these are as widely distributed as Adobe's Acrobat Reader not much will happen... hence the WebForms2 approach.

    Posted by: johnreynolds on February 22, 2005 at 10:23 AM

  • I think this is the same crap we've gotten used to with a lame 'shiny polishing' layer on top of it. I think IE doesn't natively support XForms because it would hurt them if web applications could ever be as good as a desktop application, but I guess they will be OK with this "webforms 2" thing since it seems to follow their usual technique of "add value by increasing the number of useless features".
    Of course we can't count on very end user upgrading their software, but on intranet applications (where I'd guess all the really complicated stuff is), where you can afford to have everyone upgrade their browser, Xforms would actually mean a step forward instead of a patch. I mean, you don't patch a crappy technology that was last updated in the 90s, unless you want it to remain crap.
    If I were in the W3c I'd suicide or something... I mean, look at CSS... people still laying out stuf with tables because of poor standards support.
    And now, after all that work with XForms we have to use Webforms 2 instead just because it will please the one company that always stood against or undermined standardization. Create a standard and the next time you look, Microsoft has forked it with propietary features (they did it to our java!!).
    If MS doesn't want to upgrade their ancient browser, the market should smack them hard with a new great product (firefox coming to mind), and if that new product makes the task of creating webapps with greater robustness easier by implementing xforms, then SO BE IT!!!
    Oh, and BTW I'm sick of javascript validation... I think we all are (not to mention javascript could be disabled).
    I'd like to get some arguments against my point.. I think I might be too rigid on this because of my long lasting experience with webapps ;)

    Posted by: jordihs on February 23, 2005 at 06:58 AM

  • I feel your pain :-)


    I'm sorry that I gave the impression that Microsoft was behind Webforms2... they aren't. This is an initialive by Mozilla and Opera, both of whom are being pragmatic in their belief that anything they come up with has to work with IE. Checkout their position paper.

    Posted by: johnreynolds on February 23, 2005 at 08:18 AM

  • Actually, I did know who was behind webforms 2. It was me who gave a wrong impression :-) I meant webforms 2 is more likely to be supported by MS than xforms becuse it extends what we currrently have and (IMHO) will not mean such an improvement as XForms. Taking a look at the points in the position paper, I find a few things that really worry me:

    -Backwards compatibility, clear migration path: they say that "Any solution that cannot be used with the current high-market-share user agent without the need for binary plug-ins is highly unlikely to be successful." Well , if that's true why aren't we all programming COBOL or the like instead of java? It's good to be pragmatic but at some point you have to risk stepping forward.
    -Scripting is here to stay : AARGH! no please, it's an open door for business rules getting right into the view!
    -Open process: well, if MS had no truble creating proprietary CSS features when CSS this won't keep them from forking as well (but we'll have lots more places to rant about it ;-) ).
    The W3c looks to me like the responsible kid trying to get their mates do the right thing and being disrespectfully ignored. Possibly it's partly their fault, but If we have a standards group for the web and they make a next generation form spec, then why create a different one? Because it's too evolutionary? Then what is the W3c for? Of course some think XForms is an unrealistic proposal but a few years ago nobody thought Microsoft's internet explorer would become the main browser and there it is. They made IE 4 which was free and a lot better than NS. XForms does have free implementations and is a lot better than HTML forms. Maybe I'm too idealistic but I just don't like that 'lowest common denominator' approach in webforms 2. I think it's a patching approach and like I said, after six years form the last revision of HTML patching doesn't look to me like the thing to do.
    Thanks for the reply!

    Posted by: jordihs on February 23, 2005 at 11:31 AM

  • A little correction: I said: " if MS had no truble creating proprietary CSS features when CSS this won't keep them from forking as well" I meant
    "if MS had no truble creating proprietary CSS features this won't keep them from forking as well"
    Oh and summarizing my feelings: if I think they shouldn't patch current web forms it's because they suck so badly that I doubt any patch will make them any good :-)

    Posted by: jordihs on February 23, 2005 at 11:36 AM

  • Don't you just hate not being able to go back and edit your own comments?

    Posted by: johnreynolds on February 23, 2005 at 01:45 PM

  • Yup

    Posted by: jordihs on February 23, 2005 at 02:38 PM





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds