Thursday, November 22, 2007

Top 12 Areas for Technology Innovation through 2025

creativity.jpg

What will likely be the most important scientific and technological breakthroughs with significant commercial value and impacts on the lives of consumers out to 2025?

To begin to answer that question, S)T's Technology Foresight program conducted a virtual, global focus group of experts in technology, innovation, and business strategy. The group included experts from the Association of Professional Futurists, Tekes, Duke University, Hasbro, Worldwatch, General Motors, Shell, Johnson Controls, and Oxford University, among others.

After consolidating input from the expert panel and analysis by Social Technologies' futurists, what emerged was our list of top 12 areas for tech innovation through 2025:

THE TOP 12 AREAS FOR TECHNOLOGY INNOVATION THROUGH 2025

  • Personalized medicine—With the initial mapping of the human genome, scientists are moving rapidly toward the following likely breakthroughs for gene-based products and services:
    • creation of an individual’s genome map for a retail price of less than $1,000
    • correlation of specific genes and proteins with specific conditions, such as cancers, Alzheimer’s, heart disease, and diabetes, which will allow both physicians and patients to anticipate, plan for, and mitigate, if not cure, DNA-based health challenges
    • development of pharmaceuticals that treat gene-based diseases, replacing surgeries and chemotherapy
  • Distributed energy—The evolution of distributed energy will reflect that of computing: just as computing has migrated from the 20th century’s centralized model (powerful mainframes delivering applications to remote workstations) to today’s decentralized model (PCs and networks), so energy generation and delivery will move from central to distributed sources, increasingly featuring local generators that can be linked when needed for greater output. Specific innovations will include:
    • advanced electric storage devices and batteries at all scales
    • new power systems with source-switching flexibility
    • new energy management systems
  • Pervasive computing—Almost every device or object in consumers’ lives will be both smart and networked, giving rise to an “Internet of things.” Pervasive computing will drive the convergence of computing, the Internet, voice communications, and television—ultimately blurring categories of infotech products and services. Specific breakthroughs will include:
    • very simple and inexpensive computing devices with integrated wireless telephone and Internet capabilities (the $100 computer)
    • the “semantic Web,” enabled by Web data that automatically self-organizes based on its content, allowing search tools or software agents to better identify relevant Web pages—not just find keywords on them
    • intelligent interfaces, in some cases enabled by virtual reality
  • Nanomaterials—Although nanotechnologies have received much attention, the R&D is progressing very slowly. But the experts expect major breakthroughs within the next two decades, including inexpensive ways to produce mass quantities of nanomaterials. In addition, the function of nanomaterials will move from “passive” to “active” with the integration of nanoscale valves, switches, pumps, motors, and other components.
  • Biomarkers for health—While DNA-based diagnoses and cures have long been under the spotlight, this category of breakthroughs stresses prevention. Consumers today believe their lifestyle choices have long-term consequences for health, and at the same time they are becoming more knowledgeable about the life sciences. They want to be able to monitor their vital signs, broadly defined, in ways that are as affordable, easy to use, and private, as home scales are for monitoring weight. Potential breakthroughs here include:
    • individualized, private, and self-administered diagnostics for multiple physical parameters such as blood sugar, urine, C-reactive proteins, HDL, and LDL, as well as home diagnostic kits that detect early signs of diabetes, heart disease, and types of cancers
    • personalized exercise equipment and regimens that deliver customized benefits (for weight control, blood pressure, blood sugar, etc.)
    • advanced CAT scans, MRIs, and brain scans to identify disorders earlier and more accurately at less cost
  • Biofuels—The expert panel felt strongly that significant further advances will be made in renewable biomass fuels, allowing them to supplement and eventually replace gasoline and diesel. Genetically modified organisms may be key to the development of biofuels.Anticipated breakthroughs include:
    • high-energy blends of gasoline and diesel with biofuels (beyond the ethanol blends known today)
    • biomass production of a methanol that can be used as a fuel for fuel cells
    • new discoveries in plant genetics and biotechnologies specifically for energy content
  • Advanced manufacturing—The long-term trend continues to favor “mass customization,” or the ability to produce low quantities of specific products in a profitable way. Such processes may apply not just to factory manufacturing, but to many applications—potentially ranging from desktop publishing to specialty foods production. The experts anticipated the following breakthroughs by 2025:
    • advanced computer-aided design and control
    • multiple variable and inexpensive sensors linked with computers
    • expert systems and advanced pattern-recognition software for very tight quality control
  • Universal water—Water supplies are increasingly strained. Less than 2% of the planet’s store of water is fresh, and most of that is trapped in polar icecaps, while much of the water available for human use is threatened by pollution. The future of water is simple: use less; keep the available fresh water clean; and make more fresh water from salt water to offset critical shortfalls. Enabling technologies will include:
    • ultra-fine filters (probably from nanotechnology)
    • new energy sources for desalination and purification, including hybrid systems that combine conventional and alternative power—especially solar power
    • smart water-use technologies for agriculture and industry
  • Carbon management—Discussions about mitigating climate change have focused on controlling greenhouse gases, yet methane and carbon dioxide, to name two principal greenhouse gases, are more difficult to measure and control than previous air pollutants. The expert panel, however, anticipates that technologies currently in R&D will prove to be effective for these gases—and that this area of work will be extremely important. Innovations will include:
    • effective “measure, monitor, and verify” systems
    • affordable and effective carbon capture and storage technologies and systems for coal-burning power plants
    • low to zero emission controls for transportation
  • Engineered agriculture—This area of genetics-based R&D is closely related to innovations in personalized medicine and biofuels, but with applications in agriculture and nutrition. Potential breakthroughs include:
    • identification of specific genomes for desired growing and use qualities
    • crop-produced pharmaceuticals and chemical feedstocks
    • crops designed specifically for energy content and conversion
  • Security and tracking—Although the experts gave less weight to breakthroughs for national security and counterterrorism than to those for consumer products and services (probably a result of how the topic question was framed), they envisioned a continued need for personal safety and security systems. Examples of potential breakthroughs in the personal-security realm include:
    • completely autonomous security-camera systems with algorithms able to correctly interpret and identify all manner of human behavior
    • multiple integrated sensors (including remote sensing)
    • radio frequency tags for people and valuables
  • Advanced transportation—In addition to the consideration of energy sources for transportation, the experts identified potentially significant breakthroughs in the management of private mobility, as well as advances in public transport. These include:
    • personal transportation coordinated through wireless computer networks, information systems, and the Internet
    • onboard sensors and computers for smart vehicles
    • advanced high-speed rail

