Class SimpleHTMLReportAction

  • All Implemented Interfaces:
    IAction, IChangeModeAction, IForwardAction, IModelAction, IModuleContextAction, IRequestAction

    public class SimpleHTMLReportAction
    extends SimpleTemplaterAction
    implements IForwardAction
    How to use the SimpleHtmlReportAction

    Create an action which extends SimpleHtmlReportAction.
    Create a report template
    Add the action in controllers.xml,

    Create an action which extends SimpleHtmlReportAction.
    If your entity does not contain collections, you don't have to create this action, you can use SimpleHtmlReportAction

    public class ReportProjectAction extends SimpleHtmlReportAction {

    public Map<String, Object> getParameters() throws Exception {
    Project p = (Project)MapFacade.findEntity(getModelName(), getView().getKeyValuesWithValue());
    return getParameters(p);

    public static Map<String, Object> getParameters(Project p) throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    // get all the field contents of the entity
    // get the field contents of the collections
    parameters.put("milestones", Objects.getCollectionParametersList(p.getMilestones()));
    parameters.put("actions", Objects.getCollectionParametersList(p.getActions()));
    return parameters;
    In most cases, you just have to call Objects.getEntityParameters(your_entity) and Objects.getCollectionParametersList(your_collection) in the action.
    By defining a static function to get the parameters, you can reuse the code for an extension of SimpleHtmlMailBaseAction.

    Create a report template in /reports (if this folder does not exist, create it as a source folder). You can create it with any WYSIWYG editor (SeaMonkey is a good free one).
    This template should be called entity_name.html, but you can create others as you want. The (very simple) syntax for the report is explained at the end.
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html xmlns="">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Project - ${reference}</title>
    <link href="/OpenXavaTest/xava/style/report.css" rel="stylesheet" type="text/css">
    <tr><td>Owner:</td><td>${owner.firstName} ${owner.lastName}</td></tr>
    <!-- $$if(customers) -->
    <!-- $$endif(customers) -->
    <!-- $$for(milestones) -->
    <!-- $$endfor(milestones) -->
            <controller name="Project">        
    <extends controller="Typical"/>
    <action name="datasheet" image="images/report.gif" mode="detail"
    class="org.openxava.actions.ReportProjectAction" >
    <set property="template" value="/Project.html" />
    <action name="actionsReport" image="images/report.gif" mode="detail"
    class="org.openxava.actions.ReportProjectAction" >
    <set property="template" value="/ProjectActions.html" />

    <controller name="Company">
    <extends controller="Typical"/>
    <action name="report" image="images/report.gif" mode="detail"
    class="org.openxava.actions.SimpleHtmlReportAction" />

    <controller name="SimpleHtmlReport">
    <action name="report" image="images/report.gif" mode="detail"
    class="org.openxava.actions.SimpleHtmlReportAction" />

    Here we have used twice the same report action with 2 different templates for Project to report on different part of the entity.
    We also have use the SimpleHtmlReportAction if we don't want to display collections in the report such as in the Company controller.

    Developping reports very fast

    1. In application.xml, add the SimpleHtmlReport controller to the module you want to report on.
    2. In /reports, create a report named entity_name.html, open it in Eclipse and just write ${fields} inside, save
    3. Start Tomcat, launch your browser, select your module and click on Report, a report will be generated with all the available fields
    4. Save this report under /reports/entity_name.html
    5. Done! If you refresh the reports folder in Eclipse and wait a little bit, when you click on report in the browser you will see a complete report of your entity (without the collections)

    Syntax for the template

    Field names
    ${field_name} is replaced in the template by the value contained in the Map returned by getParameters()
    field_name can contain references such as ${} with a default (adjustable) depth of 5.

    There are 3 types of control blocks
    Syntax: <!-- $$if(field_name) -->Some text which can contain control blocks<!-- $$endif(field_name) -->
    The content of the block will only appear if field_name IS in the getParameters() Map and is not empty.

    Syntax: <!-- $$ifnot(field_name) -->Some text which can contain control blocks<!-- $$endifnot(field_name) -->
    The content of the block will only appear if field_name is NOT in the getParameters() Map or is empty.

    Syntax: <!-- $$for(field_name) -->Some text which can contain control blocks<!-- $$endfor(field_name) -->
    The content of the block will be repeated as many times as there are items in the Vector<Map<String, Object>> returned by getParameters().get(field_name)
    Laurent Wibaux
    • Constructor Detail

      • SimpleHTMLReportAction

        public SimpleHTMLReportAction()
    • Method Detail

      • getForwardURI

        public java.lang.String getForwardURI()
        Description copied from interface: IForwardAction
        The URI to go.

        If it starts with "http://" or "https://" the action will forward to the absolute URL in internet (since v4m1). Since 7.1 using "javascript:" as prefix to execute JavaScript is not allowed. Since 4.0.1 if it starts with "javascript:" the corresponding code will executed by the browser. Since 5.9 you should use IJavaScriptPostAction to execute JavaScript because IForwardAction with javascript: does not update the page before executing the JavaScript, but executes the JavaScript instead. If it returns null the forwarding is not done.

        Specified by:
        getForwardURI in interface IForwardAction