Adding a custom displayer to a report page
For any class in the model, custom JSP pages can be inserted into the report pages under the "Further information" section. These custom JSPs are referred to as "long displayers". The JSP has access to the InterMineObject instance being displayed. An example of this in FlyMine is the GBrowse viewer that is shown on gene report pages. Also, the various links to external databases are produced with long displayers.
Adding a long displayer
The basic steps to adding a long displayer are:
- Create a JSP in trunk/bio/webapp/resources/webapp/model/ or <MINE_NAME>/webapp/resources/webapp/model/
- Configure long displayer in <MODEL_NAME>/webapp/resources/webapp/WEB-INF/webconfig-model.xml
- See WebConfigModel for detailed information about this file.
If you want the JSP to have a controller (a Java action class that can create some attributes for the JSP) you should configure a tile. In this case the steps involved are:
- Create a JSP
- Create a Java action class that extends TilesAction.
- Configure long displayer in webconfig-model.xml
- specify the name of a tile rather than the path to the JSP page
- Add a tile definition to <MINE_NAME>/webapp/resources/tiles-defs-model.xml
How are the long displayers inserted?
All the information in webconfig-model.xml is read into an instance of WebConfig that is placed on the servlet context as attribute "WEBCONFIG" (see InitialiserPlugin). Look at objectDetails.jsp to find the JSP code that finds the long displayers for a given type and inserts them into the page with the <tiles:insert ..> tag.
Attributes available to the long displayer JSP
At the moment, these attributes are put on the request scope but in the future they will probably be moved to the tiles context scope (which will be neater) and the long displayer JSPs will have to use the <tiles:useAttributes/> tag to import attributes into the page scope.
object
the InterMineObject being displayed
cld
ClassDescriptor of the object being displayed
Creating a displayer that renders a generated image
At some point, you'll want a long displayer that renders some kind of generated image specific to the object being examined. A long displayer, created as described above can insert an <img...> tag onto the report page but it isn't clear how the image is generated. The solution is to create a seperate struts action that renders the image given some input URL parameters. Commonly you'll want to pass the InterMine object id as a parameter. So the long displayer JSP might look like this:
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<img src="<html:rewrite action="/myImageRenderer?gene=${object.id}"/>" />
The action "myImageRenderer" should split out image data. Something like this:
public class MyImageRenderer extends InterMineAction
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
ObjectStore os = (ObjectStore) request.getSession().getServletContext()
.getAttribute(Constants.OBJECTSTORE);
String id = request.getParameter("object");
MyModelObject obj = (MyModelObject) os.getObjectById(new Integer(id));
image = myImageRenderingFunction(obj);
response.setContentType("image/png");
ImageIO.write(image, "png", response.getOutputStream());
return null;
}
}
You'll need to remember to add configuration for the action to struts-config-model.xml.
So communication between the long displayer JSP/tile and the action that renders the image is really limited to the parameters you can stick on the URL and pass through to the image rendering action. Even if the long displayer JSP has a controller, it is not recommended that the session is used to pass attributes from the tile controller to the image renderer action.