Over the next few weeks and months we will update ChangeWaves with more information about each of these top 12 areas for innovation.

Remote working better for staff and employers

Working from home (or teleworking) is better for both workers and bosses, as it boosts morale and job satisfaction, and cuts stress levels, researchers have discovered.

Researchers analysed 46 studies on flexible work arrangements over the past twenty years.

Ravi S. Gajendran and David A. Harrison, at the Department of Management and Organisation at Pennsylvania State University studied data on 12,833 telecommuters who spend time working away from the office, and found that working away from the office has more pluses than negatives for people and the companies that employ them.

They reported their findings to journal of Applied Psychology, published by the American Psychological Association (APA).

"Our results show that telecommuting has an overall beneficial effect because the arrangement provides employees with more control over how they do their work," said lead author Gajendran.

"We found that telecommuters reported more job satisfaction, less motivation to leave the company, less stress, improved work-family balance, and higher performance ratings by supervisors," he said.

Gajendran and Harrison also found that telecommuting has more positive than negative effects on employees and employers. In addition, the employees in their study reported that telecommuting was beneficial for managing the often conflicting demands of work and family.

The researchers also refuted the popular belief that "face time" at the office is essential for good work relationships.

"Telecommuters' relationship with their managers and coworkers did not suffer from telecommuting with one exception. Employees who worked away from their offices for three or more days a week reported worsening of their relationships with co-workers," said Gajendran.

They also countered productivity concerns, saying that that managers who oversaw telecommuters reported that the telecommuters' performance was not negatively affected by working from home.

"Telecommuting has a clear upside: small but favourable effects on perceived autonomy, work-family conflict, job satisfaction, performance, turnover intent and stress," the authors wrote.

"Contrary to expectations in both academic and practitioner literatures, telecommuting has no straightforward, damaging effects on the quality of workplace relationships or perceived career prospects."

An estimated 45 million Americans telecommuted in 2006, up from 41 million in 2003, according to the magazine WorldatWork. The uptake of broadband in recent years has often been linked to the rise in teleworking.

Yet it is not all plain sailing, and there is still resistance to teleworking in some quarters. Despite AT&T concluding a few years back that teleworking was the future, it now seems that the US carrier is now requiring thousands of employees who work from home to return to traditional office environments.

"It is a serious effort to reel in the telework people," the Telework Coalition’s Chuck Wilsker told Network World. He has heard that as many as 10,000 or 12,000 full-time teleworkers at AT&T may be affected. It is reported that following AT&T’s merger with SBC, new upper management are not supportive of teleworking.

There is also concern at the teleworking trend among IT managers. Last month, nearly nine in 10 IT managers revealed that they feared the security risks caused by remote working practices, in spite of the increased productivity.

Best and Worst Consumer Electronics, 2007

Winners were clear in the music player and game console categories, but the dust has yet to settle in the fight over PC-to-TV and next-gen DVD technology


Every year there are winners and losers in the consumer electronics business. But rarely are they so acutely divided as they appear to be in 2007. Those products deemed winners not only won—they won big. Those that lost tended to lose big, too.

Some winners will come as no surprise. Apple (AAPL) continued to dominate the mobile media player business, its iPod brand still a synonym for the entire category. The clear loser in this market was pretty much any company that dared challenge Apple on turf it has owned in an undisputed manner since 2003.

iPod Far Outstrips Rivals

Microsoft's (MSFT) Zune player, despite a heavily hyped release and a respectable spurt of purchases when it first hit the market in late 2006, had generated sales volume of just 1.2 million units from launch through mid-2007, according to market research firm NPD Group. Apple sold more than 17 times that many iPods during last year's holiday quarter alone.

Still, as this year's holiday season was getting under way, the newly redesigned Zune player (BusinessWeek.com, 10/3/07)> was in surprisingly short supply at online retailers including Amazon (AMZN). Of course, while higher-than-expected demand may be the culprit, such shortages could easily be the result of either poor planning or deliberate strategy. There's nothing like an artificial shortage to build a buzz and create the illusion of strong demand.

But despite Apple's ongoing dominance in handheld music players, there was another winner in the consumer electronics business: SanDisk (SNDK). The maker of memory chips and storage devices managed to retain its distant No. 2 slot behind Apple in the U.S. market, capitalizing on the cost advantage of being its own flash memory supplier. NPD estimates that SanDisk sells about 10% of the MP3 players sold in the U.S.

Slingbox Edges Ahead

But Apple didn't dominate in every market segment it entered. Selling downloadable TV episodes—it has sold 100 million of those in two years—is one thing. Selling gadgets that make those videos watchable on a TV set is quite another. Take AppleTV, an iTunes-connected TV accessory that, with sales clearly not taking off in an iPod way, Apple CEO Steve Jobs described as a "hobby" (BusinessWeek.com, 5/31/07).

Compared with other devices meant to bridge the gap between a home PC packed with videos and the TV set in the living room, AppleTV appeared to be just another entrant in a crowded race that's just getting under way. "Nothing in this space is settled. In fact, the picture keeps getting cloudier by the day," says Chris Crotty, a consumer electronics analyst with iSuppli, a Silicon Valley research firm. Apple has yet to release any official sales figures since AppleTV was introduced in January, which can't be an encouraging sign since the company has already disclosed sales numbers for the iPhone, which arrived a half-year later than the set-top box.

