title: jasper reports and struts2
body: <p>This one may be a tricky one.</p>
  
  <p>Using jaspersoft studio I created a report : myreport.jrxml,  it works very fine :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- Created with Jaspersoft Studio version last--&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Blank A4" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="36f7dbef-85e9-4a2e-bc9a-61e146a441b6"&gt;
      &lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="ISA"/&gt;
      &lt;queryString&gt;
          &lt;![CDATA[select nom, prenom from beneficiaire where nni='105011411873713']]&gt;
      &lt;/queryString&gt;
      &lt;field name="NOM" class="java.lang.String"/&gt;
      &lt;field name="PRENOM" class="java.lang.String"/&gt;
      &lt;background&gt;
          &lt;band splitType="Stretch"/&gt;
      &lt;/background&gt;
      &lt;pageHeader&gt;
          &lt;band height="147" splitType="Stretch"&gt;
              &lt;image&gt;
                  &lt;reportElement uuid="ca704754-4477-48ed-999d-29bc717e08d3" x="0" y="0" width="50" height="50"/&gt;
                  &lt;imageExpression&gt;&lt;![CDATA["C:/Documents and Settings/DAVENNE-09298/Bureau/logo_assurance_maladie.gif"]]&gt;&lt;/imageExpression&gt;
              &lt;/image&gt;
              &lt;staticText&gt;
                  &lt;reportElement uuid="29581e3a-a202-43c1-b3c9-47a56d05edfe" x="0" y="60" width="121" height="25"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="8" isBold="false"/&gt;
                  &lt;/textElement&gt;
                  &lt;text&gt;&lt;![CDATA[SERVICE  ADMINISTRATIF
  DU CENTRE APPAREILLAGE]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;textField&gt;
                  &lt;reportElement uuid="7049158d-a7e1-4c10-adb0-2e10e11bbcb7" x="380" y="80" width="175" height="20"/&gt;
                  &lt;textElement/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{NOM} + ' ' + $F{PRENOM}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
      &lt;/pageHeader&gt;
      &lt;detail&gt;
          &lt;band height="253" splitType="Stretch"&gt;
              &lt;staticText&gt;
                  &lt;reportElement uuid="c6bb6b7e-5316-49fb-b3c4-90faed1f4fcc" x="3" y="15" width="552" height="20"/&gt;
                  &lt;textElement textAlignment="Center" verticalAlignment="Middle"&gt;
                      &lt;font size="12" isBold="true"/&gt;
                  &lt;/textElement&gt;
                  &lt;text&gt;&lt;![CDATA[A L'ATTENTION DE VOTRE MUTUELLE]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement uuid="c3e93907-b312-437f-b032-68c919387986" x="0" y="50" width="554" height="130"/&gt;
                  &lt;textElement/&gt;
                  &lt;text&gt;&lt;![CDATA[Madame, Monsieur,
  
  La fourniture ....
  
  Le montant ...
  
  Recevez, Madame, Monsieur, mes sincères salutations]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement uuid="f71b41b6-02fb-44d4-9c8d-f10cc78d4b83" x="370" y="200" width="186" height="51"/&gt;
                  &lt;textElement/&gt;
                  &lt;text&gt;&lt;![CDATA[LE RESPONSABLE DU SERVICE
  
  ]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
          &lt;/band&gt;
      &lt;/detail&gt;
      &lt;pageFooter&gt;
          &lt;band height="54" splitType="Stretch"/&gt;
      &lt;/pageFooter&gt;
  &lt;/jasperReport&gt;
  </code></pre>
  
  <p>Now I would like to use this template in my struts 2 project (I added the struts2-jasperreport plugin in my project).
  I have to add the myreport.jasper but before I get rid of 2 lines that I dont need in my project :</p>
  
  <pre><code>&lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="ISA"/&gt;
  &lt;queryString&gt;
          &lt;![CDATA[select nom, prenom from beneficiaire where nni='105011411873713']]&gt;
  &lt;/queryString&gt;
  </code></pre>
  
  <p>I declare my new result type :</p>
  
  <pre><code>&lt;result-type name="jasper" class="org.apache.struts2.views.jasperreports.JasperReportsResult"/&gt;
  </code></pre>
  
  <p>I declare my action in struts.xml :</p>
  
  <pre><code>&lt;action name="testCourrierMutuellePDF" class="isa.presentation.jasper.CourrierMutuellePDF"&gt;
      &lt;result name="success" type="jasper"&gt;
          &lt;param name="location"&gt;jasper/courriers/myreport.jasper&lt;/param&gt;
          &lt;param name="dataSource"&gt;resultats&lt;/param&gt;
          &lt;param name="format"&gt;PDF&lt;/param&gt;
      &lt;/result&gt;
   &lt;/action&gt;
  </code></pre>
  
  <p>and I write my action class :</p>
  
  <pre><code>private Beneficiaire resultats;
  
  public String execute() {
          try {
              GestionBeneficiaireFacade facade = GestionBeneficiaireFacade.getInstance();
              resultats = facade.recupererBeneficiaire("105011411873713");
          } catch (IsaException e) {
              this.addActionMessage(this
                      .getText("error.benefInfosAction.sauverBenef"));
              this.isaException = e;
              return ERROR;
          }
          return SUCCESS;
      }
  
  public Beneficiaire getResultats() {
          return this.resultats;
  }
  </code></pre>
  
  <p>I am sure about a few things :</p>
  
  <ol>
  <li><p>The jasper file is found because I have no FileNotFoundException</p></li>
  <li><p>The datasource is found because I debugged and the getter is called and it is not empty, the data is inside</p></li>
  </ol>
  
  <p>One last thing.. of course my object resultats has 'nom' and 'prenom' properties</p>
  
  <p>Anyway I get a nullpointerException that I dont understand :</p>
  
  <pre><code>java.lang.NullPointerException
      net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)
      net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)
      org.apache.struts2.views.jasperreports.JasperReportsResult.doExecute(JasperReportsResult.java:326)
      org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
      com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:361)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)
      isa.presentation.intercepteur.IsaExceptionXMLIntercepteur.intercept(IsaExceptionXMLIntercepteur.java:29)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)
      com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:251)
      org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
      com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
      com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
      com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:270)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
      com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:164)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
      org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
      org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:498)
      org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)
      org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
  </code></pre>
  
  <hr>
  
  <p>Thanks to Aleksandr, I upgraded the jasperReport library and I have my pdf file.
  But the name and firstname are null.
  When I debugged the application I could see the call for the resultats variable through the getter and name / firstname properties were not null but with good values..</p>
  
  <p>So? any idea ?</p>