Difference between revisions of "Xebra Master Pages"

(Controllers)
Line 47: Line 47:
  
 
===Controllers===
 
===Controllers===
 +
Controllers can still be defined on a per .xeb base. If not overwritten by implementors the controller is inherited.
 +
Templates can also be used to separate authenticated from unauthenticated content. If we take the example from above we can add access restriction by defining two regions and restricting the access to them:
 +
 +
<xml>
 +
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 +
<html xmlns="http://www.w3.org/1999/xhtml">
 +
<page:controller class="LOGIN_CONTROLLER" />
 +
<head>
 +
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 +
<title>Foo</title>
 +
</head>
 +
<body>
 +
<img href="logo.gif/>
 +
<xeb:container render="%=authenticated">
 +
<page:region id="auth_content" />
 +
</xeb:container>
 +
<xeb:container render="=%not_authenticated">
 +
<page:region id="not_auth"content" />
 +
</xeb:container>
 +
</body>
 +
</html>
 +
</xml>

Revision as of 09:32, 31 July 2009

Basics

Xebra Server Pages (.xeb) can be modularized with master pages (or templates). Usually a page has different regions which are dynamic and others which are static. These regions can be modeled with xebra. To illustrate this we use a small example of a page with a static logo and a dynamic content. First we define the static master page (master.xeb):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//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>Foo</title>
</head>
<body>
<img href="logo.gif"/>
<page:declare_region id="dynamic_content" />
</body>
</html>

and a concrete page which includes this master page (slave.xeb):

<page:include template="master">
<page:define_region id="dynamic_content">
Some Content
</page:define_region>
</page:include>

If we compile and display we will get the following page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//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>Foo</title>
</head>
<body>
<img href="logo.gif"/>
Some Content
</body>
</html>

Quite obviously the declared region in master.xeb is filled with the defined region of slave.xeb. Notice that master.xeb will not be transformed to a servlet and will not be accesible from the browser since it is not complete. Multiple regions can be declared per template. Furthermore including xeb pages can themselves declare new regions or transitively delegate their not implemented regions to their implementors.

Controllers

Controllers can still be defined on a per .xeb base. If not overwritten by implementors the controller is inherited. Templates can also be used to separate authenticated from unauthenticated content. If we take the example from above we can add access restriction by defining two regions and restricting the access to them:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<page:controller class="LOGIN_CONTROLLER" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Foo</title>
</head>
<body>
<img href="logo.gif/>
<xeb:container render="%=authenticated">
<page:region id="auth_content" />
</xeb:container>
<xeb:container render="=%not_authenticated">
<page:region id="not_auth"content" />
</xeb:container>
</body>
</html>