iReport, how to print fields of different table - dataset

I need multiple queries in my report so i added a new dataset.
The problem is i can't use fields of new dataset in my report, the error is: field does not exists.
So, how can i have multiple query in my report(to print fields of different table) without create a subreport for each field?
Thanks.

Unfortunately this isn't how iReport works. You need to get all your data into one dataset to use the fields side by side. See #GenericJon's detailed answer on using a datasetRun where your fields are used as input parameters to define another dataset.
If you really want the parameters can be used to pass a field for output in a datasetRun. This outputs Dataset1>Field1 / Dataset2>Field2.
<subDataset name="TotalUsers">
<parameter name="Users" class="java.lang.Integer" isForPrompting="false"/>
<parameter name="Date" class="java.util.Date" isForPrompting="false"/>
<queryString language="SQL">
<![CDATA[CALL GetTotalUsersAtDate($P{Date})]]>
</queryString>
<field name="TotalUsers" class="java.lang.Long"/>
</subDataset>
...
<componentElement>
<reportElement x="0" y="78" width="555" height="16"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="TotalUsers">
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<datasetParameter name="Users">
<datasetParameterExpression><![CDATA[$F{MusicSubscribers}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:listContents height="16" width="555">
<textField pattern="#,##0.00 %" isBlankWhenNull="true">
<reportElement style="table_TD" x="475" y="0" width="80" height="16"/>
<textElement/>
<textFieldExpression><![CDATA[$P{Users}.doubleValue()/$F{TotalUsers}.doubleValue()]]></textFieldExpression>
</textField>
<staticText>
<reportElement style="table_TD" x="0" y="0" width="475" height="16"/>
<textElement textAlignment="Left" markup="none"/>
<text><![CDATA[Proportion of total users]]></text>
</staticText>
</jr:listContents>
</jr:list>
</componentElement>
I would go further to suggest you do as much of the math and collating outside of iReport too, i.e. use stored procedures if your data source is a database.

Related

I can't change range and/or default values in DevExpress Dashboard

I have a page where users register and can make their personal diet plan etc.
I am trying to make some graphs with built-in VS dashboards.
I am using VS 2015 and SQL Server Management Studio 15.0.18206.0 if that matters.
My problems are the following:
Automatic (SUM)
Dashboard values default to SUM function, which I am not able to change, as you see in the first picture, but I kind of managed to solve this problem with the help of SQL (SELECT DISTINCT, SELECT TOP(1) etc.)
Automatic (SUM)
Default year count
When I am trying to make a dashboard to show track of user's vitals and activity, which is the core of my statistics, time defaults to YEAR and the result end up like the second picture.
Default year count
There is nothing I can do to change these and I just made irrelevant graphs to fill the page, but it's a shame because I planned to make a lot of graphs with the table you see in the third picture.
User History table
If it helps, the XML code generated from the last dashboard is this:
<?xml version="1.0" encoding="utf-8"?>
<Dashboard>
<Title Text="YearDashBoard" />
<DataSources>
<SqlDataSource ComponentName="DataSource1">
<Name>UserHistory1</Name>
<Connection Name="foodConnectionString" FromAppConfig="true" />
<Query Type="SelectQuery" Name="UserHistory1" Distinct="true">
<Tables>
<Table Name="UserHistory" />
</Tables>
<Columns>
<Column Table="UserHistory" Name="CaloriesDate" />
<Column Table="UserHistory" Name="DailyCalories" />
<Column Table="UserHistory" Name="UserID" />
</Columns>
<Filter>[UserHistory.UserID] = 17</Filter>
</Query>
<ConnectionOptions CloseConnection="true" CommandTimeout="0" />
</SqlDataSource>
</DataSources>
<Items>
<Chart ComponentName="chartDashboardItem1" Name="Chart 1" DataSource="DataSource1" DataMember="UserHistory1">
<DataItems>
<Measure DataMember="DailyCalories" DefaultId="DataItem0" />
<Dimension DataMember="CaloriesDate" DefaultId="DataItem1" />
</DataItems>
<Arguments>
<Argument DefaultId="DataItem1" />
</Arguments>
<Panes>
<Pane Name="Pane 1">
<Series>
<Simple>
<Value DefaultId="DataItem0" />
</Simple>
</Series>
</Pane>
</Panes>
</Chart>
</Items>
<LayoutTree>
<LayoutGroup Weight="100">
<LayoutItem DashboardItem="chartDashboardItem1" Weight="100" />
</LayoutGroup>
</LayoutTree>
</Dashboard>
Finally, with the help of DevExpress technical team, I found out that the whole time there was an invisible scroll bar, but you had to mouse over it (!) while being on the "BINDING" tab of the menu.

Submit data-table in JSF / Primefaces?

I am working on a web application using jsf/ primefaces, netbeans and tomcat.
I have a datatable with some values loaded in from another table and some editable fields. My question is, after the user has edited this table how do i submit the whole table so it can be stored in a database, in a new table?
<h:form id="form" prependId="false">
<h3>All of your Paddocks</h3>
<p:dataTable var="paddock" value="#{paddock.getfromPaddock()}" editable="true">
<p:ajax event="rowEdit" listener="#{paddock.onRowEdit}" />
<p:ajax event="rowEditCancel" listener="#{paddock.onRowCancel}" />
<p:column headerText="Id">
<h:outputText value="#{paddock.idPaddock}" />
</p:column>
<p:column headerText="Name">
<h:outputText value="#{paddock.name}" />
</p:column>
<p:column headerText="Area">
<h:outputText value="#{paddock.area}" />
</p:column>
<p:column headerText="Enter Grass Weight">
<p:cellEditor>
<f:facet name="output"><h:outputText value="0" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput" value="0" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:32px">
<p:rowEditor />
</p:column>
</p:dataTable>
<h:commandButton value="Log" action="#{paddock.add}" />
</h:form>
Note that the only editable column is the grass column.
First of all, there are two main mistakes which may have undesired side effects:
<h:form ... prependId="false">
Never use prependId. Remove the whole attribute.
<p:dataTable var="paddock" value="#{paddock.getfromPaddock()}">
You should give var a different name than the managed bean. E.g. paddockItem.
As to the concrete question, your other mistake is here:
<p:inputText id="modelInput" value="0" />
You didn't bind the input value to the model. So JSF won't be able to update the model with the submitted values anyway.
Fix it accordingly, e.g.:
<p:inputText id="modelInput" value="#{paddockItem.grass}" />
In the submit method, it'll be right away there in the model.
You should only make absolutely sure that you aren't interacting with the database in the getter method of the <p:dataTable value>, otherwise you will be overwriting the model on every iteration round, hereby basically trashing the submitted values until the last row before the submit method is hit. The strange method name behind the data table value value="#{paddock.getfromPaddock()}" namely suggests that you're doing that. If it were a real property, the average starter would just have used value="#{paddock.fromPaddock}" or so.
See also:
How and when should I load the model from database for h:dataTable

mapnik not rendering postgis multipolygonzm?

So I loaded a bunch of NHD data, and the geometry ended up as MultiPolygonZM (and pointZM and areaZM for other tables)
way geometry(MultiPolygonZM,900913)
I've tested the query and its returning data when run against the db directly. Here's my style:
<Style name="waterways">
<Rule>
<LineSymbolizer stroke="blue" stroke-width="3" />
</Rule>
</Style>
<Layer name="waterways" status="on">
<StyleName>waterways</StyleName>
<Datasource>
<Parameter name="table">
(select way
from nhd_waterbody)
as waterway
</Parameter>
<Parameter name="type">postgis</Parameter>
<Parameter name="port">5432</Parameter>
<Parameter name="user">gisuser</Parameter>
<Parameter name="dbname">gis</Parameter>
<Parameter name="estimate_extent">false</Parameter>
<Parameter name="extent">-20037508,-19929239,20037508,19929239</Parameter>
</Datasource>
</Layer>
But I can't get mapnik (version 2.10) to render it. The osm data is rendering just fine (its standard MultiPolygon, not 4d) from mapnik and qgis (v1.8) map all of it just hunky dory. Has anyone else experienced anything like this? Is it a geometry problem or is that just a red herring? Is there anyway to get mapnik to spit out any type of debug info when rendering?
TIA!
-- Randy
Several GIS programs, such as QGIS, internally use ST_Force_2D to make a 2D drawing from higher-dimension data types. I'm not sure how Mapnik treats these geometries, but I suspect they might not be supported. Also, be sure to double-check the extent, since this is often overlooked.
If you are not actually using the higher dimensions, then remove them! For PostGIS 2.0:
ALTER TABLE my_table
ALTER COLUMN way TYPE geometry(MultiPolygon,900913) USING ST_Force_2D(way);
And for PostGIS 1.x, see this answer.

Fetching data from external XML with Alloy in Titanium

I'm working on my very first iPhone application made in Appcelerator Titanium. I'm using the Alloy framework.
I only have a general JavaScript background. I Have read up on how BackboneJS works, however I am struggling with the concept.
The app is very basic, all I need is to fetch an URL which contains a XML response. Example: http://www.domain.com/api.php?listProducts
This URL will respons something like this
<response>
<request>
<timestamp id="0.66266400 1357656226"/>
<status id="100">OK</status>
</request>
<api_function>getproductsimage</api_function>
<products>
<product id="1">
<images>
<image name="featured" width="640" height="347" src="../html/productImages/featured.jpg"/>
<image name="nonretina" width="125" height="95" src="../html/productImages/thumbnail.jpg"/>
<image name="retina" width="250" height="190" src="../html/productImages/thumbnail.jpg"/>
<image name="ldpi" width="" height="" src=""/>
<image name="mdpi" width="" height="" src=""/>
<image name="hdpi" width="" height="" src=""/>
<image name="xhdpi" width="" height="" src=""/>
</images>
</product>
</product>
</products>
</response>
I want to handle this data in a TableView and obviously there will be more than one response. However I don't really understand the documentation about making an XHR in BackboneJS. Would anyone be able to help me make a simple collection / model for simply fetching this URL and displaying the data.
Thanks in advance
is is purely a backbonejs Model parse issue since backbone works with JSON responses and you are looking at return XML.
There is no requirement that you use Alloy models to solve this problem so you can just implement your solution with http requests and populate the objects yourself.

Jasper Report (iReport) Pie Dataset from main dataset

I want to use a pie chart per group in Jasper iReport, but I don't know how to create a dataset per group.
Assume I have a table as follows:
Table users
---------
category - user - status
Then I have a the following SQL
select * from users order by category
My display has a simple group band of category with detail showing each user and their status. Ideally I would have each category group header show a pie chart with all the distinct statuses and their counts within that group. I'm at a loss as how to do this in iReport.
If I knew all the categories ahead of time I could just create a dataset for each one using the following:
select status, count(user) from user where category = <current category> group by status
I'm attempting to do this using a JRMapCollectionDataSource that resets each group and pulls the data from the rows in the group using a variable, but I'm not very familiar with the whole reset group and increment paradigm.
Any help?
You can solve this issue without programming following this steps:
sort data by category field and by user field (add sorting via iReport or adding ORDER BY clause to the query in case having deal with jdbc datasource);
add two groups: the 1st group - for category field and the 2nd group - for user field (via iReport). Note: It is not necessarily to add GROUP BY clause to the query;
add Pie Chart component to the Group Header band for the category field;
set evaluationTime and evaluationGroup properties for this pieChart.
Here is working sample for demonstrating how to build Pie Chart. In this sample I've used the csv file as datasource.
The chart shows the quantity of users for every category. I used variable usersCount for counting users in every group, but it is was possible to use built-in variable $V{userGroup_COUNT}.
Here is my jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ...>
<field name="category" class="java.lang.Integer"/>
<field name="user" class="java.lang.String"/>
<field name="status" class="java.lang.String"/>
<sortField name="category"/>
<sortField name="user"/>
<variable name="usersCount" class="java.lang.Integer" resetType="Group" resetGroup="userGroup" calculation="Count">
<variableExpression><![CDATA[$F{user}]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
<group name="categoryGroup">
<groupExpression><![CDATA[$F{category}]]></groupExpression>
<groupHeader>
<band height="135">
<pieChart>
<chart evaluationTime="Group" evaluationGroup="categoryGroup">
<reportElement x="158" y="0" width="200" height="135"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset>
<dataset resetType="Group" resetGroup="categoryGroup" incrementType="Group" incrementGroup="userGroup"/>
<keyExpression><![CDATA[$F{user}]]></keyExpression>
<valueExpression><![CDATA[$V{usersCount}]]></valueExpression>
<labelExpression><![CDATA[String.valueOf($V{usersCount})]]></labelExpression>
</pieDataset>
<piePlot>
<plot/>
<itemLabel/>
</piePlot>
</pieChart>
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["Category: " + $F{category}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
<group name="userGroup">
<groupExpression><![CDATA[$F{user}]]></groupExpression>
</group>
<title>
<band height="79" splitType="Stretch"/>
</title>
</jasperReport>
Here is my csv file (data file - datasource):
category,user,status
1,user1,WORK
1,user1,HOLIDAY
1,user2,SICK
2,user1,WORK
2,user2,WORK
2,user2,HOLIDAY
2,user3,HOLIDAY
2,user4,SICK
3,user1,HOLIDAY
3,user3,HOLIDAY
3,user5,HOLIDAY
4,user1,WORK
4,user1,HOLIDAY
4,user2,SICK
4,user2,WORK
4,user2,SICK
4,user3,HOLIDAY
4,user4,HOLIDAY
4,user5,HOLIDAY
The result will be (via iReport preview):

Resources