Skip to main content

Using Inheritance in Web Pages

If we make Utils a super class of ShowTimes, then we can access all of the methods defined within Utils, including AddShow, within ShowTimes using the convenient ..MethodName syntax.

To indicate this relationship, we define Utils as a super class of our page, through the super attribute in the <csp:class> tag. This enables ShowTimes to use any method defined in the Utils class.

Note that we do not need to make ShowTimes a subclass of Utils. Since AddShow is a class method, we can access it within ShowTimes using either the ##class(PackageName.ClassName).MethodName syntax or the PackageName.ClassName.MethodName syntax depending on the context. Neither of these approaches requires that Utils be a superclass of ShowTimes. However, the syntax is slightly less convenient than our ..MethodName.

—ShowTimes.csp—
ShowTimes.csp
<html> <body>
<csp:class encoded=1 super="%CSP.Page,Cinema.Utils">

<csp:query 
        name="Times" 
        classname="Show" 
        queryname="ShowTimes" 
        P1='#(%request.Data("FilmID",1))#'>
<csp:object 
        name="Film" 
        classname="Cinema.Film" 
        objid='#(%request.Data("FilmID",1))#'>

<font> <b>Today's Show Times for #(Film.Title)#</b></font>

<table cellpadding=5>
    <tr>
    <td><b>Time</b></td>
    <td><b>Theater</b></td>
    </tr>
<csp:while condition="Times.Next()">
    <tr>
    <td>#(Times.GetDataByName("StartTime"))#</td>
    <td>#(Times.GetDataByName("TheaterName"))#</td>

    </tr>
</csp:while>
</table>
</body> </html>
FeedbackOpens in a new tab