If overall buzz and an unexpected acquisition can be used to declare an early leader, if not an out-and-out winner, for the TV gadget business in 2007, then the $380 million acquisition of Sling Media by the satellite TV concern EchoStar (DISH) fits the bill. Sling makes the curious Slingbox, a device that lets users watch their home cable TV channels and videos stored on a DVR from a laptop or mobile device on the road. It's expected that Sling, which has only vaguely quantified its customer base as "hundreds of thousands," will see its "place-shifting" technology added to future set-top boxes offered to EchoStar subscribers.

The video game market also produced a surprise winner in 2007. While Sony's PlayStation 3 console and Microsoft's Xbox 360 attracted all the prerelease hype in late 2006, both saw their unit sales come up behind Nintendo's Wii. More than 15 million Wii consoles had been sold this year through October, according to iSuppli. That beats the 10.4 million Xbox systems and the 8.8 million PS3 consoles sold in the same period.

DVD Stalls Out

While most segments produced clear victors in 2007, one battle for control of the home TV screen has yielded nothing but losers. With global sales of DVD players starting to fall as the market reaches saturation—consumers will have scooped up 126 million players in 2007, vs. 130 million in 2006, iSuppli reckons—the clash of next-generation DVD technologies ended in stalemate.

The Blu-ray disc camp, led by Sony (SNE), Samsung, and Panasonic (MC), traded minor victories with the HD DVD camp let by Toshiba (TOSBY). But neither side has the sort of momentum that would make consumers feel anything less than anxious about investing their money in a device that runs on what could become the losing format. As a result, they're showing little interest in either format. Combined, only 2.2 million Blu-ray and HD DVD players have been sold worldwide to date, says iSuppli. That amounts to less than 7% of the estimated 32 million HDTV sets in use. "By fighting each other, both sides are losing," iSuppli's Crotty says.

For now, awareness of the competing DVD formats remains relatively meager. A recent study by NPD found that 29% of those surveyed had heard of the HD DVD format, while only 20% had heard of Blu-ray discs. A strong holiday season for sales of HDTV sets combined with declining prices for both types of high-definition DVD players may help drive adoption, says Ross Rubin, an NPD analyst.

A price war is already under way. Toshiba's high-end HD DVD player is now listed at about $300, down from price tags of $500 and up (BusinessWeek.com, 6/23/06) earlier this year. And in recent weeks, retailers including Wal-Mart (WMT) and Best Buy (BBY) have featured a Toshiba HD DVD player on sale for $100. Meanwhile, the price on Sony's Blu-ray player has fallen to the $400 range, down from $500 to $600 earlier this year.

There has been one silver lining amid this standoff, for movie makers at least. Of those consumers who have purchased a next-generation DVD player, most plan to replace about a quarter of their existing movie DVD collections with next-generation discs.

courtesy @businessweek.com

Create your first pure Java ASP.NET application

Grasshopper 2.0 fully integrates with Visual Studio 2005 and offers an implementation of new ASP.NET 2.0 features. In this article, we'll see how you can use the Grasshopper 2.0 and ASP.NET 2.0 controls to develop a Web-based accounting application with membership and role-based security and to deploy it on Linux. We will use Master Pages and new controls, including: Login, which is an out-of-the-box authentication feature; Wizard, which is used to split large forms and maintain state consistency; and the powerful GridView, a data control offering GUI-manageable support for paging and sorting.

The sample application, originally developed for the annual JavaDay in Rome, uses the new ASP.NET 2.0 providers featured with Grasshopper. These Grasshopper 2.0 providers are based on Apache Derby, an embedded database that offers a pure Java runtime alternative to MS SQL Express for ASP.NET 2.0 Membership and Role Profile providers. Moreover, we show in this sample how to access application data, which remains stored in MS SQL Express 2005. Finally, we'll show you how to take advantage of the integrated debugger, based on open standard JPDA (Java Platform Debugger Architecture), and how to create a deployment package that can be used over multi-platform application servers.

Download the source code for this article.

It All Begins With a Good Database



Figure 1: The JDExpenses Database.

There is no denying it: creating a good application database makes application development go much faster.

JDExpenses is an imaginary accounting application, developed for JavaDay, which allows the conference speakers to input their expenses, and the administrator to view each person's balances. Note that there is no need for authentication and role database tables since this Grasshopper version features the ASP.NET 2.0. Membership and Role API. The balance, defined as a BigInteger, demonstrates how Grasshopper handles a native Java type such as BigDecimal. Besides which, I prefer big expense accounts! :-)

In order for us to use the SQL Server from a Grasshopper application, we need to configure the database. Obviously, Windows Authentication will not work for an application that can potentially run on any operating system for which a JVM is available. We are therefore going to log in using SQL Server authentication and enable Mixed Mode Authentication in the database properties. (See Figure 2.) To do this, you can use Microsoft’s SQL Server Management Studio Express (SSMSE) tool, freely available for download from Microsoft.

Launch SSMSE, sign in, select the database, and right-click. From the context menu, select Properties. You'll see the SQL Server Properties dialog. Select Security and make sure that the SQL Server and Windows Authentication mode radio button is selected.

Next, we need to enable the preset sa account for access via SQL Server Authentication since it is disabled in the default setting (see Figure 3). From the same tool, expand Security > Logins > sa. Right-click and select Properties. Switch to Status page and set Login to Enabled. This sample assumes that you have a blank password for sa user. If not, update the password in the JavaDayConnectionString property in the Web.Config file.

To deliver multi-platform portability, Grasshopper's JDBC driver for SQL Server (the same one provided by Microsoft) supports connections via TCP/IP only, and not via Named Pipes. We therefore need to run the SQL Server Configuration Manager from Start > Program Files > Microsoft SQL Server 2005 > Configuration Tools, and enable connectivity via TCP/IP (Figure 4). Restart the SQL Server after making these changes.

Figure 2: Naturally, an application that can potentially run on any operating system cannot resort to Windows Authentication; it is therefore necessary to enable SQL Server's Mixed Mode Authentication.

Figure 3: It may be necessary to enable the "sa" user.

Figure 4: The JDBC driver used to access SQL Server supports TCP/IP connectivity only; so we'll need to enable the protocol in the SQL Server Configuration Manager.

