Problem with Velocity Report

Hello Everbody

Servoy 6.01 with webclient.
With Velocity-Reports i show serveral informations in an html-aera on a form.
(record fields, picture,related records,…)

One of the related table has 0 to n Dokuments.
I fetch them like this:

	var  pdquery = "select produktdoktyp.dokumenttyp,produktdokumente.produktdokument "+
	" from produktdokumente join produktdoktyp on produktdoktyp.produktdoktypid = produktdokumente.produktdoktypid "+
	 "where produktstammid = '"+vproduktid+"'";
	context.datasetd = databaseManager.getDataSetByQuery(servername,pdquery,null,-1);
		
	context.previewBounds = {x: -1, y: -1, w: 900, h: 720};
	return context;

The result part in the html-aera looks like this:

Dokumente:

Dokumenttyp 	      Produktdokument
Betriebsanweisung 	P:\PUGINFO\KATEGORIE\DOKUMENTE\ARBEITS_UMWELTSCHUTZ\BETRIEBSANWEISUNGEN\M5-00.PDF
Datenblatt        	P:\PUGINFO\KATEGORIE\DOKUMENTE\MATERIAL\CHEMIE\040015_SDB.PDF

P:\ is a mapped directory an external fileserver.
Now i want, that the user can download/open the offered documents.
In a normal tableview form we put a button in each record and do this on action:

var vdokument = utils.stringReplace(produktdokument, "\\", "/");
vdokument = utils.stringReplace(vdokument,'P:','//vm-s-file1/pb-allgem');
var file = plugins.file.convertToJSFile(vdokument);
plugins.file.writeFile(file.getName(), file.getBytes());

I have no idear how to get this functionality in a html-aera created with velocity.

Any help welcomed.
Regards
Albert

Hi Albert,

You can use myDocumentName in your XHTML to trigger a method that writes out those files.
Of course you can pass any data, this documentid just an example.

Hope this helps.

Hello
Thank you for the quick answer.

