Using Jasperserver user login in report

I've read all the entries related to how to use a user login in a report, but I'm missing something.

I've got 3.7 verson of jasperserver and the 3.6 version of iReports.

 

Most of the posts related to this say that you need to create 2 parameters.  In iReports I've created a parameter LoggedInUser and set the Parameter Class to com.jaspersoft.jasperserver.api.metadata.user.domain.User and with a default value expression = Test

Then I create a second parameter UserID and give it a default value expression of $P{LoggedInUser}.getFullName()

The report has only one element - a text field to show the value of UserID.  When compiled I get the error - ClassNotFoundException:  com.jaspersoft.jasperserver.api.metadata.user.domain.User

Can anyone tell me what I'm doing wrong??

Here is the XML -

<?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 http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="LoginNameTest" language="groovy" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
 <parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false">
  <defaultValueExpression><![CDATA[aaa]]></defaultValueExpression>
 </parameter>
 <parameter name="UserID" class="java.lang.String">
  <defaultValueExpression><![CDATA[$P{LoggedInUser}.getFullName()]]></defaultValueExpression>
 </parameter>
 <background>
  <band/>
 </background>
 <title>
  <band height="79"/>
 </title>
 <pageHeader>
  <band height="35"/>
 </pageHeader>
 <columnHeader>
  <band height="61"/>
 </columnHeader>
 <detail>
  <band height="125">
   <textField>
    <reportElement x="247" y="58" width="100" height="20"/>
    <textElement/>
    <textFieldExpression class="java.lang.String"><![CDATA[$P{UserID}.toString()]]></textFieldExpression>
   </textField>
  </band>
 </detail>
 <columnFooter>
  <band height="45"/>
 </columnFooter>
 <pageFooter>
  <band height="54"/>
 </pageFooter>
 <summary>
  <band height="42"/>
 </summary>
</jasperReport>
 

 

dknutson's picture
392
Joined: Oct 4 2006 - 7:26am
Last seen: 8 years 4 months ago

14 Answers:

Hello,

The class com.jaspersoft.jasperserver.api.metadata.user.domain.User

exists only on the server so if you try to compile your report only with iReport this will not work.

Try to upload your report in the server and then run it from the server.

Hope this helps,

Guillaume



Post Edited by gautier at 01/10/2010 05:45
gautier's picture
910
Joined: Oct 15 2008 - 7:09am
Last seen: 8 years 2 months ago
Thanks for the reply. I was thinking that if I copy the correct jar to the iReports lib folder, then set LoggedInUser with a default, it should work. Problem is I'm not sure of which jar and where to put it - iReports or Java folder
dknutson's picture
392
Joined: Oct 4 2006 - 7:26am
Last seen: 8 years 4 months ago
On a side note, I have switched to using:
<parameter name="LoggedInUsername" class="java.lang.String" isForPrompting="false"/>

This eliminates one parameter in order to get the user name, and I have experienced it to be a more stable solution.
msn's picture
msn
218
Joined: Dec 23 2009 - 2:00am
Last seen: 13 years 9 months ago
How exactly are you useing "LoggedInUsername" and what do you mean by eliminates one parameter?
I've tried using it by itself setup as you describe and it come up null. I've gotten it to work where LoggedInUsername references a second parameter containing LoggedInUser.getUserName(), but at this time I can't get the parameter to work in a query.
dknutson's picture
392
Joined: Oct 4 2006 - 7:26am
Last seen: 8 years 4 months ago

