Markup-Behind model is a mechanism for separating the programming logic and presentation in a web application.

Web request is processed by a combination of two types of pieces: the code piece which provides programmatic, navigational and business logic; and the markup piece which provides presentation output.

As opposed to Code-Behind model, where the target of navigation is the markup piece, in Markup-Behind the target is the code piece.

There are three distinctive properties of Code-Behind:

Markup-Behind model allows for more possibilities in processing server requests, such as

Because the code piece has all the programmatic versatality, it is possible to load different additional code components depending on events, processing and state, in addition to rendering different markups.

Because the code piece is the target of navigation and also a web handler, its granularity can range from a single hub handler (such as Wiki) to separate targets for different URLs as in traditional one code piece per markup approach.

Examples

For live example, see Grouped Params screen in the JHP demo.

For a more detailed/extensive login example see User Login.


In-line code would look like this

test.jhp

<% ContentType 'text/html' %>
<html><body>
<% 
  UserId=: qcookie 'UserID'
  LoggedIn=: 0<#UserId
%>
<div> Test App </div>
<% if. LoggedIn do. %>
  <p>Hello, <span><%=UserId%></span></p>
<% else. %>
  <p>User: <input name=UserId></p>
  <p>Password: <input type=password name=Password></p>
  <p><input type=submit></p>
<% end. %>
<div> Copyright </div>
</body></html>


Code-Behind code would look like this

test.jhp

<% ContentType 'text/html' %>
<html><body>
<% load 'test.ijs' %>
<div> Test App </div>
<% if. LoggedIn do. %>
  <p>Hello, <span><%=UserId%></span></p>
<% else. %>
  <p>User: <input name=UserId></p>
  <p>Password: <input type=password name=Password></p>
  <p><input type=submit></p>
<% end. %>
<div> Copyright </div>
</body></html>

test.ijs

  UserId=: qcookie 'UserID'
  LoggedIn=: 0<#UserId


Markup-Behind code would look like this

test.jhp

<% ContentType 'text/html'
UserId=: qcookie 'UserID'
LoggedIn=: 0<#UserId
if. LoggedIn do. markup '~CGI/test.html'
           else. markup '~CGI/login.html' end. %>

test.html

<html><body>
<div> Test App </div>
  <p>Hello, <span><%=UserId%></span></p>
<div> Copyright </div>
</body></html>

login.html

<html><body>
<div> Test App </div>
  <p>User: <input name=UserId></p>
  <p>Password: <input type=password name=Password></p>
  <p><input type=submit></p>
<div> Copyright </div>
</body></html>

History

RicSherlock made initial proposal to separate business logic and presentation for JHP markup engine by putting the code piece first, and invoking markup processing as a separate step, which made possible post-rendering, state-reuse and markup preservation. OlegKobchenko recognized the distinctive features of this approach, identified "Markup-Behind" as a separate procesing model and participated in implementing the support for it in JHP.

See Also

Web/Markup-Behind (last edited 2008-12-08 10:45:50 by )