Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Web Development

Wt: A Web Toolkit


Deployment Architecture

Communication over the HTTP protocol with a web browser is abstracted in Wt using a Connector implementation. Two Connector implementations are available in Wt 2.x. One connector uses the FastCGI protocol, which lets Wt applications run in conjunction with many web servers via FastCGI plug-ins. A second connector contains a lightweight, built-in web server, so that Wt applications can be developed and deployed without need for a third-party web server.

The open FastCGI protocol was initially designed to allow CGI applications to be long lived and handle multiple requests. A plug-in in the web server forwards requests corresponding to a specific web application through a local socket to such a long-lived process. This process implements a Wt dispatching server, which identifies the session that is targeted by the request and forwards it to the process that implements this session.

On the other hand, using the built-in web server avoids the need for an intermediate protocol by listening for HTTP(S) requests. In such a deployment scenario, a robust web server may still be used as a front-end web server, which is then configured to proxy pass requests to the Wt application. Because of its small footprint, the built-in web server is also a well-suited standalone for embedded applications. Perhaps most importantly, the built-in web server simplifies the development of Wt applications, because you may start them easily in your debugger, and they have a process and thread structure that may be configured to be as simple as a single thread in a single process, which includes the web server.

The World Is Not Enough

Unlike desktop applications, web applications are automatically available to an international audience. To enable this opportunity, Wt provides features to make it straightforward for your application to be localized and internationalized. For localization, Wt provides message resource bundles. A single message resource bundle defines a set of XML files, one for each locale. Each XML file associates localized text or XHTML with message keys.

The Wt API uses WString for all rendered text. WString defines an implicit constructor that takes standard strings (both narrow and wide variants, C and C++), which then represents a literal string. For example:


WText *aText = 
  new WText("Hello World!");

creates a text widget that simply displays "Hello World."

To make a localized version of the hello-world program, you would instead use the static method WString::tr(key), which for convenience is aliased in WWidget::tr(key) to create a localized string:


WText *text = 
  new Wtext(tr("hello-world"));

The string that is displayed will now be resolved by looking for the key in the message resource bundles and the current locale. For example, there could be a file "hello-world.xml" with the contents:


<messages>
  <message id="
    hello-world">Hello World!</message>
</messages>

and a file "hello-world_nl.xml" providing the same contents in locale nl corresponding to Dutch:


<messages>
  <message id=
    "hello-world">Dag Wereld!</message>
</messages>

How is the locale determined? By default, Wt uses the locale that is reported by the browser. But the locale may also be changed at runtime, using WApplication::setLocale(locale). Here comes the nice part of the story. WApplication::setLocale() will invoke a refresh of the entire application, by calling WApplication::refresh(), which will propagate a WWidget::refresh() through the entire widget tree. During this propagation, all widgets use the new locale to resolve their displayed text elements in the new locale, and any changes are caught by the usual Wt rendering mechanism to be reflected in the browser. This propagation requires no effort from you, even for application-defined widgets.

Internationalization requires support for characters that go beyond the 8-bit western character sets. For this purpose, Wt provides Unicode support for both literal and localized strings. For literal strings, you may specify and access content through narrow, wide, and UTF8 encoded strings, and therefore allow interfacing with legacy code. For localized strings, Wt relies on the extensive support for Unicode and different character encodings available in XML.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.