How get fields of object in parameter iReport - jasper-reports

I'm passing the object "OrdemServico" as parameter to report.
OrdemServico ordemServico = new OrdemServico();
ordemServico.setCodigo("CA123");
mapa.put("ORDEMSERVICO", ordemServico);
And on the .jrxml i added a parameter with same name of the parameter in map. how i can get the fields of the object? Tnks

You need also add import and declare the parameter
Great.
To work here:
<parameter name="RelatorioMaquina" class="br.pro.x87.reports.RelatorioMaquina"/>
and to acess the field:
$P{RelatorioMaquina}.getDescricao()

Related

Bind report parameter to a sql output jasper report

I have an existing report which needs to modified a little. Suppose my report query is like
select name,currency,productcode from where name=?
Now this '?' value will come from a report parameter say countryName. That can be done using parameterized query not a problem.
Now what I need is this parameter countryName to get the data from another query like below
select name from countries
In short I want to bind the value of report parameter countryName to the output of the above query and also I want to put this query in report it self.
Using birt its very easy but I want to know is it possible with jasper?
P.S I'm novice in jasper report.
I have tried to give an small scenario to represent my issue. The actual report is much more that this and is very complex.
Any help would be highly appreciated!!
I give you an answer how this can be achieved without passing anything through the parameter map (even if I think the parameter map should be the preferred way, modify your standard module to support parameter map)
You say you will have combobox value with the country name, we need to make it static. (or have a static way to access it, "there can be only one")
Example class of your interface:
package com.your.package;
public class SelectCountryInterface {
private static JComboBox<String> selectCountry;
public static synchronized String getSelectedCountry(){
Object value = selectCountry.getSelectedItem();
if (value instanceof String){
return (String)value;
}
return "";
}
//...Here goes you code to instance and populate the combobox
}
In jasper report (.jrxml)
Define a parameter and set the defaultValueExpression to point at your static method in class, this way it will be initialized with the value that you are providing from your interface class.
<parameter name="country" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA[com.your.package.SelectCountryInterface.getSelectedCountry()]]> </defaultValueExpression>
</parameter>
Set the queryString to use your parameter
<queryString>
<![CDATA[select name,currency,productcode from where name=$P{country}]]>
</queryString>

Variable is not showing from sub report to main report in iReport

I am trying to pass a variable from sub report to main report. I have already declared variable in subreport. But it's not showing when I'm trying to use this at the main report.
Can anyone please help me out?
Thanks in advance.
Add the folowing parameters in Properties of your Subreport
Parameters Map Expression : $P{REPORT_PARAMETERS_MAP} : This is used to pass a map containing report parameters to the subreport. The map is usually obtained from a parameter in the master report, or by using the built-in REPORTS_PARAMETERS_MAP parameter to pass the parent report's parameters to the subreport. This expression should always return a java.util.Map object in which the keys are the parameter names.
Subreport Expression Class : java.lang.String
Subreport Expression : $P{SUBREPORT_DIR} + "yourPage.jasper"
Connection/Data source Expression, select Use connection expression, and put : $P{REPORT_CONNECTION}
See also:
JasperReports - Create SubReports
As per my knowledge, You need to specify Parameters for that sub-report present in main-report based on which it will fetch data. It may help.
While returning any value from subReport you have to just type the variable name you declared at the subReport in "subReport variable" field. And at the "Local Destination Variable" you will find the variable you declared in main report. Like this:
Don't forget to set the variable expression you declared at the main report. It has to be that variable itself.

Field not found, JRXML has definitions?

I'm using iReport Designer 5.5.0, and was making a test JRXML. I added a text field with a value of $F{pricing_date} and added "pricing_date" to the list of "fields" on the Report Inspector panel (no properties or description set for the field).
The resulting JRXML has the "pricing_date" field defined:
<field name="pricing_date" class="java.lang.String"/>
And it has a text field with $F{pricing_date} as expected:
<textFieldExpression><![CDATA[$F{pricing_date}]]></textFieldExpression>
But... I get the error "Field not found : pricing_date" within iReport, and I get the same error during compilation.
I've compared this to other JRXML files within the samples provided, and it seems to match... what am I missing? Is there a setting somewhere to recognize field definitions?
I can see two possible reasons here.
If the report does not compile, the problem might be that the element in which you have placed the textField uses a different datasource than the one in which you have declared the field.
If it does not run, you might be missing the field in the object type of the datasource. Also, if you use JRBeanCollectionDataSource from java you have to have the getter for your field (declared as getPricing_date(){...}).
Hope this helps.

How use a parameter as datasource in Jasper list element?

I have a report template where a parameter is defined as:
<parameter name="phonenumbers" class="java.util.List"/>
Those phonenumbers are objects of type:
se.primenta.data.entity.PhoneNumber
and these objects have two methods that I need present in the report:
String getMaskedNumber();
Long getNumber;
I can't understand how to get these two fields into a subDataset that can be visualized in a List element. How do I write the dataset and the list definitition in the JRXML template?
What about having a Datasource for the list like :
<dataSourceExpression>
<![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{phonenumbers})]]>
</dataSourceExpression>
And then using
$F{maskedNumber} and $F{number}
inside the list ?

How to select id and name of multiselect input control in jrxml?

I am working with jasperserver and ireport. I have created multiselect input control. I need to access its id as well as name in report. How can I do that?
You cannot.
The value gets passed as the value of the relevant parameter (the parameter with exactly the same name as the input control). The label used in the input control (if any) does not get passed to the report. It's it's something that you want to pass to the report then you need to pass it as part of the value.