26.3. Sending Form Data

The XSLT document you created in the previous section created HTML that works with any HTML-3.2-compliant browser. You will transmit the form data as usual, by using the browser’s HTTP capabilities. New capabilities in Microsoft’s Internet Explorer version 5.0+ and Netscape version 6.2+ allow the XML to be sent directly to and from the browser. These capabilities are certainly the direction that Internet devices should take in the future.

Unfortunately, you cannot be certain that all users will be using XML-compliant browsers, so you will continue to send the data by using HTML standards in our case study.

After you send the data, you must commit to a server development framework. The CRSS case study is going to use Microsoft’s .NET Framework. This section looks at how to receive the client request by using ASP.NET. You should carefully consider certain features when choosing a framework. Defining what you are looking for in a Web application development framework will help. Ideal Web applications should have the following characteristics:

  • No broken links

  • No business logic in the Web tier

  • No database logic in the Web tier

  • Easy deployment from development to test to production

  • Ability to scale by using the selected framework

  • Ability to respond to any type of Web-enabled device

  • Ability to respond by using the correct cultural settings

Achieving all the characteristics in the preceding list is a bit beyond the scope of this case study. However, you will achieve the first five items, with the ability to do the sixth item readily apparent. We do not attempt to deal with the last item in this case study.

Accepting a client request assumes that you have installed the Microsoft .NET Framework on your Web server. Specifically, the following configuration is suggested:

  • Windows 2000 Professional or Server

  • IIS version 5 or later

  • .NET Framework installed

  • Visual Studio .NET is optional but quite useful

Note

Choosing a language for programming the .NET Framework is a matter of individual preference. The .NET Framework works with any language that is compliant with the Common Language Specification (CLS). Microsoft has submitted the specifications of C#, the runtime, the metadata, and the other parts of the .NET development platform to the European Computer Manufacturers Association (ECMA) for standardization. The specifications submitted to ECMA are available at http://www.dotnetexperts.com/ecma. ECMA is an international industry association founded in 1961 and dedicated to the standardization of information and communication systems. More information on ECMA is available at http://www.ecma.ch.


You develop the CRSS application by using Visual Basic .NET.

Assuming that you have successfully installed the framework as noted previously, you can now create your Web application. The steps are

1.
Open Visual Studio.NET.

2.
Create a VB.NET Web application.

3.
Open default.aspx and add one line of code.

4.
Test.

Start by creating a Visual Basic ASP.NET Web application called CRSS. Figure 26.10 shows how you can create a Visual Basic .NET Web project.

Figure 26.10. Creating a Web project in .NET.


You then create a new page called default.aspx as shown in Figure 26.11.

Figure 26.11. Adding default.aspx.


Open the default.aspx page. There are two tabs to choose from for viewing the page. Choose the HTML tab at the bottom of the screen. Delete all content except the first line, as shown in Figure 26.12.

Figure 26.12. Default.aspx HTML view.


You will not be using any Microsoft-specific client controls in your application. The application uses XSLT for all views, so no HTML is required on the page.

Now you need to add content to your Web application. Drag the XML and XSL files into folders created under the CRSS project, as shown in Figure 26.13.

Figure 26.13. Folder structure in CRSS Web project.


Note

You will want to download the files shown from http://www.XMLSchemaReference.com/examples/CRSS. Set up the folder structure as shown in Figure 26.13.


Next you need to add some code to the Page_Load event. Open the default.aspx.vb page by right-clicking on the default.aspx page and choosing View | Code. The code to begin testing your site is in Listing 26.14.

Listing 26.14. ASP.NET Listing for Default Page
 Option Explicit On 
 Option Strict On 
 Imports System.Xml 
 Imports System.Xml.Xsl 
 Imports System.Xml.XPath 

 Public Class Cdefault 
   Inherits System.Web.UI.Page 
 'AUTO GENERATED CODE REMOVED FROM THIS LISTING FOR BREVITY 
'Holds the final XML - UI XML and page data XML 
  Private o_FinalDoc As New XmlDocument() 
'Contains the application footer XML 
  Private o_appFooter As New XmlDocument() 
'Contains the application header XML 
  Private o_appHeader As New XmlDocument() 
'Contains the application menu XML 
  Private o_appMenu As New XmlDocument() 
'Contains the application style XML 
  Private o_appStyle As New XmlDocument() 
'Contains the page header XML  
  Private o_pageHeader As New XmlDocument() 
