PDA

View Full Version : Resolved seperation of concerns (HTML - ASP)


FabriceB
11-09-2010, 10:45 PM
Hi!
This is as much of a discussion then question I suppose and I am also uncertain that this is the right place to ask but here goes...

I'm learning (in school) at the moment about separations of concerns and see some of the benefits so I'd like to try and see if it could pay off here as well.

I am trying to clean up the codes that were developed here which are mainly done in ASP. (At school we're learning JSP)

In JSP I noticed that most of the HTML page was free of code. There was really the minimum present (i.e.: access to information through RS)

Here is what I am wondering, is there a way to do the same with ASP?

With a page like this one:


<!--#include virtual="\common\asp\functions.asp"-->
<!--#include virtual="\common\classes\asp\connectionmanager.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Outage Tool</title>
</head>
<%
if not (HasRight("42-SMST_Report") or HasRight("42-SMST_Coordinator_Report")) then DieSecurityError
dim conn, sp, pageNameOfThisPage, phrases,rsP
dim rs, WTS_isEmpty,arrH , arrM
WTS_isEmpty = session("WTS_RSisEmpty")

if not WTS_isEmpty then
set rs = session("WTS_recordset")
end if

function IIf( expr, truepart, falsepart )
IIf = falsepart
If expr Then IIf = truepart
end function

function condIf( expr, expr2, expr3, truepart1, truepart2, truepart3 )
condIf = ""
If expr Then condIf = truepart1 end if
If expr2 then condIf = truepart2 end if
If expr3 then condIf = truepart3 end if
end function

pageNameOfThisPage = "default"

set conn = new connectionManager

sp = "SELECT phraseid, phrase FROM Tbl_Form_SMST_Phrases " _
& " WHERE (pageid IS NULL OR pageid = '" & pageNameOfThisPage & "' " _
& ") AND language = '" & Session("language") & "'"

conn.storedprocedure = sp
'response.write(sp)
conn.connect

Set phrases = Server.CreateObject("Scripting.Dictionary")

if conn.hasErrorOccured then
response.write("<div class='error'>")
response.write(conn.messageString)
response.write("</div>")
else
set rsP = conn.recordset
If rsP.EOF Then Response.Write "NO RECORDS in rsP recordset<hr>"
Do Until rsP.EOF
pid = rsP("phraseid")
ph = rsP("phrase")
'Response.Write pid & "::" & ph & "<br/>" & vbNewLine
phrases.Add LCase(pid), ph
rsP.MoveNext
Loop
set rsP = nothing
end if


'------------------------------ SystemTool_id Selection --------------------------------------------------
if not isObject(session("sysSelect")) then

sp = "SELECT SystemTool_id, SystemTool_Name FROM Tbl_Form_SMST_System_Dim WHERE (Language IS NULL) OR Language = '" & Session("language") & "'"

conn.storedprocedure = sp
conn.connect

if not conn.hasErrorOccured then
session("sysSelect") = conn.getrows
else
response.write("<div class='error'>")
response.write(conn.messageString)
response.write("</div>")
end if

end if
'------------------------ Ending SystemTool_id selection -------------------------------------------------
'------------------------ network Selection --------------------------------------------------
if not isObject(session("netSelect")) then

sp = "SELECT network_id, network_Name FROM Tbl_Form_SMST_Network_Dim"

conn.storedprocedure = sp
conn.connect

if not conn.hasErrorOccured then
session("netSelect") = conn.getrows
else
response.write("<div class='error'>")
response.write(conn.messageString)
response.write("</div>")
end if

end if
'------------------------ Ending Department selection -------------------------------------------------
'------------------------------ SystemTool_id Selection --------------------------------------------------
if not isObject(session("provSelect")) then

sp = "SELECT province_id, province FROM Tbl_Form_SMST_Provinces_Dim WHERE (Language IS NULL) OR Language = '" & Session("language") & "'"

conn.storedprocedure = sp
conn.connect

if not conn.hasErrorOccured then
session("provSelect") = conn.getrows
else
response.write("<div class='error'>")
response.write(conn.messageString)
response.write("</div>")
end if

end if
'------------------------ Ending SystemTool_id selection -------------------------------------------------
'------------------------------ Service Selection --------------------------------------------------
if not isObject(session("servSelect")) then

sp = "SELECT service_id, service_name FROM Tbl_Form_SMST_Service_Dim WHERE (Language IS NULL) OR Language = '" & Session("language") & "'"

conn.storedprocedure = sp
conn.connect

if not conn.hasErrorOccured then
session("servSelect") = conn.getrows
else
response.write("<div class='error'>")
response.write(conn.messageString)
response.write("</div>")
end if

end if
'------------------------ Ending SystemTool_id selection -------------------------------------------------
'------------------------------ Service Selection --------------------------------------------------
if not isObject(session("escSelect")) then

sp = "SELECT escalate_id, escalate_name FROM Tbl_Form_SMST_Escalate_Dim WHERE (Language IS NULL) OR Language = '" & Session("language") & "'"

conn.storedprocedure = sp
conn.connect

if not conn.hasErrorOccured then
session("escSelect") = conn.getrows
else
response.write("<div class='error'>")
response.write(conn.messageString)
response.write("</div>")
end if

end if
'------------------------ Ending SystemTool_id selection -------------------------------------------------
dim link
link = Request.ServerVariables("URL")



%>
<link rel="stylesheet" type="text/css" href="smst.css">
<style type="text/css">@import url(datepicker.css);</style>
<script language="javascript" src="/common/javascript/jquery/jquery-1.2.6.min.js"></script>
<script language="javascript" src="/common/javascript/jquery/jquery.blockUI.js"></script>
<script type="text/javascript" src="smst.js"></script>
<body >
<div id="MainPage" >
<form id="form" name="form" action="details.asp" method="get" onsubmit="return fn_validate()">
<div id="bannerDIV">
<p align="center"><img id="banner" name="banner" src="<%=phrases("bannerurl")%>" width=600 height=50 /></p>
<div id="lineList">
<ul class="left">
<li> <a href="default.asp"><%=phrases("inline1")%></a></li>
<li> <a href="itsc.asp"><%=phrases("inline2")%></a></li>
<li> <a href="noc.asp"><%=phrases("inline3")%></a></li>
<li> <a href="smst.asp"><%=phrases("inline4")%></a></li>
<li> <a href="mailto:Fido-System.ManagementandSupport@rci.rogers.com?subject=Signaler Problème"><%=phrases("inline5")%></a></li>
</ul>
</div>
</div> <!-- end of Banner Div -->
<div id="ticketEntry" dir="ltr" style="float:left;width:960px">
<div>
<table>
<tr>
<td>
<label class="inputs"><strong><%=phrases("ticket")%></strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("Ticket_Id")) ,"" , rs("Ticket_Id"))) end if %><br/>
<label class="inputs"><strong><%=phrases("master")%></strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("SMSTTicket_Id")) ,"" , rs("SMSTTicket_Id"))) end if %> <br/>
<label class="inputs"><strong><%=phrases("system")%> </strong></label><% If WTS_isEmpty = false then response.write(IIF(isNull(rs("System_selected")) ,"" , rs("System_selected"))) end if %> <br/>
<label class="inputs"><strong><%=phrases("network")%></strong></label><% If WTS_isEmpty = false then response.write(IIF(isNull(rs("Network_selected")) ,"" , rs("Network_selected"))) end if %> <br/>
<label class="inputs"><strong><%=phrases("province")%></strong></label><% If WTS_isEmpty = false then response.write(IIF(isNull(rs("Province_selected")) ,"" , rs("Province_selected"))) end if %> <br/>
<label class="inputs"><strong><%=phrases("service")%></strong></label><% If WTS_isEmpty = false then response.write(IIF(isNull(rs("Service_selected")) ,"" , rs("Service_selected"))) end if %> <br/>
<label class="inputs"><strong><%=phrases("estarttime")%> </strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("Start_Date")) , "", rs("Start_Date"))) end if%> <% response.write(" " & rs("Start_Time")) %><br/>
<label class="inputs"><strong><%=phrases("eendtime")%> </strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("End_Date")) , "", rs("End_Date"))) end if%> <% response.write(" " & rs("End_Time")) %><br/>
<label class="inputs"><strong><%=phrases("etr")%> </strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("etr")) , "", rs("etr") )) end if%> <br/>
<label class="inputs"><strong><%=phrases("escalate")%> </strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("escalate_name")) ,"" , rs("escalate_name"))) end if %> <br/>
<label class="inputs"><strong><%=phrases("severity")%> </strong></label><%if not WTS_isEmpty then response.write( condIf( rs("severity")=1, rs("severity")=2, rs("severity")=3, phrases("serverity1"), phrases("serverity2"), phrases("serverity3") ) ) end if %><br/>
<label class="inputs"><strong><%=phrases("example")%> </strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("examples")) , "", rs("examples"))) end if%><br/>
<label class="inputs"><strong><%=phrases("status")%> </strong></label><%if not WTS_isEmpty then response.write( condIf( rs("status")=1, rs("status")=2, rs("status")=3, phrases("status1"), phrases("status2"), phrases("status3") ) ) end if %><br/>
<label class="inputs"><strong><%=phrases("detail1")%>: </strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("alert_msg")) , "", rs("alert_msg"))) end if %><br/>
<label class="inputs"><strong><%=phrases("detail5")%>: </strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("RootCause")) , "", rs("RootCause"))) end if %><br/>
<label class="inputs"><strong><%=phrases("input1")%>: </strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("Description")) , "", rs("Description"))) end if%><br/>
<label class="inputs"><strong><%=phrases("input2")%>: </strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("Positioning")) , "", rs("Positioning"))) end if%><br/>
<label class="inputs"><strong><%=phrases("input3")%>: </strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("WorkAround")) , "", rs("WorkAround"))) end if%><br/>
<label class="inputs"><strong><%=phrases("input4")%>: </strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("CxImpact")) , "", rs("CxImpact"))) end if%><br/>
<label class="inputs"><strong><%=phrases("input5")%>: </strong></label><%If WTS_isEmpty = false then response.write(IIF(isNull(rs("history")) , "", rs("history"))) end if%><br/>
</td>
</tr>
</table>
</div>
</div> <!-- end of ticketentry -->
<input type="hidden" id="actionState" name="actionState" <%response.write(IIF(request("actionState") <> "" , "value=" & request("actionState"),"")) %> />
</form>
</div>
</body>
</html>

