AqDWeb : AdvancedControls

HomePage :: Categories :: PageIndex :: Login/Register
HomePage - Tutorials - Advanced Controls and Validations

Advanced Controls and Validations

image ForEach Control

A replacement for asp:repeater, in order to support custom attributes:
<%@ Register TagPrefix="aqd" Namespace="AqDWeb.Controls" %>
<!-- A list of users -->
<aqd:forEach runat="server" id="userList" bind-source="Users"
    dataVarName="usr" indexVarName="usrNum">

    <itemTemplate>
        ${#usrNum}: ${usr.Name} <br/>
    </itemTemplate>
</aqd:forEach>
As you can see it's just like repeater. The dataVarName and indexVarName are to set the names of the item variable and of the index variable (begins from 0) for your controls in <itemTemplate>, by default their values are "data" and "index" if you don't specify. Now, you may also specify the bindings for <itemTemplate>:
<%@ Register TagPrefix="aqd" Namespace="AqDWeb.Controls" %>
<!-- A list of users whose ages are smaller than 10 -->
<aqd:forEach runat="server" id="kidList" bind-source="Users"
    dataVarName="usr" indexVarName="usrNum"
    bindItem-id="#usr.ID" bindItem-visible="#usr.Age < 10">

    <itemTemplate>
        ${#usrNum}: ${usr.Name} <br/>
    </itemTemplate>
</aqd:forEach>
Note the index variable usrNum is set before bindItem-visible is evaluated, so those whose ages are equal or more than 10 in the Users are still counted for index - but only set to hidden in the final output. The bindItem-id isn't necessary, but you have better to set it to something that can uniquely identify your control for its corresponding model object (such as usr.ID), especially when there are two-way binding controls inside <itemTemplate> - in case the Users data are changed before postback (more users added or re-ordered).

image Scope Control

To help you declare variables in OGNL context:
<%@ Register TagPrefix="aqd" Namespace="AqDWeb.Controls" %>
<aqd:scope runat="server" bVar-sess="#context.Session"
    bVar-cookies="#request.Cookies">

    Session count: ${#sess.Count}
    Cookies count: ${#cookies.Count}
</aqd:scope>
You can achieve a similar result by using OGNL expression like "#sess = #context.Session", but then it wouldn't be confined in the place where you define it.
<%@ Register TagPrefix="aqd" Namespace="AqDWeb.Controls" %>
<aqd:scope runat="server" bVar-myvar="'a'">
    <aqd:scope runat="server" bVar-myvar="'b'">
        <!-- Display "b" -->
        Variable myvar: ${#myvar}
    </aqd:scope>
    <!-- Display "a" -->
    Variable myvar: ${#myvar}
</aqd:scope>
<!-- Give error because #myvar doesn't exist. -->
Variable myvar: ${#myvar}

image Validations

You should already know about ASP.NET validations, so we'll jump to the more advanced thing: Validation Groups
<body runat="server" validationGroup="page">
    <div runat="server" id="SearchPanel" validationGroup="search">
        <b>Search:</b>
        <!-- SEARCH INPUT -->
        <input runat="server" id="SearchBox" bind-value="SearchInput"/>
        <asp:requierdFieldValidator run="server" controlToValidate="SeachBox"
            text="Give some chars you dude!"/>

        <!-- SEARCH BUTTON -->
        <input runat="server" id="SearchButton" type="submit" ext-serverClick="Search()"/>
    </div>

    <h2>User Profile</h2>
    <!-- USER NAME INPUT -->
    Name: <input runat="server" id="UserNameBox" bind-value="User.Name"/>
    <asp:requierdFieldValidator run="server" controlToValidate="UserNameBox"
        text="Name!!!"/>
<br/>
    <!-- USER AGE INPUT -->
    Age: <input runat="server" id="UserAgeBox" bind-value="User.Age"/>
    <asp:requierdFieldValidator run="server" controlToValidate="UserAgeBox"
        text="Age!!!"/>

    <asp:regularExpressionValidator run="server" controlToValidate="UserAgeBox"
        validationExpression="^[0-9]+$" text="Don't be stupid!"/>
<br/>
    <!-- USER SEX INPUT -->
    Sex:
    <input runat="server" type="radio" name="UserSexSelection"
        value="Boy" bind-checked="User.Sex == 'male'"
        ext-select="User.Sex = 'male'"/>

    <input runat="server" type="radio" name="UserSexSelection"
        value="Girl" bind-checked="User.Sex == 'female'"
        ext-select="User.Sex = 'female'"/>

    <!-- SUBMIT FOR USER -->
    <input runat="server" id="SubmitButton" type="submit" ext-serverClick="SaveUser()"/>
</body>
In the above code you can see two validation groups: search and page - the purpose of validation group was simply to prevent the SearchBox's validator come up when you click on the User profile's SubmitButton and so on. Unlike the old ASP.NET, you no longer need to set validation group in every input and in every validators - instead, you can set it in any server-side controls (<div runat="server"> for example), and the validation group will be passed down to every of its children and finally your inputs and validators, unless they change it otherwise. Second, since AqDWeb fills your form data to model objects automatically when you post back, validation groups are now also being used to specify what parts of inputs should be filled. For example, when you write Age = "hello" in the bottom UserAgeBox, and then do a simple search - they're different validation groups and thus the Age's validator doesn't come up, but what's more important is the UserAgeBox's value you wrote does not be sent into User.Age, even if you're not going to save it (remember User.Age is an interger and cannot accept "hello").
SourceForge.net Logo
Valid XHTML 1.0 Transitional :: Invalid CSS :: Powered by Wikka Wakka Wiki 1.1.6.1
Page was generated in 0.1008 seconds