I have only tried this with JasperServer 3.5.0, but the only thing you have to do, is in iReport to add a parameter of type String which is called "LoggedInUsername" (and that's the name reserved by JasperReport). This should correspond to manually adding the jrxml as listed in my last reply.

Come to think about it, the LoggedInUsername gives you the login name of the user currently logged in to the JasperServer, and not the attached Full Name field of this Jasper user account.
However, if the username (not the full name) would suffice, for me having the LoggedInUsername as String parameter replaced the need for having both the "LoggedInUser" parameter and the second parameter with default value $P{LoggedInUser}.getUsername().

I think perhaps "LoggedInUserFullName" exists as well. Also a String parameter that Jasper provides automatically without any input control.



Post Edited by msn at 01/11/2010 16:30
msn's picture
msn
218
Joined: Dec 23 2009 - 2:00am
Last seen: 13 years 9 months ago
Thanks - that clears up something. A few months back I tried this with 3.5 and had no problems. With 3.7 it doesn't work. I think I'll reload 3.5.
dknutson's picture
392
Joined: Oct 4 2006 - 7:26am
Last seen: 8 years 4 months ago
I just loaded up a 3.5 Jasperserver and tested this. I logged in as userid = DMKTest. It's giving me the current default for LoggedInUsername "DMK" not the userid. Any idea why?
dknutson's picture
392
Joined: Oct 4 2006 - 7:26am
Last seen: 8 years 4 months ago

The parameters available are defined on this wiki page: http://jasperforge.org/plugins/mwiki/index.php/Jasperserver/Cascading_input_controls

 

@dknutson:  I don't know why you are not getting the right value. It works in general for other folks.

 

Sherman

Jaspersoft

swood's picture
24621
Joined: Jun 21 2006 - 12:48pm
Last seen: 10 years 11 months ago
Create $P{LoggedInUser}.
In the XML, add: <import value="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>

And replace : <parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false">
<defaultValueExpression><![CDATA[aaa]]></defaultValueExpression>
</parameter>
<parameter name="UserID" class="java.lang.String">
<defaultValueExpression><![CDATA[$P{LoggedInUser}.getFullName()]]></defaultValueExpression>
</parameter>

by:
<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/>

There isn't defaultValueExpression in this line.
fab67100's picture
Joined: Jul 8 2010 - 12:51am
Last seen: 7 years 8 months ago

Hello,

sory for my poor english ....

when I add

 <import value="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>
<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/>

I have the error " The selected Jrxml could not be parsed." when i load the JRXML using the Report Wizardof fasperserver 3.7.1

Is it possible to have a simple way to use "LoggedInUser" in que query ?

I do not undersand enough "http://jasperforge.org/plugins/mwiki/index.php/Jasperserver/Cascading_in...

Please help, tell me the way to do this easily ( "copy/paste")


 

 

jpclerc's picture
112
Joined: Nov 10 2010 - 12:47pm
Last seen: 10 years 7 months ago



Post Edited by jpclerc at 01/13/2011 02:10
jpclerc's picture
112
Joined: Nov 10 2010 - 12:47pm
Last seen: 10 years 7 months ago
Hello,

sory for my poor english ....

when I add

<import value="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>
<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/>

I have the error " The selected Jrxml could not be parsed." when i load the JRXML using the Report Wizardof fasperserver 3.7.1

Is it possible to have a simple way to use "LoggedInUser" in que query ?

I do not undersand enough "http://jasperforge.org/plugins/mwiki/index.php/Jasperserver/Cascading_in...

Please help, tell me the way to do this easily ( "copy/paste")
jpclerc's picture
112
Joined: Nov 10 2010 - 12:47pm
Last seen: 10 years 7 months ago

jpclerc,

We appreciate that you take the time and effort to post in English. Please do not worry about any mistakes in grammar or spelling.

You are replying to a thread that is relatively old. Please create a new thread.

Please add a few details. You say that  you got the error when you added that parameter. Can you please confirm that you got no error and everything worked correctly before you added that parameter?

Have you looked at the report /reports/samples/SalesByMonth which ships with JasperServer Pro (now called JasperReports Server)? It has an example of using LoggedInUser. The example is just displaying the value in the report rather than using it in the SQL query... but it would be very easy to use it in the SQL query.

[Please don't respond in this thread, but create a new one instead.]

Regards,
Matt

mdahlman's picture
37490
Joined: Mar 13 2007 - 2:43am
Last seen: 8 years 10 months ago

 So here is how my report looks, i have highlighted the code in red. It does not work on ireport 4.0(giving an error for java.lang.classnotfoundexception: com.jaspersoft.jasperserver.api.metadata.user.domain.User)

and on jasper server 4.0 it just says report is empty and no errors in the catalina.out

can you please let me know what i am missing?

 

<?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 http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="userReport" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">

<property name="ireport.zoom" value="1.0"/>

<property name="ireport.x" value="0"/>

<property name="ireport.y" value="0"/>

<import value="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>

<parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/>

<parameter name="newUser" class="java.lang.String" isForPrompting="false">

<defaultValueExpression><![CDATA[$P{LoggedInUser}.getUsername()]]></defaultValueExpression>

</parameter>

<background>

<band splitType="Stretch"/>

</background>

<title>

<band height="69" splitType="Stretch">

<staticText>

<reportElement x="129" y="21" width="100" height="20"/>

<textElement/>

<text><![CDATA[Trial report]]></text>

</staticText>

</band>

</title>

<pageHeader>

<band height="26" splitType="Stretch"/>

</pageHeader>

<columnHeader>

<band height="13" splitType="Stretch"/>

</columnHeader>

<detail>

<band height="125" splitType="Stretch">

<textField>

<reportElement x="116" y="29" width="173" height="36"/>

<textElement textAlignment="Center"/>

<textFieldExpression class="java.lang.String"><![CDATA[$P{newUser}]]></textFieldExpression>

</textField>

</band>

</detail>

<columnFooter>

<band height="45" splitType="Stretch"/>

</columnFooter>

<pageFooter>

<band height="54" splitType="Stretch"/>

</pageFooter>

<summary>

<band height="42" splitType="Stretch"/>

</summary>

</jasperReport>

 
mandm's picture
463
Joined: Jan 10 2010 - 1:18pm
Last seen: 10 years 1 month ago
Feedback
randomness