All for One and One Template for All: The Master Pages



Figure 5: Let's create a new Grasshopper application.

The Master Pages of ASP.NET 2.0 allows you to create a consistent look and feel for our applications by defining a template that will be used for each page. First, create a new application from File > New > Project > Visual C# for Java EE project template (Figure 5). Make sure the Tomcat Application Server that comes with Grasshopper 2.0 has been launched.

From the Solution Explorer of Visual Studio, add a new Master Page. We can work on this graphic template directly in Design mode, adding all the necessary elements (Figure 6). The ContentPlaceHolder element will receive the personalized content from each page to which the template is applied. In this case, I am certain you will have no trouble recognizing the two characters in the column on the left; they may even work in your company's Accounting Department! :-)

We can now use the template for all pages. In Default.aspx, in the @Page directive, add the new attribute MasterPageFile, whose value will match the Master Page that was just created (Visual Studio will suggest this automatically). Select the Title attribute, which will overwrite the same attribute on the Master Page. In the Source view of Default.aspx, delete all the code under the @Page directive and replace it with an control:



Figure 6: Once a Master Page has been added to the Visual Studio project, it will be possible to define the template entirely in Visual mode. Pay special attention to the ContentPlaceHolder element that will receive each page's specific content.

Figure 7: Once a Master Page has been defined, it is possible to edit its content, though the Master Page area itself cannot be modified.

Naturally, the content will be associated with a ContentPlaceHolder with the same name defined in the Master Page. Next, start adding content to the page (Figure 7). Notice that the area defined in the Master Page cannot be edited in the pages that use it. Making changes to the template is a simple matter of updating the Master Page. A preview of Default.aspx shows that the title is also replaced in runtime mode.

Tell Me Who You Are and I Will Tell You What You Can Do: Role-Based Access Control



Figure 8: The Grasshopper 2.0 version of the WSAT, executed from within the application server.



Figure 9: The Grasshopper version of the administration tool for the Membership, Role, and Profile API database: the creation of roles...



Figure 10: ...and of users. Notice how roles are assigned to a user upon creation.

The time has come to "witness in action" the extraordinary role-based authentication features provided by the ASP.NET 2.0 controls, thanks to the infrastructure available for each application through the Membership and the Role APIs, which can be configured graphically with the Web Site Administration Tool (WSAT). The operation of the ASP.NET 2.0 Membership is the subject of a series of articles on MSDN, and for issues concerning implementation, I recommend reading this tutorial: Walkthrough: Creating a Web Site with Membership and User Login (Visual Studio).

On Microsoft .NET, the WSAT graphics tool creates an ASPNETDB.MDF MS SQL Express database in the default App_Data application folder in a manner that is transparent to the user. Grasshopper 2.0 creates, in the same folder, an ASPNETDB database based on Apache Derby, a pure Java open source database and offers its own version of the WSAT tool. Whereas ASP.NET 2.0 offers an AspNetSqlMembershipProvider that frees the developer from the detailed handling of the SQL Server database containing the Membership data, Grasshopper 2.0 provides an analogous AspNetDerbyMembershipProvider defined in the Mainsoft.Web.Security namespace.

For JDExpenses, we need to set up two components: ExpensesManagement, which enables speakers to input their expenses, and BalancesReport, which will be used by the accounting team to retrieve the account data. The first component will be accessible to all speakers, who are going to be associated with the role of speaker and to the accounting team; the second component will be accessible only to the accounting team, defined by the role of admin. From the Solution Explorer, create two folders by the same names. These will contain the pages pertaining to the two elements. Then, compile the application and launch the Grasshopper 2.0 version of the WSAT, which can be launched from the Visual Studio IDE or can be accessed from within the application runtime via the URL http://localhost:8090/JDExpenses/aspnetconfig/Default.aspx (Figure 8).

Create the roles (Figure 9) and the users (Figure 10) for the application. When creating the users, we will assign specific roles by checking the appropriate boxes in the form. The last link in the administration page, Manage Users, allows modification of these settings after the users have been created (Figure 11).

To set up access control and determine which roles have access to which parts of the application, we will use ASP.NET 2.0 to define appropriate allow and deny rules in the web.config file. In this case, our tasks are to:

  • Deny access to the application subfolders to all users, by default.
  • Allow access to the ExpensesManagement subfolder to both the speaker and admin roles.
  • Allow access to the BalancesReport subfolder to the admin role only.

The rule set will be as follows:



















Figure 11: The Grasshopper 2.0 version of the WSAT's user management page.

At runtime, Grasshopper's ASP.NET 2.0 providers, based on Derby, will create an aspnetdb folder containing the Derby store that corresponds to the SQL Server database used by Microsoft ASP.NET 2.0. By default, the folder App_Data is used, and during development, it will be looked up from the project folder so projects can be shared or copied together with their membership data. When deploying the application as a WAR file, App_Data will be looked up from the deployment directory. When necessary, the system administrator responsible for application deployment will be able to change this setting, thanks to a new context parameter in the web.xml deployment file:


DataDirectory
App_Data

At runtime, the application developer will be able to retrieve the value of this parameter in the program itself:

(string)AppDomain.CurrentDomain.GetData("DataDirectory")
AppDomain.CurrentDomain.SetData("DataDirectory","/usr/tmp");

Controls for Accessing JDExpenses



Figure 12: In the application's main page, add two HyperLink controls that connect to two JDExpenses elements by assigning a value to the NavigateUrl property.



Figure 13: The Login control of ASP.NET 2.0 handles form-based authentication.

Now we are ready to take advantage of the authentication tools offered by ASP.NET 2.0, which are accessible from the Login group of the Visual Studio Toolbox. In Default.aspx, add two HyperLink controls and connect them to the ExpensesManagement.aspx and BalancesReport.aspx pages, two elements of JDExpenses, through the NavigateUrl property (Figure 12). Since both pages require authentication (they belong to two folders that require it), the user will be redirected to the page that contains the login form, which by default is Login.aspx. It is possible to change the default page from web.config, but it is unnecessary and would complicate this example.

