Package org.openxava.actions
Class SimpleHTMLReportAction
- java.lang.Object
-
- org.openxava.actions.BaseAction
-
- org.openxava.actions.ViewBaseAction
-
- org.openxava.actions.TabBaseAction
-
- org.openxava.actions.SimpleTemplaterAction
-
- org.openxava.actions.SimpleHTMLReportAction
-
- All Implemented Interfaces:
IAction
,IChangeModeAction
,IForwardAction
,IModelAction
,IModuleContextAction
,IRequestAction
public class SimpleHTMLReportAction extends SimpleTemplaterAction implements IForwardAction
How to use the SimpleHtmlReportAction
Process
Create an action which extends SimpleHtmlReportAction.
Create a report template
Add the action in controllers.xml,
Action
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
In most cases, you just have to call Objects.getEntityParameters(your_entity) and Objects.getCollectionParametersList(your_collection) in the action.
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
parameters.putAll(Objects.getEntityParameters(p));
// get the field contents of the collections
parameters.put("milestones", Objects.getCollectionParametersList(p.getMilestones()));
parameters.put("actions", Objects.getCollectionParametersList(p.getActions()));
return parameters;
}
}
By defining a static function to get the parameters, you can reuse the code for an extension of SimpleHtmlMailBaseAction.
Report
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">
controllers.xml
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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">
</head>
<body>
<table>
<tr><td>Name:</td><td>${name}</td></tr>
<tr><td>Reference:</td><td>${reference}</td></tr>
<tr><td>Owner:</td><td>${owner.firstName} ${owner.lastName}</td></tr>
<!-- $$if(customers) -->
<tr><td>Customers:</td><td>${customer}</td></tr>
<!-- $$endif(customers) -->
</table>
<table>
<tr>
<td>Milestone</td>
<td>Target</td>
<td>Achieved</td>
</tr>
<!-- $$for(milestones) -->
<tr>
<td>${milestone.name}</td>
<td>${targetDate}</td>
<td>${achievedDate}</td>
</tr>
<!-- $$endfor(milestones) -->
</table>
</body>
</html>
<controller name="Project">
Here we have used twice the same report action with 2 different templates for Project to report on different part of the entity.
<extends controller="Typical"/>
<action name="datasheet" image="images/report.gif" mode="detail"
class="org.openxava.actions.ReportProjectAction" >
<set property="template" value="/Project.html" />
</action>
<action name="actionsReport" image="images/report.gif" mode="detail"
class="org.openxava.actions.ReportProjectAction" >
<set property="template" value="/ProjectActions.html" />
</action>
</controller>
<controller name="Company">
<extends controller="Typical"/>
<action name="report" image="images/report.gif" mode="detail"
class="org.openxava.actions.SimpleHtmlReportAction" />
</controller>
<controller name="SimpleHtmlReport">
<action name="report" image="images/report.gif" mode="detail"
class="org.openxava.actions.SimpleHtmlReportAction" />
</controller>
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 ${parent.child.name} with a default (adjustable) depth of 5.
Control
There are 3 types of control blocks
if
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.
ifnot
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.
for
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)- Author:
- Laurent Wibaux
-
-
Field Summary
-
Fields inherited from class org.openxava.actions.SimpleTemplaterAction
COLLECTION, MAX_DEPTH
-
Fields inherited from interface org.openxava.actions.IChangeModeAction
DETAIL, LIST, PREVIOUS_MODE, SPLIT
-
-
Constructor Summary
Constructors Constructor Description SimpleHTMLReportAction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getForwardURI()
The URI to go.boolean
inNewWindow()
-
Methods inherited from class org.openxava.actions.SimpleTemplaterAction
execute, getClassParameters, getCollectionParametersList, getCollectionParametersList, getCollectionTable, getCollectionTable, getDepth, getEntityParameters, getEntityParameters, getEntityParameters, getFieldsTable, getParameters, getTemplate, getValuesTable, setDepth, setModel, setTemplate
-
Methods inherited from class org.openxava.actions.TabBaseAction
getCollection, getRow, getSelected, getSelectedKeys, getTab, setCollection, setRow, setViewObject
-
Methods inherited from class org.openxava.actions.ViewBaseAction
changeThisPropertyByViewValue, closeDialog, getModelName, getPreviousView, getPreviousViews, getView, resetDescriptionsCache, returnToPreviousView, setControllers, setPreviousViews, setView, showDialog, showDialog, showNewView, showView, validateViewValues
-
Methods inherited from class org.openxava.actions.BaseAction
addActions, addError, addErrors, addInfo, addMessage, addMessages, addWarning, clearActions, commit, executeAction, executeAfter, executeBefore, getContext, getEnvironment, getErrors, getLocale, getManager, getMessages, getNextMode, getQualifiedActionIfAvailable, getRequest, removeActions, returnToPreviousControllers, rollback, setContext, setDefaultControllers, setEnvironment, setErrors, setMessages, setNextMode, setRequest
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openxava.actions.IAction
execute, getErrors, getMessages, setEnvironment, setErrors, setMessages
-
-
-
-
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 interfaceIForwardAction
-
inNewWindow
public boolean inNewWindow()
- Specified by:
inNewWindow
in interfaceIForwardAction
-
-