VAST 8 / Seaside Tips: More about Character Sets in HTML Forms


In my last post I suggested setting an application default for character Sets and overriding the accept-charset attribute ib form tags to ensure all your form data is encoded in the character set which you want to use, especially if your charset is not (yet) utf-8 which is very likely to be the case in context of VA Smalltalk.

It is, of course, not a good thing to have to modify each and every form tag (or, in seaside words ‘form brush’). This also means you will have a hard time maintaining your application when it comes to changing character sets, for example when VAST supports UTF-8.

Wouldn’t it be better if a form tag simply used the charaxter set that’s defined in the Application’s preferences? This would have many effects:

  • No need to change every form. All forms would automagically use the Application’s encoding
  • Easy change of a whole application by simply changing the Application’s preferences
  • A component rendering a Form could be reused in applications with different character encodings without any modifications
  • It would simply be “right”

This is where a little bug of Seaside comes to play (I consider it a bug), which is easy to fix.

Seaside initializes a form tag to use utf-8 as its accept-charset attribute. By changing WABasicFormTag>>initialize, you can make it ask the Application for its preference instead. The initialize method of WABasicFormTag should be changed from:

initialize
 super initialize.
 self acceptCharset: self defaultUrlCharset

to:

initialize
 super initialize.
 self acceptCharset: self application charSet.

That’s how easy it is😉.

I haven’t used terribly long yet, so maybe I’ll find some horrifying side-effects, but so far this seems to be working just fine.