Let's create a Login.aspx page in which we will drag the Login control from the Toolbox. As is customary for the ASP.NET 2.0 controls, we can personalize its aspect using the associated Smart Tag, which is accessible through the black arrow on the edge of the control. The Login control manages the handling of username and password input errors through the integrated Validator controls in a way that is transparent to the developer, and it can use a cookie to remember the user's data for future logins via the Remember Me check box. We would normally assign a value to DestinationPageUrl and MembershipProvider, but in this case it will be unnecessary. The destination page will be handled by the HyperLink that calls up Login.aspx, handled autonomously by Grasshopper 2.0.

Launch the application, click on either of the two HyperLinks in the Home Page and type the credentials in the login page. This should allow you to access the login page and the application itself (Figure 14). You'll notice the classic "welcome message" and logout links are personalized with the username. These were achieved out-of-the-box thanks to three controls in the Login group: LoginView, which provides a personalized message depending on the authentication state of the user; LoginName; and LoginStatus. The last two require very little work: LoginName is a pure drag-and-drop control, and LoginStatus requires you to simply personalize the messages that appear before the user has logged in or is already authenticated, using the LoginText and LogoutText properties, respectively. LoginView requires a little personalization of the views for anonymous or registered users by means of the associated Smart Tag (Figure 15). Ultimately, we could have achieved the same results working in the Code view of the page and inputting the simple code below:



Authenticated! Welcome,


You're not logged. Click over "Login"



As mentioned, the Login control also handles credential input failure and failed authentications (Figure 16); by selecting the Remember Me Next Time check box (associated with the RememberMeSet property), users will not be asked for their data the next time the application is launched.

Figure 14: Access to areas that require authentication is illustrated. Note the welcome message and the logout link, obtained using the LoginView, LoginName, and LoginStatus controls.

Figure 15: The LoginView control requires only minimal personalization of the templates for anonymous or registered users using the associated Smart Tag.

Figure 16: Through ValidatorControls, the Login control handles failure to input username, password, or both, and shows an error message if the authentication has failed.

Inputting Data: The Wizard Control and the Data Sources



Figure 17: The Wizard control offers various means of personalizing from the GUI, in terms of both graphical and functional aspects.

In order to sample the authentication features, we used a simple stub page for ExpensesManagement.aspx. We can certainly do better. We will use this page to allow users to input a good deal of data, thanks to the Wizard control. This new ASP.NET 2.0 control can be found in the Standard group of the Visual Studio Toolbox. It is designed to allow the creation of a large number of fields, which are shown to the user a few at a time. This feature offers an out-of-the-box menu and a series of buttons to navigate between the various pages, while maintaining their state of course.

Drag a Wizard control onto the page and have a look at the outline of the generated code:











Figure 18: The DropDownList control Smart Tag allows association of a data source by the Wizard.

The wizard consists of a series of steps, each of which allows a series of personalization thanks to the GUI provided by the associated Smart Tag. It is almost needless to say that from the Smart Tag itself we can choose a series of graphical templates thanks to the Auto Format feature (Figure 17).

Let us begin to populate the first step of the control. From the Toolbox, drag the Label and Calendar controls that the speaker will use to select the date of JavaDay, that he or she has taken part in. There is no reason in particular to select a date using a Calendar control; but, oh, what would a Grasshopper tutorial be, without a Calendar? :-)

Let's insert another Label and a DropDownList, used to select the host city from the corresponding table in the SQL Server 2005 Express database. Here again, Visual Studio comes to our aid by allowing us to connect the drop-down box to a data source by means of a wizard (Figure 18).



Figure 20: ...the type will be SqlDataSource.



Figure 19: In the first step of the Data Source wizard, choose to create a new data source...

Select Choose Data Source. The wizard's first step appears. Choose to create a new data source (Figure 19), whose type will be SqlDataSource (Figure 20).

Click OK. It will now be possible to create a new database connection through New Connection (Figure 21). The Add Connection dialog box will appear (Figure 22). Select the SQL Server instance to be used, the authentication via SQL Server Authentication, and the database that contains the data. In order to be able to use the SQL Server 2005 Express data source from a Java application server, we still have one last step to complete: enabling the use of TCP/IP instead of the Named Pipes.

Click the Advanced button. From the connection properties, choose to use TCP/IP under Network Library. Also, note how Integrated Security is set automatically to False. Click on Test Connection to ensure that everything works correctly. Our connection string is now ready (Figure 24). When the time comes for deployment on a non-Windows platform, one last change needs to be made — this involves substituting the named instance of SQL Server (STEFANENKO\MSSMLBIZ in the figure) with the IP address of the database server. To do this, you will have to open the Web.Config file, and replace Data Source=.\SqlExpress with Data Source=\SqlExpress.

Click Next to persist the connection string in web.config, and visually create the SQL query (Figure 25), whose testing will take place in the last step of the Data Source wizard. In much the same way, associate a DropDownList to the database Accounts table in order to select the name of the speaker. Finally, add a TextBox so that the total number of JavaDay participants can be inputted. The final result is shown in Figure 26.

Figure 21: New Connection allows us to start creating the database connection.

Figure 22: From within the Add Connection dialog, choose the SQL Server 2005 Express instance to be used, the SQL Server Authentication, and the database. Finally, click "Avanzate" (Advanced) to configure the connection via TCP/IP.

Figure 23: In the connection properties, choose TCP/IP under Network Library.

Figure 24: Our connection string is now ready. At the time of deployment on Linux, we will have to substitute the name of the SQL Server instance with the IP address of the machine that hosts the database server.

Figure 25: The visual editor of SQL queries, provided by Visual Studio.

Figure 26: The first page of the Data Input wizard is now complete. The connection to SQL Server works perfectly, with the JDBC driver provided by Grasshopper 2.0.

Travel Expenses, or: How I Learned to Love External Java Classes

