Using Groovy in a JPF Page

A JPF Page that can be run, will be run using groovy. Since groovy is a superset of java, you can write your code just like how you would write your java program, or you could just take advantage of the extra syntax sugar groovy affords you.

The variables made available for the developer are:

  1. postdata :- the POST value submitted by the user

  2. arg1,arg2,arg3,arg4,arg5 :- Additional variables the developer can use optionally from the url

  3. request :- the request object of this current request

  4. env :- the enviroment object of this current request. Can be used to access variables set in the runtime environment or even application.properties settings

  5. namedjdbctemplate :- the namedjdbctemplate object which the developer can use to run custom queries to the database

  6. javaMailSender :- the javamailsender object to use to send emails

  7. passwordEncoder :- the password encoder in case the page processing requires to hash user password

  8. trackerService :- the service to manage and manipulate trackers and their data

  9. userService :- the service to access information about users including the currently login user

  10. settingService :- the service to manage and use settings

  11. fileService :- the service to manage and use files uploaded as FileLink

  12. treeService :- the service used to manage and manipulate tree structures in the portal

Manipulating Excel Output

If the page is accessed through url http://<server>/excel/<module>/<slug> would allow for an excel file to be customised. The template would already have variable wb and sheet for the workbook and excel sheet:

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;

Row headerRow = sheet.createRow(0);

def headers = ['Name','Group','Test'];
for(int i=0;i<headers.size();i++) {
  Cell cell = headerRow.createCell(i);
  cell.setCellValue(headers[i]);
}

The above example would create a simple excel file with 3 columns.