Pergunta

I'm having problems trying to send input fields values to a Jasper report. I know how to send parameters to a report but I always did this using the show.gsp view because it was quite simple to do something like this:

<g:jasperReport controller="liquidacionDeEstano" action="crearReporte" jasper="liquidacion_estano" format="PDF" name="ReporteLiquidacion${liquidacionDeEstanoInstance.lote}">
<input type="hidden" name="LIQ_SN_ID" value="${liquidacionDeEstanoInstance.id}" />
</g:jasperReport>

Where LIQ_SN_ID is a "static" parameter used by the report.

But now I want to fill some input fields and use this values as parameters. So, what I'm doing is to use some input fields out of the jasperReport tags and hidden fields inside the jasperReport tags. Then I copy the values from the input fields to the hidden fields using JavaScript.

To generate the report I'm just using SQL and the parameters passed are used for filtering.

This is my controller closure to create the report (I think I don't need anything else but the parameters):

def crearReporte = {
chain(controller:'jasper',action:'index',params:params)
}

This is the code in the GSP form to invoke the report:

<g:jasperReport controller="reporteLotesRecepcionados" action="crearReporte" jasper="reporte_recepcion_fechas" format="PDF" name="ReportePorFechas">
    <input type="hidden" id="ELEMENTO_1" name="ELEMENTO_1" />
    <input type="hidden" id="ELEMENTO_CLASS_1" name="ELEMENTO_CLASS_1" />
    <input type="hidden" id="FECHA_INICIAL_1" name="FECHA_INICIAL_1"/>
    <input type="hidden" id="FECHA_FINAL_1" name="FECHA_FINAL_1"/>
    <input type="hidden" id="ESTADO_LOTE_1" name="ESTADO_LOTE_1"/>
</g:jasperReport>

I checked that all the parameters are correct (hidden fields values) using Firebug and a Web Developer extension for Firefox but when I click the link to the report this error is produced:

Timestamp: 23/12/2013 07:20:00 p.m.
Error: TypeError: link.parentNode._format is undefined
Source File: http://localhost:8080/Liquidaciones/reporteLotesRecepcionados/create
Line: 660

Following the link to the error this automatic generated code is shown:

<script type="text/javascript">
    function submit_reporterecepcionfechas(link) {
      link.parentNode._format.value = link.title;
      link.parentNode.submit();
      return false;
    }
  </script>

I don't know what I'm doing wrong. In fact this is the first time I try to generate a report using values as parameters from input fields.

Please help me with this.

Thank you in advance.

Foi útil?

Solução 2

Finally I solved it but I'm not sure how I did it. Ok, here is what I did:

As you know, since Grails 2 (I think) there is a form.gsp used by the create.gsp and edit.gsp views. I was using just the create.gsp (and, in consequence, the form.gsp) view to have the input fields to obtain parameters to generate reports. Initially I located the code:

<g:jasperReport controller="reporteLotesRecepcionados" action="crearReporte" jasper="reporte_recepcion_fechas" format="PDF" name="ReportePorFechas">
    <input type="hidden" id="ELEMENTO_1" name="ELEMENTO_1" />
    <input type="hidden" id="ELEMENTO_CLASS_1" name="ELEMENTO_CLASS_1" />
    <input type="hidden" id="FECHA_INICIAL_1" name="FECHA_INICIAL_1"/>
    <input type="hidden" id="FECHA_FINAL_1" name="FECHA_FINAL_1"/>
    <input type="hidden" id="ESTADO_LOTE_1" name="ESTADO_LOTE_1"/>
</g:jasperReport>

INSIDE the <g:form></g:form> tags. So, I tried, as an experiment, to copy the code to declare the input fields and the code to generate the report from form.gsp file to create.gsp, OUTSIDE the <g:form></g:form> tags (I'm not using the form.gsp file anymore). And that was all. It's working perfectly now.

As I told you I don't know how this problem has been solved. Maybe it is mandatory to have the tags outside any <g:form></g:form> tags...

...but why?

PD.: I created a domain class to have the form to enter the values that were going to be parameters. All of you must be thinking this was completely unnecessary and that having an ordinary HTML form was enough , well, I'm a Grails newbie, sorry.

Outras dicas

I know this have been here for 11 months withuoth an answer so... Jasper tags uses their own form and since html forbids to have nested forms:

Content model: Flow content, but with no form element descendants. (HTML)

Jasper documentation says : "Note that the jasperReport tag should not be nested with a form element, as it uses a form element in its implementation, and nesting of forms is not allowed."

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top