We are not going to fill in the second page of the Wizard control with data. Instead, we'll use a series of labels that contain the travel expenses incurred by the speaker selected on the first page. Note, first of all, that there is no need to retrieve the value from a DropDownList, since the control handles the persistence of data in a manner that is transparent to the developer. However, in a real application, the travel expense database would, in all likelihood, be populated by another application, or better still, by several applications: one hosted by the travel agency, another by the hotel chain where the speaker resides, yet another hosted by the restaurant chain where the speaker eats, and so forth. So why not add a "touch of realism" to JDExpenses?

The data pertaining to travel expenses are in fact sourced from another application, JDTravel, provided by the agency that takes care of the logistics for this event. Let us take a look at the application's source code:

package JDTravel;
import java.lang.*;
import java.util.*;

public class TravelExpenses {
private String speaker;
private int expensesTravel;
private int expensesLodging;
private int expensesBoard;
/** Creates a new instance of TravelExpenses */
public TravelExpenses() {
}

public int[] calculateExpenses(String surnameToSearch) {
int[] speakerExpenses = {0,0,0};
HashMap expenses = getExpensesByERP();
if (expenses.containsKey(surnameToSearch))
{
speakerExpenses = expenses.get(surnameToSearch);
}
return speakerExpenses;
}

protected HashMap getExpensesByERP() {
HashMap expensesTable = new HashMap();
int[] DeNictolisExpenses = {1243, 234, 4985};
int[] LandiniExpenses = {4324, 3487, 7893};
int[] CutriExpenses = {2362, 9832, 3489};
int[] BaccanExpenses = {348, 6895, 3894};
String DeNictolis = "De Nictolis";
String Landini = "Landini";
String Cutri = "Cutrì";
String Baccan = "Baccan";
expensesTable.put(DeNictolis, DeNictolisExpenses);
expensesTable.put(Landini, LandiniExpenses);
expensesTable.put(Cutri, CutriExpenses);
expensesTable.put(Baccan, BaccanExpenses);
return expensesTable;
}
}

Listing 1: A Java class developed using NetBeans.

There is no denying it: this is not a typical .NET application! In fact, we created it with the lean, educational version of NetBeans 5.0,BlueJ. The public method calculateExpenses takes care of an array of integers containing the speaker expenses, retrieving them from a HashMap and using a surname passed on as a parameter as the key. The HashMap is returned by an internal method, getExpensesByERP. While this method simply populates the HashMap with a series of value put assigned in a hard-coded manner, its name hints at a deeper notion: if the map were really produced by a complex application, such as an ERP, the wrapper calculateExpenses method would make the results available within our .NET application.

To enable and use application classes, right-click the project name in the Solution Explorer and choose Add Java Reference. Click the Browse tab and select the BlueJ JAR - JDTravel.jar - executing the build of the JDTravel (Figure 27) project. To make the project internally consistent, I added the JAR to a new ext (external) folder under the Visual Studio JDExpenses project. Adding the JAR to the project references is a little time-consuming, and if we look at the reference properties when the job is done (Figure 28) we will realize why: Grasshopper records the JAR as if it were a native .NET assembly, assigning values to many of the properties of a "common" assembly.

In order to be able to use the TravelExpenses class, an instance of it must be created in the transition to the wizard's second page. In practical terms, we must handle the Wizard control's NextButtonClick event. Add the instruction — OnNextButtonClick="LoadExpenses" — to the attribute of the Wizard control in the Code view of ExpensesManagement.aspx (Visual Studio features auto-completion with IntelliSense) and write the handling code, in the LoadExpenses method, in the page's code-behind, which is to say in ExpensesManagement.aspx.cs. This is an event handler with the following signature:

protected void LoadExpenses
(object sender, WizardNavigationEventArgs e)



Figure 27: The Add Java Reference dialog allows us to add a Java class library packaged in a JAR file that will be regarded as a .NET assembly.



Figure 28: Grasshopper assigns to the JAR, which was added to the project, several of the properties of a native .NET assembly, thanks to its own assembly management based on the Java EE application server shared classpath.

Having defined it as protected, we will not have to add the instruction AddHandler in Page_Load(). In the code-behind, add the following directive:

using JDTravel;

And create an instance of the class, as well as a private variable that will receive the array of integers returned by the calculateExpenses method:

private TravelExpenses ExpensesJD = new TravelExpenses();
private int[] expenses;

Go back to ExpensesManagement.aspx and in Design mode move to the second step of the Wizard control by selecting the corresponding Various expenses item defined in the control's menu. Bear in mind that before the compilation stage, you will need to re-select the first Wizard step, and then the execution will begin from the page highlighted during compilation. Then, add three labels that will help us show the user's travel, room, and board expenses:















Text="Travel expenses: " Font-Size="X-Large">


Travel

Text="Lodging expenses: " Font-Size="X-Large">


Alloggio

Text="Board expenses: " Font-Size="X-Large">


Vitto


Populate them using the following code:

protected void LoadExpenses(object sender, WizardNavigationEventArgs e)
{
expenses = ExpensesJD.calculateExpenses(this.ddlSpeaker.SelectedValue);
this.lblTravelExpenses.Text = "Travel
expenses: "
+
expenses[0].ToString() + " dollars";
this.lblLodgingExpenses.Text = "Lodging
expenses: "
+
expenses[1].ToString() + " dollars";
this.lblBoardExpenses.Text = "Board
expenses: "
+
expenses[2].ToString() + " dollars";
}



Figure 29: A Java class has populated our ASP.NET 2.0 page: the beauty of Grasshopper.

Besides the great simplicity of the code, notice what actually happened when the expenses variable was assigned its value: a Java array, which is an instance of java.lang.reflect.Array, was transformed into an array, which is to say an instance of System.Array implemented .NET's ICollection. It would be rather difficult to achieve this transformation in such an efficient way if we resorted to the Web Services as an integration technology.

The result is shown in Figure 29.

Cross-Platform Debugger