As a Servoy,Velocity-Report and HTML newbee i can’t get this running! :(
I call the report like this:

vhtml = plugins.VelocityReport.renderTemplate("PasProdukte.html", m_produktinfos(), resolution);

In m_produktinfos i fetch the records into datasetd as described above.
The dataset contains only 2 columns(documenttype and produktdokument which is the full path to the document on our fileserver)

In my PasProdukte.html i have these 2 lines to show the records:

<h2>Dokumente:</h2>

#tablizer($datasetd, "datasetTable", true)

But i don’t know how to make a button beside each record that does the wanted open/download or
how to make a link from each line of the datasetd.
Example would be great.
Regards
Albert

#tablizer is a macro (you can find it’s code in the VM_global_library.vm file located in you reports folder), but it is a generic way of creating a table from a dataset or a foundset.

In your case you want to do something specific with one of the columns, so using the generic #tablizer is not a good idea.

You have to create the table using a loop inline in your template (although you could create your own macro or put that part in an included template).
Something like this:

<table>
 <thead>
  <tr>
   <th>Columm 1</th>
   <th>Column 2</th>
  </tr>
 </thead>
 <tbody>
#foreach($record in $datasetd)
  <tr>
   <td><a href="javascript:getDocument($record.id)">$record.documentName</a></td>
   <td>$record.column2</td>
  </tr>
#end
 </tbody>
</table>

Hope this helps,

Hello

I tried your example with no success.

I call this to get the data into a html-field:

function m_produkt() 
{
	vhtml = plugins.VelocityReport.renderTemplate("PasProdukte.html", m_produktinfos(), resolution);
	
}

In m_produktinfos i get my data:

//dokumente
	var  pdquery = "select produktdokumente.produktdokumenteid,produktdoktyp.dokumenttyp,produktdokumente.produktdokument "+
	" from produktdokumente join produktdoktyp on produktdoktyp.produktdoktypid = produktdokumente.produktdoktypid "+
	"where produktstammid = '"+vproduktid+"'";
	
	context.datasetd = databaseManager.getDataSetByQuery("pug_produktiv",pdquery,null,-1);

In my PasProdukte.html the table part looks like this(copied from your suggestion):

<h2>Test:</h2>
    <table>
    <thead>
      <tr>
       <th>Dokument</th>
       <th>Typ</th>
      </tr>
    </thead>
    <tbody>
    #foreach($record in $datasetd)
      <tr>
       <td><a href="javascript:getDocument($record.produktdokumenteid)">$record.produktdokument</a></td>
       <td>$record.dokumenttyp</td>
      </tr>
    #end
    </tbody>
    </table>

The result part in my html-aerea looks like this:

Test:
Dokument Typ
$record.produktdokument $record.dokumenttyp
$record.produktdokument $record.dokumenttyp

What do i miss??

Regards
Albert

Note that context is not a build-in object.

I don’t see your whole m_produktinfos() method but it should look like:

function m_produktinfos() {
   var context = new Object();
   // anything else that you put in your context object could happen here

   //dokumente
   var  pdquery = "select produktdokumente.produktdokumenteid,produktdoktyp.dokumenttyp,produktdokumente.produktdokument "+
   " from produktdokumente join produktdoktyp on produktdoktyp.produktdoktypid = produktdokumente.produktdoktypid "+
   "where produktstammid = ?";

   context.datasetd = databaseManager.getDataSetByQuery("pug_produktiv",pdquery,[vproduktid],-1);

   // anything else that you put in your context object could also happen here...
   return context;
}

If that is what you have, I would make sure that your datasetd is indeed containing the data you want…

Hello
Datasetd has the wanted infos.
When i use:

<h2>Dokumente:</h2>

#tablizer($datasetd, "datasetTable", true)

in my PasProdukte.html the correct infos are shown.
Displaying the records with foreach($record in $datasetd) as described above doesn’t work??

Test
Dokument Typ
$record.produktdokument $record.dokumenttyp
$record.produktdokument $record.dokumenttyp

Regards
Albert

You must have a typo somewhere in your #foreach call. Maybe you forgot a # or a $ ?

Internally the tablizer macro is doing a foreach as well so if this one is working there’s no reason yours isn’t.
I also just tried a foreach loop on a dataset and it’s working as expected here.

Check the velocity.log in case there is a parsing error (see the wiki for the location of that log).

Hello
I found the problem.
I get the datasetd with:

//dokumente
   var  pdquery = "select produktdokumente.produktdokumenteid,produktdoktyp.dokumenttyp,produktdokumente.produktdokument "+
   " from produktdokumente join produktdoktyp on produktdoktyp.produktdoktypid = produktdokumente.produktdoktypid "+
   "where produktstammid = ?";

   context.datasetd = databaseManager.getDataSetByQuery("myserver",pdquery,[vproduktid],-1);

In my HTML-page i have to do:

#foreach($record in $datasetd)
$record.DOKUMENTTYP $record.PRODUKTDOKUMENT  

#end

UPPER!!!
Lowercase is not working:

#foreach($record in $datasetd)
$record.dokumenttyp $record.produktdokument  

#end

Thank you for your efforts
Regards
Albert

Yes, Velocity is case-sensitive.

But what you say is weird because I don’t change the case of the record/row properties!
What DB are you using?

Hello

We use MAXDB 7.8 (from SAP)!

After i got this one running i step into another problem:

In my servoy 6.03 form i show a record and a picture.
The full path and the filename of the picture is stored in a field:
“F:\xxx\xxx\mypicture.gif”

F is a mapped directory from a fileserver!

To show the picture in the form i do:

var vbildpfad = utils.stringTrim(foundset.produktbild);
var vbildurl = utils.stringIndexReplace(vbildpfad,1,2,'\\\\servername\\pb-allgem');
vbild = plugins.file.readFile(vbildurl); (vbild is a form variable which i show in my form with displaytype Image_media)

Everything works as expected local and on our application server.

To show the picture in a velocity report i use the same code.

var vbildurl = utils.stringIndexReplace(vbildpfad,1,2,'\\\\servername\\pb-allgem');
var vbild = plugins.file.readFile(vbildurl); 
context.bild = vbild;
...

And in my HTML-Page:

<head>

<style type="text/css">
  body {
    color: black; background-color: white;
    font-size: 12px;
    font-family: Courier,Fixedsys,Helvetica,Arial,sans-serif;
   
  }

 img.bild {
    margin: 0 0 0.7em; padding: 0em;
    height: 150px;
    width: 150px;
    border: 2px double;
  }
</style>
</head>

<body width="100%">

<h1><B>  Produkt Informationen </B>  </h1>


<img class="bild" $bild 


...
...

On my local maschine everything works.
Velocity shows the wanted informations and the picture.

But after putting the solution on our application server, the picture is not shown with Velocity???
All other content is ok.
The velocity.log on the application server is empty.
On the application server i use the same version of Velocity as on my local maschine.

Application server log:

011-11-23 11:37 	http-8080-2 	WARN 	org.apache.wicket.request.target.component.listener.BehaviorRequestTarget 	component not enabled or visible; ignoring call. Component: [MarkupContainer [Component id = 1]] 	8621AB05-184C-4FDA-93AB-2FCB785C9370	PAS_Produkte
2011-11-23 11:37 	http-8080-2 	ERROR 	com.servoy.j2db.util.Debug 	Throwable 	8621AB05-184C-4FDA-93AB-2FCB785C9370	PAS_Produkte

java.awt.HeadlessException
     at java.awt.GraphicsEnvironment.checkHeadless(Unknown Source)
     at java.awt.Window.<init>(Unknown Source)
     at java.awt.Frame.<init>(Unknown Source)
     at java.awt.Frame.<init>(Unknown Source)
     at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(Unknown Source)
     at javax.swing.SwingUtilities.getSharedOwnerFrame(Unknown Source)
     at javax.swing.JOptionPane.getRootFrame(Unknown Source)
     at javax.swing.JOptionPane.getWindowForComponent(Unknown Source)
     at javax.swing.JFileChooser.createDialog(Unknown Source)
     at javax.swing.JFileChooser.showDialog(Unknown Source)
     at javax.swing.JFileChooser.showOpenDialog(Unknown Source)
     at com.servoy.j2db.util.FileChooserUtils.getAReadFile(FileChooserUtils.java:170)
     at com.servoy.j2db.util.FileChooserUtils.getAReadFile(FileChooserUtils.java:160)
     at com.servoy.extensions.plugins.file.FileProvider.js_readFile(Unknown Source)
     at com.servoy.extensions.plugins.file.WebFileProvider.js_readFile(Unknown Source)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:179)
     at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:367)
     at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3666)
     at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2680)
     at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:166)
     at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:387)
     at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3134)
     at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:165)
     at com.servoy.j2db.scripting.ScriptEngine.executeFunction(ScriptEngine.java:528)
     at com.servoy.j2db.FormController.executeFunction(FormController.java:4058)
     at com.servoy.j2db.FormController.executeFormMethod(FormController.java:4375)
     at com.servoy.j2db.FormController.executeOnRecordSelect(FormController.java:4313)
     at com.servoy.j2db.FormController.refreshAllPartRenderers(FormController.java:2234)
     at com.servoy.j2db.FormController.valueChanged(FormController.java:2306)
     at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
     at com.servoy.j2db.util.model.AlwaysRowSelectedSelectionModel.fireValueChanged(AlwaysRowSelectedSelectionModel.java:219)
     at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
     at com.servoy.j2db.util.model.AlwaysRowSelectedSelectionModel.setSelectedRows(AlwaysRowSelectedSelectionModel.java:199)
     at com.servoy.j2db.util.model.AlwaysRowSelectedSelectionModel.setSelectedRow(AlwaysRowSelectedSelectionModel.java:164)
     at com.servoy.j2db.util.model.AlwaysRowSelectedSelectionModel.setSelectedRow(AlwaysRowSelectedSelectionModel.java:131)
     at com.servoy.j2db.dataprocessing.SwingFoundSet.setSelectedIndex(SwingFoundSet.java:132)
     at com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor.setSelectedIndex(WebEventExecutor.java:576)
     at com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor.onEvent(WebEventExecutor.java:390)
     at com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor$4.onEvent(WebEventExecutor.java:305)
     at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:177)
     at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:302)
     at org.apache.wicket.request.target.component.listener.BehaviorRequestTarget.processEvents(BehaviorRequestTarget.java:157)
     at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
     at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1252)
     at org.apache.wicket.RequestCycle.step(RequestCycle.java:1331)
     at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1438)
     at org.apache.wicket.RequestCycle.request(RequestCycle.java:546)
     at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
     at com.servoy.j2db.server.servlets.Zl.doGet(Zl.java:8)
     at org.apache.wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:138)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:554)
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
     at java.lang.Thread.run(Unknown Source)

