1.Create e report with an textfied en change markup to html and set expression to $V{htmlData}
2.Define an variable with expression $F{documentos_source}
3.Define another variable $V{recordObj} and set ‘initial value expression’ to a class name of our record object, ex: document
4.create a class document
public class document{
public function _get($prop) {
if (method_exists($this, 'get_'.$prop)) // if an method defined with get+name of propriety exits, run it
{
// run method get_ + name of propriety
return call_user_func(array($this, 'get_'.$prop));
}
else // fallack to return a value into propriety, in this case a field value
{
// return a value of propriety
if (isset($this->$prop))
{
return ($this->$prop);
}
}
}
public function get_document_source
{
// load or create your html here
return $hrmlcode;
}
}
5. Define an sql query as you want, but a simple sample “SELECT DATE(NOW()) as date”.
if you use sql query to load a record to merge into html code, you can insert $F{fields} into html code and jasperphp replaces with your data.
Bonus: in my codes, i use this sql query
“SELECT *,
(SELECT CONVERT(documentos_source USING latin1)
FROM documents
WHERE idDocument = $P{idDocument}
) as documentos_source,
DATE(NOW()) as date
FROM $P{table} $P{join}
WHERE $P{criteria}”
and powerfull your html document generator, my documents are pre created and store into database table and select it with parameter “idDocument”, parameters $P{table} , $P{join} and $P{criteria} help you to select a record to use into html generated code, and the record object is necessary if you want need more resources in record manipulate.