To see Grasshopper's integrated debugger in action, insert a breakpoint in the row in which the expenses variable received its value, clicking as usual on the gray bar beside the row numbers, and launch the application by pressing F5. The code flow will be suspended at the breakpoint, as expected, and we will be able to use all our familiar debugging tools: call stack, local variables window, and Step Over, as well as the opportunity to verify the value of a variable by mouse-over (Figure 30).



Figure 30: Grasshopper 2.0's debugger, based on JPDA, incorporates all Visual Studio's familiar tools, including breakpoints, call stack, local variables window, Step Over, and the possibility to verify variable values.

As a final task for the ExpensesManagement element, we need to handle the data gathered in the Wizard control. This control does not execute the data POST, not even in the type-safe form of the ASP.NET 2.0 cross-page posting. Rather, it reveals the FinishButtonClick event, where we shall execute not only the persistence of the inputted data, but the management of the state as well. The most suitable device among those offered by ASP.NET 2.0 for a self-contained and cross-platform application is the Session object. We shall therefore add this call to the event handler - OnFinishButtonClick="WizardDataManagement" - and write the persistence code in ExpensesManagement.aspx.cs, as follows:

protected void WizardDataManagement(object sender, WizardNavigationEventArgs e)
{
int DollarsForPresent = 10;
int generalExpenses = 0;
IEnumerator it = expenses.GetEnumerator();
while ((it.MoveNext()) && (it.Current != null))
generalExpenses = generalExpenses + (Decimal)it.Current;
BigDecimal generalExpensesBD =
PrimitiveTypeUtils.DecimalToBigDecimal(generalExpenses);
BigDecimal presents = new BigDecimal(this.txtPresent.Text);
BigDecimal unitaryFee = new BigDecimal(DollarsForPresent);
BigDecimal fee = presents.multiply(unitaryFee);
fee = fee.add(generalExpensesBD);
updateBalance(fee);

Session["Speaker"] = this.ddlSpeaker.SelectedValue;
Session["City"] = this.ddlCity.SelectedValue;
Session["JDate"] = this.JDCalendar.SelectedDate.ToShortDateString();
Session["Fee"] = fee;
}

private void updateBalance(BigDecimal amount)
{
string connectionString =
ConfigurationManager.ConnectionStrings["JavaDayConnectionString"]
.ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
try
{
conn.Open();
string sQuery = "UPDATE
Accounts SET Balance = Balance + "

+ amount + " WHERE SurnameAccount = '";
sQuery = sQuery + this.ddlSpeaker.SelectedValue + "'";
SqlCommand comm = new SqlCommand(sQuery, conn);
comm.ExecuteNonQuery();
conn.Close();
}
catch (SqlException err)
{
Console.WriteLine(err.Message);
}
}

The actual persistence in the SQL Server database is executed by the updateBalance private method that receives the speaker's total remuneration. This method is nothing new for developers who use ADO.NET. It is far more interesting to see how the application calculates this remuneration - that is to say the sum of the overall expenses (retrieved by means of a simple Iterator on the expenses array of integers, whose elements are cast at Decimal) plus a fixed amount (DollarsForPresent) for each speaker. Actually, the number of participants is a little unrealistic, since it amounts to more than ten thousand times the planet's population, but the use of a BigDecimal, that is to say a native Java type (requiring using java.math directive) is an excellent way of demonstrating Grasshopper 2.0's integration potential at the code level.

To convert generalExpenses from a .NET Decimal to a Java BigDecimal, we will use PrimitiveTypeUtils.DecimalToBigDecimal, a helper method provided by Grasshopper and available in the vmw.common namespace (subject to using), once we add the J2SE.Helpers.jar classes among the project references through Add Java Reference. This kind of conversion would be quite difficult to achieve if we chose to integrate .NET and Java applications using the Web Services!

The number of participants and the remuneration per person are retrieved respectively by the TextBox of the Wizard control and by an internal variable, since the BigDecimal builder accepts either a String or an int. At this point, we carry out "simple" arithmetic operations on very large numbers via the BigDecimal multiply and add methods, invoke the persistence method in the database, and memorize the values input in the Wizard controls through as many Session variables.

The application's last page, Review.aspx, allows us to simply verify the persistence of the remuneration in the database as well as verify that the Session variables have been actually assigned their values. Having pressed the Finish button of the Wizard control, after the execution of the method associated to the FinishButtonClick event, we shall be redirected automatically to this page, as long as it has been specified as a value in the FinishDestinationPageUrl property of the Wizard control. Let us now retrieve the speaker's balance on the Page_Load of Review.aspx event:

protected void Page_Load(object sender, EventArgs e)
{
string connectionString =
ConfigurationManager.ConnectionStrings["JavaDayConnectionString"]
.ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
try
{
conn.Open(); //you need till r68649 of Mono System.Data
string sQuery = "SELECT
Balance FROM Accounts WHERE "

+ "SurnameAccount = '" + Session["Speaker"] + "'";
SqlCommand selComm = new SqlCommand(sQuery, conn);
SqlDataReader r =
selComm.ExecuteReader(System.Data.CommandBehavior
.SingleRow);
if (r.HasRows)
{
while (r.Read())
this.lblBalance.Text = r.GetValue(0).ToString();
}
else
{
this.lblBalance.Text = "zero";
}
r.Close();
conn.Close();
}
catch(SqlException err)
{
Console.WriteLine(err.Message);
this.lblBalance.Text = "ERROR.
Data not recovered
"
;
}
}



Figure 31: The Review.aspx page serves the purpose of showing us that the speaker's remuneration persisted in SQL Server and that the Session variables, which are meant to receive the values of the Wizard controls, have actually received these values.

And show it to the user in a Label, as well as retrieve the values in the Session variables code. The final result is shown in Figure 31.

The Speaker's Account Report and the GridView Control