<% set conn = nothing
set detailsRS = nothing %>

Is there anything that could be done?

(In this particular case, I'm really inquiring about the code in between head and body

Old Pedant
11-10-2010, 01:37 AM
Not really.

ASP.NET, yes.

But ASP is the oldest of the server-side technologies in this vein. (I *think* it even pre-dates PHP.) And it has really never been improved.

Oh, you *CAN* create files that you #include into the page, so that at least you have the *appearance* of not much scripting in the page. But it's really all still there. In fact, ASP works but doing the #include's *FIRST*--the same as you could do by copy-pasting the text from the include file in place. Then it passes it through the ASP "engine" that strips out all the <% ... %> and converts the text (yes, still text) into code that is 100% VBScript language (or JScript language, though that's less commonly used). Finally, the VBScript "engine" is passed this text (same as if you had invoked VBScript from the DOS command line, essentially) all as a single file (or pseudo-file). VBS compiles the script into a tokenized form and only *then* does it run an interpreter engine that "executes" the tokens.

All of this is done like this so that, if there is room in memory, the tokenized form is cached by the server. That way the #include processing, the conversion from <%...%> form to pure text, and the compiling are all avoided on subsequent re-uses of the same page.

But in the end, it means that, for all intents and purposes, your ASP pages must be thought of as one big bunch of text. Non-modular.

Actually, the original JSP started out this way. And to a very large degree, PHP is still this way. JSP has evolved the most, as you have noted. In the case of ASP, MicroSlop decided it was better to abandon the scripting technology and go to a fully compiled model, which is what ASP.NET is. And that's why you'll find similarities between ASP.NET and modern JSP. The similarities under the covers are actually more than skin deep, but the actual coding used doesn't look all that close.

Old Pedant
11-10-2010, 01:40 AM
Aha.

officially released PHP/FI 2 in November 1997

ASP was one of the first web application development environments that integrated web application execution directly into the web server, 9 months after the 1996 release of NeXT's (now Apple) WebObjects

So, really, ASP and PHP were in original development at the same time. So in that regard, it's kind of amazing that they are as close in nature as they are.