Samples

SamplesXml

Code

Config

API Docs

Download

Neolectric

Include - common dxp code

Most applications contain multiple pages. You can put common dxp code on a target page and include it at runtime. The included nodes behave as if they belong to the calling page. This is not a redirection or a forward to another page, you are actually calling the target page from the cache and accessing a particular set of nodes by their unique id so it's fairly efficient. You might think of this as the dxp alternative to calling local Java beans from a jsp page. A remote version is under development.

Include Sections from the target page in this page

<!-- first, store parameters required by the Section we are calling on the target -->
<dxp:Rp value="4" store="bid.id"/>
<dxp:Rp value="auction-form.txt" store="filename"/>

<!-- now include a node on the target page with the desired id attribute -->
<dxp:Include target="/dxp/sample/include-target.dxp" node="bid"/>
Your Last Bid
UserID:4
Email:johndoe@msn.not
Item:Eternal Battery
Bid date:07/12/01
Amount:
New Bid:
<!-- include a Section that has an id="all-bidders" -->
<dxp:Include target="/dxp/sample/include-target.dxp" node="all-bidders"/>
1mark@coldmail.comEternal Battery10.0007/01/01
2mark@coldmail.comStartup.com Stock5.0007/01/01
3mark@coldmail.comHerbal Youth Tonic20.0007/10/01
4johndoe@msn.notEternal Battery20.0007/12/01
5karl@youhoo.comEternal Battery100.0007/17/01
6mark@coldmail.comSuper WhamoBots8.0010/02/01
7rx8re3x@spambot.netStartup.com Stock32.0001/13/02
8japerry@jademicrosystems.comSuper WhamoBots56.0008/29/02

When you include a target page you are actually calling it from the cache maintained by the DxpServlet. Note the target attribute above:

target="/dxp/sample/include-target.dxp"
This begins with a / character and is actually the key that maps the target page in the cache. A target page is essentially a function library that does not have a logical page sequence. It contains a dxp:AuthInclude tag that allows nodes or sections to be included by other dxp pages but prevents the target page istelf from being called externally. Included nodes behave as if they belong on the calling page, not the target. If you want to pass parameter values to included nodes you need to store those values in your current request before calling the target. You can't pass them by appending them to the target attribute.

Here's what the target page we included looks like

<?xml version="1.0"?>
<dxp:DxpPage xmlns:dxp="dxp.neolectric.com" contentType="text" buffsize="0">
<dxp:AuthInclude/> <!-- can't be called externally but can be included -->

<dxp:Section id="bid"> <!-- query by id and insert the result into a template file --> 
 <dxp:DbAction value="query" dbcon="demo" store="record">
  <dxp:SqlStmt name="stmt">
   <dxp:Cp name="sql">select id, email, item, biddate, amount from auction where id=?</dxp:Cp>
   <dxp:SqlParam value="${bid.id}" type="NUMBER" require="true"/>
  </dxp:SqlStmt>
 </dxp:DbAction>
 <dxp:ReplaceChar token="$" value="${record}"> <!-- here is where it's stored -->
  <dxp:ReadText name="target" filename="dxp/sample/${filename}"/>
 </dxp:ReplaceChar>
</dxp:Section>

<dxp:Section id="all-bidders"> <!-- get all bidders --> 
 <dxp:DbAction value="query" dbcon="demo" store="bids">
  <dxp:Cp name="stmt">select * from auction</dxp:Cp>
 </dxp:DbAction>
 <table border="0" cellspacing="2" cellpadding="2" bgcolor="#999999">
 <dxp:LoopMatrix value="${bids}" cols="next" bgcolor="#ffffff,#eeeeff"> <!-- print all cols -->
 <tr bgcolor="${bgcolor}">
  <dxp:LoopArray value="${next}" cols="n"><td>${n}</td></dxp:LoopArray>
 </tr>
 </dxp:LoopMatrix>
 </table>
</dxp:Section>

</dxp:DxpPage>

Footnotes

A dxp:Section tag is a convenient way to refer to a block of code on a target page; it only has one function, to pass the request on to the child nodes it encloses. Some other dxp nodes that manage their own children can also be used on a target page. To use them, set a unique id attribute that identifies the top node in the group you want to include. Use a non-numeric value that will override the the default numeric id created by the node linker. dxp:UserAccess is a good candidate for this. It can protect a section of target nodes and require user privileges to access them.

Including sections on a target page provides a function that is similar to Java beans. Unlike calling beans, the method for getting values in and out of your target nodes is consistent with the rest of the dxp system; you don't have to map request values to bean properties. Target pages are also stored in the page cache so they will be removed from memory when they are not used for a while.