Hello,
I got started with JasperIntelligence reports. I am able to work with the formats, groups, totals etc... But I would like to know is there any option of displaying the user_name(the person who has created the report) on the report. If anyone has worked with it, please give an example.
Thanks in advance,
Mohan
I got started with JasperIntelligence reports. I am able to work with the formats, groups, totals etc... But I would like to know is there any option of displaying the user_name(the person who has created the report) on the report. If anyone has worked with it, please give an example.
Thanks in advance,
Mohan
9 Answers:
Posted on November 7, 2006 at 9:00pm
In your JRXML that will run in JasperIntelligence, add:
<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>
All reports get passed this parameter.
From this LoggedInUser object you can get:
<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>
All reports get passed this parameter.
From this LoggedInUser object you can get:
Code: |
public String getUsername();<br /> <br /> public String getFullName();<br /> <br /> public String getEmailAddress();<br /> <br /> public boolean isExternallyDefined();<br /> <br /> public boolean isEnabled();<br /> <br /> public Set getRoles();<br /> </td></tr></tbody></table><br /> <br /> <br /> Sherman<br /> JasperSoft |
Posted on November 8, 2006 at 11:10am
Hello Sherman,
Thanks a lot for the solution.
I am getting the user name displayed in the JasperIntelligence environment. But when I export the same report to html or pdf formats, I am not able to get the username on the report which is in html or pdf format. Can I get the user name displayed on the corresponding html or pdf?
Please can you give some solution for this?
Thank you so much,
Mohan.
swood wrote:
Thanks a lot for the solution.
I am getting the user name displayed in the JasperIntelligence environment. But when I export the same report to html or pdf formats, I am not able to get the username on the report which is in html or pdf format. Can I get the user name displayed on the corresponding html or pdf?
Please can you give some solution for this?
Thank you so much,
Mohan.
swood wrote:
In your JRXML that will run in JasperIntelligence, add: <parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/> All reports get passed this parameter. From this LoggedInUser object you can get:
|
Posted on November 8, 2006 at 12:12pm
Our unit tests export the user name to all formats.
Does your report fail? Or just come up with a blank user? In the JRXML, we do things like:
Does your report fail? Or just come up with a blank user? In the JRXML, we do things like:
Code: |
<textFieldExpression class="java.lang.String">msg("{0}", $P{LoggedInUser}.getFullName())</textFieldExpression><br /> </td></tr></tbody></table><br /> <br /> <br /> Sherman<br /> JasperSoft |
Posted on November 13, 2006 at 1:23pm
Hello Sherman,
I tried the putting the piece of code you had sent. For me it didn't work. My be I was wrong some where. So can you please suggest me more elaborately about how to get the user_name on the report. Iam getting it in the JasperIntelligence environment. But after exporting the same report to pdf, html,... Iam not able to get that. Can you please help me in more detailed manner, please?
Thank you,
Mohan.
swood wrote:
I tried the putting the piece of code you had sent. For me it didn't work. My be I was wrong some where. So can you please suggest me more elaborately about how to get the user_name on the report. Iam getting it in the JasperIntelligence environment. But after exporting the same report to pdf, html,... Iam not able to get that. Can you please help me in more detailed manner, please?
Thank you,
Mohan.
swood wrote:
Our unit tests export the user name to all formats. Does your report fail? Or just come up with a blank user? In the JRXML, we do things like:
|
Posted on November 15, 2006 at 12:42pm
The report fails here. I changed the JRXML file the same way as you have suggested. There might be something wrong from my side. I am not able to make out. The error is:
it.businesslogic.ireport.ReportClassLoader@1757423 net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: 1. com.jaspersoft.jasperserver.api.metadata.user.domain.User cannot be resolved to a type value = (java.lang.String)(msg("{0}", ((com.jaspersoft.jasperserver.api.metadata.user.domain.User)parameter_LoggedInUser.getValue()).getFullName())); <-------------------------------------------------------> 2. com.jaspersoft.jasperserver.api.metadata.user.domain.User cannot be resolved to a type value = (java.lang.String)(msg("{0}", ((com.jaspersoft.jasperserver.api.metadata.user.domain.User)parameter_LoggedInUser.getValue()).getFullName())); <-------------------------------------------------------> 3. com.jaspersoft.jasperserver.api.metadata.user.domain.User cannot be resolved to a type value = (java.lang.String)(msg("{0}", ((com.jaspersoft.jasperserver.api.metadata.user.domain.User)parameter_LoggedInUser.getValue()).getFullName())); <-------------------------------------------------------> 3 errors
swood wrote:
it.businesslogic.ireport.ReportClassLoader@1757423 net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: 1. com.jaspersoft.jasperserver.api.metadata.user.domain.User cannot be resolved to a type value = (java.lang.String)(msg("{0}", ((com.jaspersoft.jasperserver.api.metadata.user.domain.User)parameter_LoggedInUser.getValue()).getFullName())); <-------------------------------------------------------> 2. com.jaspersoft.jasperserver.api.metadata.user.domain.User cannot be resolved to a type value = (java.lang.String)(msg("{0}", ((com.jaspersoft.jasperserver.api.metadata.user.domain.User)parameter_LoggedInUser.getValue()).getFullName())); <-------------------------------------------------------> 3. com.jaspersoft.jasperserver.api.metadata.user.domain.User cannot be resolved to a type value = (java.lang.String)(msg("{0}", ((com.jaspersoft.jasperserver.api.metadata.user.domain.User)parameter_LoggedInUser.getValue()).getFullName())); <-------------------------------------------------------> 3 errors
swood wrote:
You are not giving enough information here. As I asked: "Does your report fail? Or just come up with a blank user?" Sherman JasperSoft |
Posted on November 17, 2006 at 1:33pm
So the report does not compile in iReport.
If you want to do this, you will need to get the jasperserver-api-metadata-XXX.jar and probably jasperserver-api-common-XXX.jar from the server and include it in the iReport classpath. That should allow the report to compile.
It will not run and produce a report in standalone iReport, as that parameter will come from the server at runtime. You can use the iReport JasperIntelligence plugin to publish the report through the server, or use the server maintenance screens to create a report unit using this JRXML.
Sherman
JasperSoft
If you want to do this, you will need to get the jasperserver-api-metadata-XXX.jar and probably jasperserver-api-common-XXX.jar from the server and include it in the iReport classpath. That should allow the report to compile.
It will not run and produce a report in standalone iReport, as that parameter will come from the server at runtime. You can use the iReport JasperIntelligence plugin to publish the report through the server, or use the server maintenance screens to create a report unit using this JRXML.
Sherman
JasperSoft
Posted on September 24, 2009 at 8:38am
Whenever I try to do this, I always get 'null' as a value. I only have JasperServer installed and not the Intelligence Suite. Does this only work if I install the entire suite?
For testing I have the parameter set to display in the title section.
Code: |
<?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports <a href="http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"" target="_blank">http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"</a> name="new351" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true"> <style name="Crosstab Data Text" isDefault="false" hAlign="Center"/> <parameter name="LoggedInUserName" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"> <defaultValueExpression><![CDATA[$P{LoggedInUserName}.getUsername()]]></defaultValueExpression> </parameter> <queryString> <![CDATA[SELECT SUM(i.Available) AS Quantity, Style, Color, if(isnull(g.Group_Name),p.Size,g.Group_Name) AS 'Size', if(isnull(g.Group_Rank),99999999,g.Group_Rank) AS 'rank' FROM inventory i INNER JOIN product p ON i.Product_ID=p.Product_ID LEFT OUTER JOIN product_size s ON p.Size=s.Size LEFT OUTER JOIN Product_Size_Group g ON g.Size_ID=s.Size_ID WHERE i.Client_ID='FDJ' GROUP BY Style, Color, if(isnull(g.Group_Name),s.Size,g.Group_Name)]]> </queryString> <field name="Quantity" class="java.math.BigDecimal"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="Style" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="Color" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="Size" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="rank" class="java.math.BigDecimal"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <variable name="TOTAL_QUANTITY" class="java.lang.Integer" calculation="Sum"> <variableExpression><![CDATA[$F{Quantity}]]></variableExpression> </variable> <background> <band/> </background> <title> <band height="92"> <staticText> <reportElement x="361" y="20" width="262" height="36"/> <textElement> <font size="24" isBold="true"/> </textElement> <text><![CDATA[Inventory Report - FDJ]]></text> </staticText> <textField pattern="K:mm a, z"> <reportElement x="702" y="0" width="100" height="20"/> <textElement/> <textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression> </textField> <image> <reportElement x="0" y="0" width="327" height="83"/> <imageExpression class="java.lang.String"><![CDATA["C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\nepco3\\images\\header.gif"]]></imageExpression> </image> <textField> <reportElement x="394" y="63" width="100" height="20"/> <textElement/> <textFieldExpression class="java.lang.String"><![CDATA[$P{LoggedInUserName}]]></textFieldExpression> </textField> </band> </title> <pageHeader> <band/> </pageHeader> <columnHeader> <band/> </columnHeader> <detail> <band/> </detail> <columnFooter> <band/> </columnFooter> <pageFooter> <band/> </pageFooter> <lastPageFooter> <band height="38"> <staticText> <reportElement x="642" y="18" width="60" height="20"/> <textElement> <font size="12" isBold="true"/> </textElement> <text><![CDATA[Total:]]></text> </staticText> <textField> <reportElement x="702" y="18" width="100" height="20"/> <textElement/> <textFieldExpression class="java.lang.Integer"><![CDATA[$V{TOTAL_QUANTITY}]]></textFieldExpression> </textField> </band> </lastPageFooter> <summary> <band height="71"> <crosstab> <reportElement mode="Transparent" x="0" y="0" width="802" height="68" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true"/> <rowGroup name="Style" width="61"> <bucket> <bucketExpression class="java.lang.String"><![CDATA[$F{Style}]]></bucketExpression> </bucket> <crosstabRowHeader> <cellContents backcolor="#F0F8FF" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textField> <reportElement style="Crosstab Data Text" x="0" y="0" width="61" height="25"/> <textElement verticalAlignment="Middle"> <font isBold="false"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$V{Style}]]></textFieldExpression> </textField> </cellContents> </crosstabRowHeader> <crosstabTotalRowHeader> <cellContents/> </crosstabTotalRowHeader> </rowGroup> <rowGroup name="Color" width="31"> <bucket> <bucketExpression class="java.lang.String"><![CDATA[$F{Color}]]></bucketExpression> </bucket> <crosstabRowHeader> <cellContents backcolor="#F0F8FF" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textField> <reportElement style="Crosstab Data Text" x="0" y="0" width="31" height="25"/> <textElement verticalAlignment="Middle"> <font isBold="false"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$V{Color}]]></textFieldExpression> </textField> </cellContents> </crosstabRowHeader> <crosstabTotalRowHeader> <cellContents/> </crosstabTotalRowHeader> </rowGroup> <columnGroup name="rank" height="0" totalPosition="End"> <bucket> <bucketExpression class="java.math.BigDecimal"><![CDATA[$F{rank}]]></bucketExpression> </bucket> <crosstabColumnHeader> <cellContents backcolor="#F0F8FF" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> </cellContents> </crosstabColumnHeader> <crosstabTotalColumnHeader> <cellContents backcolor="#005FB3" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <staticText> <reportElement x="0" y="0" width="36" height="42" forecolor="#FFFFFF"/> <textElement textAlignment="Center" verticalAlignment="Middle"> <font isBold="false"/> </textElement> <text><![CDATA[Total]]></text> </staticText> </cellContents> </crosstabTotalColumnHeader> </columnGroup> <columnGroup name="Size" height="42" totalPosition="End"> <bucket> <bucketExpression class="java.lang.String"><![CDATA[$F{Size}]]></bucketExpression> </bucket> <crosstabColumnHeader> <cellContents backcolor="#F0F8FF" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textField> <reportElement style="Crosstab Data Text" x="0" y="0" width="34" height="42"/> <textElement verticalAlignment="Top"> <font isBold="false"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$V{Size}]]></textFieldExpression> </textField> </cellContents> </crosstabColumnHeader> <crosstabTotalColumnHeader> <cellContents backcolor="#BFE1FF" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> </cellContents> </crosstabTotalColumnHeader> </columnGroup> <measure name="QuantityMeasure" class="java.math.BigDecimal"> <measureExpression><![CDATA[$F{Quantity}]]></measureExpression> </measure> <crosstabCell width="34" height="25"> <cellContents> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textField isBlankWhenNull="true"> <reportElement style="Crosstab Data Text" x="0" y="0" width="34" height="25"/> <textElement verticalAlignment="Middle"/> <textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{QuantityMeasure}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell height="25" rowTotalGroup="Style"> <cellContents backcolor="#005FB3" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textField> <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25" forecolor="#FFFFFF"/> <textElement/> <textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{QuantityMeasure}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell width="36" columnTotalGroup="rank"> <cellContents backcolor="#005FB3" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textField isBlankWhenNull="true"> <reportElement style="Crosstab Data Text" x="0" y="0" width="36" height="25" forecolor="#FFFFFF"/> <textElement verticalAlignment="Middle"/> <textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{QuantityMeasure}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell rowTotalGroup="Style" columnTotalGroup="rank"> <cellContents backcolor="#005FB3" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textField> <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25" forecolor="#FFFFFF"/> <textElement/> <textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{QuantityMeasure}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell width="0" columnTotalGroup="Size"> <cellContents backcolor="#BFE1FF" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> </cellContents> </crosstabCell> <crosstabCell rowTotalGroup="Style" columnTotalGroup="Size"> <cellContents backcolor="#005FB3" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textField> <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25" forecolor="#FFFFFF"/> <textElement/> <textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{QuantityMeasure}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell height="25" rowTotalGroup="Color"> <cellContents backcolor="#BFE1FF" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textField> <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/> <textElement/> <textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{QuantityMeasure}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell rowTotalGroup="Color" columnTotalGroup="rank"> <cellContents backcolor="#005FB3" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textField> <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25" forecolor="#FFFFFF"/> <textElement/> <textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{QuantityMeasure}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> <crosstabCell rowTotalGroup="Color" columnTotalGroup="Size"> <cellContents backcolor="#BFE1FF" mode="Opaque"> <box> <pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textField> <reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/> <textElement/> <textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{QuantityMeasure}]]></textFieldExpression> </textField> </cellContents> </crosstabCell> </crosstab> </band> </summary> <noData> <band/> </noData> </jasperReport> |
Post Edited by emiii0 at 09/24/2009 15:48
Post Edited by emiii0 at 09/24/2009 15:49
Posted on September 24, 2009 at 4:03pm
emiii0,
Yes, JasperServer is all you need. Please start a new thread, as the details of whatever is causing the problem are likely to have changed since the main thread 3 years ago.
For troubleshooting purposes, please post a minimal .jrxml file that just shows the problem (without the additional crosstab).
Regards,
Matt