Monthly Archives: February 2011

URL Rewriter

The concept of rewriting URLs in XAF turned out to be quite a beast. The major trouble we had to tackle was navigating to specific session objects/views with a rewritten address.

An example is the “Current Order” of a storefront.

If you want to navigate to the current order of a session, you need to know the session ID. Well, if you wanted this page to be masked as cart.aspx, you would need to know the session ID prior to loading and detail view/page items.

This provided to be difficult because there was no Session ID available in the URL Re-writer so we couldn’t persist the object directly from the re-writer.

It came down to adding a property to the authentication object and getting that property from the application.

XPO Upcasting & Downcasting

In XPO, when working with persistent objects, a filter allows you to upcast and downcast data.

Consider the following example:

Public Class Contact
    Inherits BaseObject

    Public Sub New(ByVal session As Session)
        MyBase.New(session)
    End Sub

    Private _mFirstName As String
    Private _mLastName As String
    Private _mMiddleName As String

    Public Property FirstName() As String
        Get
            Return _mFirstName
        End Get
        Set(ByVal value As String)
            If String.Compare(_mFirstName, value, False) = 0 Then
                Return
            End If
            _mFirstName = value
        End Set
    End Property
    Public Property LastName() As String
        Get
            Return _mLastName
        End Get
        Set(ByVal value As String)
            If String.Compare(_mLastName, value, False) = 0 Then
                Return
            End If
            _mLastName = value
        End Set
    End Property
    Public Property MiddleName() As String
        Get
            Return _mMiddleName
        End Get
        Set(ByVal value As String)
            If String.Compare(_mMiddleName, value, False) = 0 Then
                Return
            End If
            _mMiddleName = value
        End Set
    End Property
End Class

Public Class Developer
    Inherits Contact

    Private _mLanguage as String
    Public Property Language As String
        Get
            Return _mLanguage
        End Get
        Set(Byval value As String)
            _mLanguage = value
        End Set
    End Property

End Class

When filtering these objects, you can filter developers based on their contact information, but you can also filter contacts based on their developer information, if they are example

Dim cntFilterForContact As New BinaryOperator("Language", "VB.NET")
Dim cntFilterForDeveloper As New BinaryOperator("Language", "VB.NET")

The filters can be used appropriately against the Contact or the Developer object to retrieve all developers who code in VB.NET. Very efficient stuff :)