'Contains empty reservation request XML 
  Private o_msgReservationRequest As New XmlDocument() 

'Initialize the xslt objects you will need 
'used to hold the request reservation XSLT template 
  Private o_requestView As New XslTransform() 
'used to hold the approval XSLT template 
  Private o_approvalView As New XslTransform() 
'used to hold the calendar XSLT template 
  Private o_viewCalendarView As New XslTransform() 
'used to hold the pending requests XSLT template 
  Private o_viewPendingView As New XslTransform() 
'XSLT template to be used in final transformation 
  Private o_FinalView As New XslTransform() 

'Initialize fully qualified path to this web site 
  Private sServerPath As String 
  Private Sub Page_Load(ByVal sender As System.Object, _ 
             ByVal e As System.EventArgs) _ 
             Handles MyBase.Load 
  Try 
'get the fully qualified URL path to server root 
  sServerPath = "http://" & _ 
         Request.ServerVariables("SERVER_NAME") _ 
         & Request.ApplicationPath & "/" 

'Load the xml documents 
    o_appFooter.Load(sServerPath & "xml/appFooter.xml") 
    o_appHeader.Load(sServerPath & "xml/appHeader.xml") 
    o_appMenu.Load(sServerPath & "xml/appMenu.xml") 
    o_appStyle.Load(sServerPath & "xml/appStyle.xml 
'Put user code to initialize the page here 
    Dim req As String 
    req = Request.QueryString("req") 
    Select Case req 
      Case "request" 
        'do stuff 
      Case "approval" 
        'do pending work 
      Case "viewCalendar" 
        'show Calendar 
      Case "viewPending" 
        'view the Pending Work 
      Case Else 
        'create the final doc 
        o_FinalDoc.LoadXml("<crss><pageData/></crss>")   
        Dim oFinalNode As XmlNode = _ 
          o_FinalDoc.DocumentElement 
        'Update oFinalDoc with page data inputs 
        FinalNode.FirstChild.AppendChild _ 
           (o_FinalDoc.ImportNode( _ 
           o_msgReservationRequest.DocumentElement, 
           True)) 
        'Update oFinalDoc with inputs UI nodes 
        oFinalNode.AppendChild(o_FinalDoc.ImportNode 
             (o_appStyle.DocumentElement,True)) 
        oFinalNode.AppendChild(o_FinalDoc.ImportNode _ 
             (o_appHeader.DocumentElement,True)) 
        oFinalNode.AppendChild(o_FinalDoc.ImportNode _ 
             (o_pageHeader.DocumentElement,True)) 
        oFinalNode.AppendChild(o_FinalDoc.ImportNode _ 
             (o_appMenu.DocumentElement,True)) 
        oFinalNode.AppendChild(o_FinalDoc.ImportNode _ 
             (o_appFooter.DocumentElement,True)) 
        'Set the XSLT template to use 
        o_FinalView.Load(sServerPath & _ 
                "xslt/defaultView.xslt") 
        showPage() 
      End Select 
    Catch ex As Exception 
      'should log the exception 
      Response.AppendToLog(ex.Message) 
    Finally 
      'Cleanup any resources open 
    End Try 
  End Sub 

  Private Sub showPage() 
    Dim parmList As New XsltArgumentList() 
    Dim xWriter As New XmlTextWriter(Response.Output) 
    xWriter.Formatting = Formatting.Indented 
    xWriter.Indentation = 4 
    o_FinalView.Transform(o_FinalDoc, parmList, xWriter) 
  End Sub 
 End Class 

Listing 26.14 creates the basic framework for the CRSS application. Let’s review what this code is doing and then examine the pros and cons of this approach. The Page_Load event is called by the ASP.NET framework whenever the page is called. The XML CRSS user interface data is loaded using the load methods for each XML document. Remember, we chose to construct the final XML document programmatically, so you must load each of the XML documents and then create a final XML document that includes the UI XML data and the CRSS application XML data. The final data representation of the page is created by using the appendChild methods to concatenate the user interface data and dynamic data.

Each XSLT template contains a hidden form field with the next action to take in a variable, req. The case statement is used when the page is accessed. Each case statement will take action depending on the requested action. Finally, all case statements call the showPage subroutine, which writes the transformed result back to the client browser by using the ASP.NET Response object’s output stream.

The code in Listing 26.14 is more than we would like to see in the production CRSS application. All of this code can be moved into components. This is what you will be doing in the next chapter so the application will begin to comply with the design in our sequence diagram (see Figure 26.3).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.60.192