aavila_1 Posted September 20, 2018 Share Posted September 20, 2018 Hi to all! im new in this, and i want to know how to display a single field value in text field for example, get the company name from the data source and set it to the header from a colum, is that possible? Link to comment Share on other sites More sharing options...
Solution reportdev Posted September 20, 2018 Solution Share Posted September 20, 2018 there are multiple ways of doing it. if your company name is in the same datasource, then you can create a variable using First Calculation like below<variable name="companyName" class="java.lang.String" calculation="First"> <variableExpression><![CDATA[$F{VALUE_FIELD}]]></variableExpression> </variable>[/code]If the company_name is from a different datasource, then you can use a table element and get it into the main jrxml.<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.4.2.final using JasperReports Library version 6.4.1 --><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="SingleField" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="e47c954d-72a7-4277-902f-0f16c4b078c1"> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <style name="Table_TH" mode="Opaque" backcolor="#F0F8FF"> <box> <pen lineWidth="0.5" lineColor="#000000"/> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> </style> <style name="Table_CH" mode="Opaque" backcolor="#BFE1FF"> <box> <pen lineWidth="0.5" lineColor="#000000"/> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> </style> <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF"> <box> <pen lineWidth="0.5" lineColor="#000000"/> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> </style> <subDataset name="db_name" uuid="8b3fccae-56b6-4f50-b924-efb505b943bc"> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="PRODSUP"/> <queryString language="SQL"> <![CDATA[select name from V$DATABASE]]> </queryString> <field name="NAME" class="java.lang.String"/> </subDataset> <queryString> <![CDATA[select 'Value1' as value_field from dualunion allselect 'Value12' as value_field from dualunion allselect 'Value13' as value_field from dualunion allselect 'Value14' as value_field from dualunion allselect 'Value15' as value_field from dualunion allselect 'Value16' as value_field from dualunion allselect 'Value17' as value_field from dualunion allselect 'Value18' as value_field from dual]]> </queryString> <field name="VALUE_FIELD" class="java.lang.String"/> <background> <band splitType="Stretch"/> </background> <columnHeader> <band height="60" splitType="Stretch"> <staticText> <reportElement x="0" y="0" width="100" height="30" uuid="4f23c596-fe25-4c21-a421-f95eac766fa6"/> <text><![CDATA[VALUE_FIELD]]></text> </staticText> <componentElement> <reportElement x="0" y="30" width="555" height="30" uuid="491dde32-9612-492c-8cc0-e069820aaa9d"> <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/> <property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/> <property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/> <property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/> </reportElement> <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"> <datasetRun subDataset="db_name" uuid="5115ebf1-1a46-4252-83b3-178309bf958e"> <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression> </datasetRun> <jr:column width="410" uuid="80251a28-4f2e-499f-af5d-685460549cfa"> <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/> <jr:detailCell style="Table_TD" height="30"> <textField> <reportElement x="0" y="0" width="410" height="30" uuid="a1569733-9bbf-45cc-a1de-f111e97abdbd"/> <textFieldExpression><![CDATA["Currently fetching Data from Database " + $F{NAME}]]></textFieldExpression> </textField> </jr:detailCell> </jr:column> </jr:table> </componentElement> </band> </columnHeader> <detail> <band height="30" splitType="Stretch"> <textField> <reportElement x="0" y="0" width="100" height="30" uuid="dbb7850a-b4f6-4cef-b394-1cb27bc4db35"/> <textFieldExpression><![CDATA[$F{VALUE_FIELD}]]></textFieldExpression> </textField> </band> </detail></jasperReport>[/code] Link to comment Share on other sites More sharing options...
aavila_1 Posted September 20, 2018 Author Share Posted September 20, 2018 Thanks very much, im still in the learning phase, but will analyze your awser, thanks again Link to comment Share on other sites More sharing options...
aavila_1 Posted October 1, 2018 Author Share Posted October 1, 2018 can you please share a example how do this with cvs file as datasource? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now