How To Load AppThena Objects in a JSP


This article shows you how to use the Model directly from a JSP without having to use AppThena's Controller or the standard GUI.

This is useful if you want to use AppThena as the model in a different model/view/controller implementation such as Apache Struts™. It's also handy when you want to add small amounts of data to existing web pages.

If you need to load an object in a JSP which is the Controller is using as a view then follow the example in How To Load AppThena Objects in a View instead. Do not use the pattern in this document as you will run into problems with the Model's transaction.

A Note on TagLibs

The release version of AppThena will include a JSP tag library that will make this task simpler. The tag library will allow you to load objects without using scriptlets (embedded Java). For example,

  <app:object var="myPage" type="page" key="4">



The solution is to instantiate the AppThena Model object using PluginManager.getModel() and then ask it to load the object you want using Model.getObject().

You need to know the type and key of the object you wish to load. The easiest way to find these is to open the object in the standard Edit screen and examine the page source. The type and key are shown in hidden form values. e.g.

<form id="form_EDIT_dbo.Directory" method="post" action="/autoedit/">
  <fieldset class="wrapper">
    <input name="antiCSRFPostToken" type="hidden" value="" />
    <input name="o.currentAction" type="hidden" value="EDIT" />
    <input name="o.action" type="hidden" value="undefined" />
    <input name="o.modified" type="hidden" value="false" />
    <!-- Note that key will be empty if this is a new unsaved object -->
    <input name="o.key" type="hidden" value="4" />
    <input name="o.type" type="hidden" value="dbo.Directory" />


This example is a complete JSP. You'll need to change the object type, its key and the name of the properties that are displayed in order to make it work with your system.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<%@ page session="true" contentType="text/html;charset=ISO-8859-1" %>
<%@ page import="com.glasspaw.appthena.*,*" %>
<%@ page import="com.glasspaw.appthena.utils.*,com.glasspaw.appthena.model.*" %>
<%@ taglib uri="" prefix="c" %>
<html xmlns="" xml:lang="en" lang="en">
  <title>This Object Was Loaded Directly from the Model</title>
<%-- Warning: The widespread use of escapeXml() is intended to prevent
     page corruption and cross site scripting attacks from user supplied
     data. No attempt is made to exclude values that can't be modified by
     the user out of paranoia. --%>
    // Load the Model to get access to the database ...
    Model model = PluginManager.getModel();
    // ... and start a database transaction

    // The context passes messages and objects between the JSP and
    // any registered event handlers.
    ModelEventContext context = new ModelEventContextImpl(request);

    // Ask the model to load an object
    // You must know the type and key of the object
    ObjectInfo directoryObject = model.getObject("dbo.Directory", "1", context);

    // Stash the object so that we can get at it with JSTL etc
    pageContext.setAttribute("directory", directoryObject);
  <h1>This Object Was Loaded Directly from the Model</h1>
  <!-- We can now read the object's data members and navigate to it's properties.
       See ObjectInfo class for details of accessors. -->
  <table border="1">
      <tr><th>Type Name</th><td>${}</td></tr>
      <tr><th>Type Display Name</th><td>${directory.type.displayName}</td></tr>
      <tr><th>Name Property</th><td>${["Title"]}</td></tr>
  <h1>Access Our Object Without JSTL</h1>
  <table border="1">
        <th>With jsp:getProperty</th>
        <td><jsp:getProperty name="directory" property="key"/></td>
        <th>With scriptlet</th>
        <td><%= directoryObject.getProperty("Id").getValue() %></td>
    // Save any changes to the database. Use rollback() to abandon changes.