What do i miss
Regards
Albert

Does the image display from the server if you place it in a field of type MEDIA?
If not, this means that the path is wrong or that you have some permission issues to access the file.

Also instead of the weird non closed tag (which might also be the cause of your trouble):

<img class="bild" $bild

You should try:

$bild.getImageTag({'class': "bild"})

Have a look at the VelocityReport FAQ about this special call:

Hello

I changed the picture part in my HTML-Page to

$bild.getImageTag({'class': "bild"})

Same behavior:
Working on local maschine, not on our application server.
Server.log=

2011-11-23 17:06 	http-8080-5 	WARN 	org.apache.wicket.request.target.component.listener.BehaviorRequestTarget 	component not enabled or visible; ignoring call. Component: [MarkupContainer [Component id = 1]] 	DAE18CCC-2AAC-4E7A-AC3A-311A009F651E	PAS_Produkte
2011-11-23 17:06 	http-8080-5 	ERROR 	com.servoy.j2db.util.Debug 	Throwable 	DAE18CCC-2AAC-4E7A-AC3A-311A009F651E	PAS_Produkte
java.awt.HeadlessException
     at java.awt.GraphicsEnvironment.checkHeadless(Unknown Source)
     at java.awt.Window.<init>(Unknown Source)
     at java.awt.Frame.<init>(Unknown Source)
     at java.awt.Frame.<init>(Unknown Source)
     at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(Unknown Source)
     at javax.swing.SwingUtilities.getSharedOwnerFrame(Unknown Source)
     at javax.swing.JOptionPane.getRootFrame(Unknown Source)
     at javax.swing.JOptionPane.getWindowForComponent(Unknown Source)
     at javax.swing.JFileChooser.createDialog(Unknown Source)
     at javax.swing.JFileChooser.showDialog(Unknown Source)
     at javax.swing.JFileChooser.showOpenDialog(Unknown Source)
     at com.servoy.j2db.util.FileChooserUtils.getAReadFile(FileChooserUtils.java:170)
     at com.servoy.j2db.util.FileChooserUtils.getAReadFile(FileChooserUtils.java:160)
     at com.servoy.extensions.plugins.file.FileProvider.js_readFile(Unknown Source)
     at com.servoy.extensions.plugins.file.WebFileProvider.js_readFile(Unknown Source)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:179)
     at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:367)
     at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3666)
     at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2680)
     at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:166)
     at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:387)
     at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3134)
     at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:165)
     at com.servoy.j2db.scripting.ScriptEngine.executeFunction(ScriptEngine.java:528)
     at com.servoy.j2db.FormController.executeFunction(FormController.java:4058)
     at com.servoy.j2db.FormController.executeFormMethod(FormController.java:4375)
     at com.servoy.j2db.FormController.executeOnRecordSelect(FormController.java:4313)
     at com.servoy.j2db.FormController.refreshAllPartRenderers(FormController.java:2234)
     at com.servoy.j2db.FormController.valueChanged(FormController.java:2306)
     at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
     at com.servoy.j2db.util.model.AlwaysRowSelectedSelectionModel.fireValueChanged(AlwaysRowSelectedSelectionModel.java:219)
     at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
     at com.servoy.j2db.util.model.AlwaysRowSelectedSelectionModel.setSelectedRows(AlwaysRowSelectedSelectionModel.java:199)
     at com.servoy.j2db.util.model.AlwaysRowSelectedSelectionModel.setSelectedRow(AlwaysRowSelectedSelectionModel.java:164)
     at com.servoy.j2db.util.model.AlwaysRowSelectedSelectionModel.setSelectedRow(AlwaysRowSelectedSelectionModel.java:131)
     at com.servoy.j2db.dataprocessing.SwingFoundSet.setSelectedIndex(SwingFoundSet.java:132)
     at com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor.setSelectedIndex(WebEventExecutor.java:576)
     at com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor.onEvent(WebEventExecutor.java:390)
     at com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor$4.onEvent(WebEventExecutor.java:305)
     at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:177)
     at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:302)
     at org.apache.wicket.request.target.component.listener.BehaviorRequestTarget.processEvents(BehaviorRequestTarget.java:157)
     at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
     at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1252)
     at org.apache.wicket.RequestCycle.step(RequestCycle.java:1331)
     at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1438)
     at org.apache.wicket.RequestCycle.request(RequestCycle.java:546)
     at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
     at com.servoy.j2db.server.servlets.Zl.doGet(Zl.java:8)
     at org.apache.wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:138)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:554)
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
     at java.lang.Thread.run(Unknown Source)

The application server must have access the fileserver.
The picture is shown in our servoy form as decribed above.

Regards
Albert

If this log is related to the problem you have, the problem seems to be more of the file plugin than VelocityReport…

This:
com.servoy.extensions.plugins.file.WebFileProvider.js_readFile(Unknown Source)
Is calling a FileDialog on your server:
com.servoy.j2db.util.FileChooserUtils.getAReadFile !!!

And this ends up being rejected because the server is headless (it has no UI), which would explain why it is working on your dev machine.

Are you sure about your path and is this a file path or a folder?
What does you vbildurl look like? Are you sure it’s not null?

[EDIT]
Actually:

vbild = plugins.file.readFile(vbildurl); (vbild is a form variable which i show in my form with displaytype Image_media)

is wrong, it should be:

var vfile = plugins.file.convertToJSFile(vbildurl);
vbild = plugins.file.readFile(vfile);

Because readFile is expecting a JSFile not a String.