All that remains to do now is to use the GridView control to generate the speaker's current account report, in other words the contents of the Accounts table, which will be shown in the BalancesReport.aspx page. Once the Master Page has been defined in the usual manner, switch to Design mode and drag GridView from the Toolbox Data control onto the work area. Personalize the graphical aspect of the GridView with the usual Auto Format command from the associated Smart Tag. Also, from the Smart Tag, choose the database Accounts table as a data source for the control using the Data Source wizard. Once the wizard is completed, select the Enable Paging and Enable Sorting check boxes of the Smart Tag to enable the corresponding features. There is nothing else to do - the reporting page is ready (Figure 32). Clicking on a column's header allows sorting of the values according to the column in question (Figure 33), whereas we can see the pagination at the bottom of the control, nice and proper (Figure 34).

The GridView control is one of the best new features of ASP.NET 2.0. With it, we managed to create a paginated report with sorting options without having had to write a single line of code! At most, we could modify the default number of rows in each page (10) by changing the control's PageSize property, but this is also a task that can be carried out in the Design mode of Visual Studio.

Figure 32: A reporting page created without writing a single line of code, thanks to the GridView control.

Figure 33: By clicking on column headers we can sort the data...

Figure 34: ...while at the bottom of the control, the pagination is nice and proper.

What is Grasshopper Without Linux?



Figure 35: The Java build category of the project property allows us to change the deployment method from Incremental to Full deployment package (WAR). The default value in Debug_Java configuration is set incremental to shorten the development cycle and is set to WAR in Release_Java configuration to create a full deployment package.

Now that our application is ready, we can deploy it on a Linux machine. First, we need to create the deployment package, which is as easy as switching your configuration from Debug_Java to Release_Java. By default, the deployment method in the Release configuration is set to Full deployment package (WAR) (see Figure 35) and creates a production-ready WAR deployment package. Our WAR file is created under the bin directory JDExpenses\bin\JDExpenses.war and is 22 Mbytes big, since it contains all Grasshopper Framework libraries. When you deploy several applications on the same server, you would probably prefer to move the Framework libraries to the shared classpath.

To run the application on Linux, Tomcat must be installed; in all likelihood we will also need to make some small changes. By default, almost all distributions of Linux use a version of Tomcat featuring JDK 1.4.2; however, we developed the JDTravel class using JDK 1.5.0, and we therefore need to install it and configure the application server to suit. From the Sun download site, download JDK 1.5.0 for Linux (the version with the .bin extension) and install it on the machine simply by launching the file. Let us say it was installed in /opt/jdk1.5.0_06; on most Linux installations it will be sufficient to change the JAVA_HOME variable to suit, before launching Tomcat, with:

export JAVA_HOME=/opt/jdk1.5.0_06



Figure 36: The Tomcat version included in the Red Hat Linux distributions allow modification of the JAVA_HOME variable from the configuration file.

In order to avoid having to carry out this procedure before each run, we need simply to modify the Tomcat launching script. In the case of Red Hat Linux, the featured Tomcat version offers a simpler and faster method. All you have to do is open the /usr/share/tomcat5/conf/tomcat5.conf file and modify the JAVA_HOME row (Figure 36).

Copy the WAR package on the Linux machine – for example, through a Samba share – and deploy it using the Tomcat Manager (Figure 37). Do not forget that in order to be able to access the Tomcat Manager, you need to create a user for the manager role in /usr/share/tomcat5/conf/tomcat-users.xml! Since we wish to use the SQL Server, copy the corresponding JDBC driver, sqljdbc.jar, from \java_refs\jdbc in Windows to /usr/share/tomcat5/common/lib in Linux, and restart Tomcat. Launching the application will result in JDExpenses finally running on Linux (Figure 38), with the report of the speakers' balances populated by SQL Server 2005!



Figure 38: A report created with an ASP.NET 2.0 control, populated with data retrieved by SQL Server 2005 running on a Red Hat Enterprise Linux. Wasn't it worth it? :-)



Figure 37: The Tomcat Manager allows us to easily deploy the WAR package created by the Deployment Packager.

Now that our application has been deployed on Linux, we can use the remote debugging capabilities offered by Grasshopper and track our Linux application runtime from the Visual Studio debugger windows. First, configure the Tomcat instance running on Linux for debugging. In order to do so, suspend Tomcat, if it is running, and type the following commands in a prompt:

set JAVA_HOME=
set JPDA_ADDRESS=8019
set JPDA_TRANSPORT=dt_socket
cd \bin
catalina.bat jpda start

Figure 39: Configurations required for remote debugging in the Debug tab of the Project Properties.

Back in Visual Studio, right-click the project name in Solution Explorer and choose Properties. A new page will open in the IDE, with several project configurations; click the Web tab and specify (Figure 39):

  • The IP address of the remote machine (select the check box in Start action).
  • The debug port number that you specified in the JPDA_ADDRESS value.

The last thing to do is to start the SQL Server Browser service, which is used by the Grasshopper runtime to locate the SQL Server Express database by the IP address you specified in the connection string, and to connect to it. To make sure that the SQL Server Browser Service is running, launch the Computer Management again, expand Services and Applications, and then click Services. In the list of services, double-click SQL Server Browser, and in the SQL Server Browser Properties window, click Start.

Figure 40: For remote debugging, we have same options as for local one.

Now, we just need to add a breakpoint in the specified page and start the remote application, performing all steps needed to reach the page where a breakpoint has been set. The Grasshopper debugger will stop the execution at the row you designate (Figure 40).

Conclusion

We hope you enjoyed this tour of Grasshopper 2.0, which shows how to extend your ASP.NET 2.0 skills to open systems using cross-platform development. To recap, we operated entirely inside the Visual Studio 2005 IDE; we used advanced ASP.NET 2.0 controls; and we used an integrated debugger, both on the local and the production machines. Grasshopper 2.0 produced a deployment package that required little configuration and minimal knowledge to deploy on a non-Windows platform. There were only a few particulars (i.e., using SQL Server 2005 from a non-Windows platform), and just TWO lines of code that we wrote that were different from "traditional" ASP.NET 2.0 project development. The Derby pure Java database and Grasshopper Site Administration Tool offer a rich Visual Studio-like experience and also enable you to use advanced features such as role-based Membership. The output, native Java bytecode, offers ease of use, high portability and a level of performance that would be difficult to achieve using "traditional" Web Services.