I have a simple report with two fields: ID and NAME. I want to sort the detail by ID or NAME depending on a parameter selected by the user in runtime.
I've tried doing something like this:
<sortField name="sort" type="Variable"/>
<variable name="sort" class="java.lang.String">
<variableExpression>
<![CDATA[$P{ord}.equals("name") ? $F{entity}.getName() : $F{entity}.getId().toString()]]>
</variableExpression>
</variable>
EDIT 1: I'm passing the datasource as a parameter, I don't execute the sql query from JasperReports. I think I could pass the datasource alredy sorted to JasperReports, but i'd like to sort the data directly from the report.
EDIT 2: I reviewed the previous code and works fine for me.