vbouq Posted January 25, 2012 Share Posted January 25, 2012 Hello,In JasperServer (4.1), how can I transmit the user id as parameter in a report.I need it to apply grants to the returned data.Thanks. Link to comment Share on other sites More sharing options...
txemacarcar Posted January 26, 2012 Share Posted January 26, 2012 HelloI have the same problem. Is there any way to print the name or user ID that has been validated in jasperserver? Is there a parameter or variable something like $P{userid}?Thank you! Link to comment Share on other sites More sharing options...
brooneyx1 Posted January 27, 2012 Share Posted January 27, 2012 I attached a small jrxml file that I use to display the properties assigned to the logged in user. I usually add $P{LoggedInUser} in my reports to show who ran the report. http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 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 http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="UserData" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" 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"/> <parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User" isForPrompting="false"/> <parameter name="LoggedInUsername" class="java.lang.String" isForPrompting="false"/> <parameter name="LoggedInUserFullName" class="java.lang.String" isForPrompting="false"/> <parameter name="LoggedInUserEmailAddress" class="java.lang.String" isForPrompting="false"/> <parameter name="LoggedInUserEnabled" class="java.lang.Boolean" isForPrompting="false"/> <parameter name="LoggedInUserExternallyDefined" class="java.lang.Boolean" isForPrompting="false"/> <parameter name="LoggedInUserTenantId" class="java.lang.String" isForPrompting="false"/> <parameter name="LoggedInUserRoles" class="java.util.Collection" isForPrompting="false"/> <parameter name="LoggedInUserAttributes" class="java.util.Map" isForPrompting="false"/> <parameter name="LoggedInUserAttributeNames" class="java.util.Collection" isForPrompting="false"/> <parameter name="LoggedInUserAttributeValues" class="java.util.Collection" isForPrompting="false"/> <background> <band splitType="Stretch"/> </background> <title> <band height="468" splitType="Stretch"> <frame> <reportElement mode="Opaque" x="28" y="0" width="476" height="172" backcolor="#CCCCCC"/> <textField> <reportElement mode="Transparent" x="111" y="0" width="318" height="20" backcolor="#FFFFFF"/> <textElement/> <textFieldExpression><![CDATA[""+$P{LoggedInUser}]]></textFieldExpression> </textField> <textField> <reportElement mode="Transparent" x="111" y="20" width="318" height="20" backcolor="#FFFFFF"/> <textElement/> <textFieldExpression><![CDATA[$P{LoggedInUsername}]]></textFieldExpression> </textField> <textField> <reportElement mode="Transparent" x="111" y="40" width="318" height="20" backcolor="#FFFFFF"/> <textElement/> <textFieldExpression><![CDATA[$P{LoggedInUserFullName}]]></textFieldExpression> </textField> <textField> <reportElement mode="Transparent" x="111" y="60" width="318" height="20" backcolor="#FFFFFF"/> <textElement/> <textFieldExpression><![CDATA[$P{LoggedInUserEmailAddress}]]></textFieldExpression> </textField> <textField> <reportElement mode="Transparent" x="111" y="80" width="318" height="20" backcolor="#FFFFFF"/> <textElement/> <textFieldExpression><![CDATA[$P{LoggedInUserTenantId}]]></textFieldExpression> </textField> <textField> <reportElement stretchType="RelativeToTallestObject" mode="Transparent" x="-107" y="60" width="318" height="20" backcolor="#FFFFFF"/> <textElement/> <textFieldExpression><![CDATA[""+$P{LoggedInUserRoles}]]></textFieldExpression> </textField> <textField> <reportElement mode="Transparent" x="111" y="120" width="100" height="20" isRemoveLineWhenBlank="true" backcolor="#FFFFFF"/> <textElement/> <textFieldExpression><![CDATA[""+$P{LoggedInUserAttributes}]]></textFieldExpression> </textField> <staticText> <reportElement mode="Transparent" x="0" y="0" width="100" height="20" backcolor="#FFFFFF"/> <textElement/> <text><![CDATA[user]]></text> </staticText> <staticText> <reportElement mode="Transparent" x="0" y="80" width="100" height="20" backcolor="#FFFFFF"/> <textElement/> <text><![CDATA[TenantId]]></text> </staticText> <staticText> <reportElement mode="Transparent" x="0" y="60" width="100" height="20" backcolor="#FFFFFF"/> <textElement/> <text><![CDATA[Email]]></text> </staticText> <staticText> <reportElement mode="Transparent" x="0" y="40" width="100" height="20" backcolor="#FFFFFF"/> <textElement/> <text><![CDATA[Full Name]]></text> </staticText> <staticText> <reportElement mode="Transparent" x="0" y="20" width="100" height="20" backcolor="#FFFFFF"/> <textElement/> <text><![CDATA[userName]]></text> </staticText> <staticText> <reportElement mode="Transparent" x="0" y="140" width="100" height="20" backcolor="#FFFFFF"/> <textElement/> <text><![CDATA[Roles]]></text> </staticText> <staticText> <reportElement mode="Transparent" x="0" y="120" width="100" height="20" backcolor="#FFFFFF"/> <textElement/> <text><![CDATA[Attributes]]></text> </staticText> </frame> </band> </title></jasperReport> Link to comment Share on other sites More sharing options...
txemacarcar Posted January 27, 2012 Share Posted January 27, 2012 Thanks brooneyx1!!But I get the error that it show in the attachment.Any idea?Thank you. Code:Compilation exceptions: com.jaspersoft.ireport.designer.compiler.ErrorsCollector@1b818b0 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 = ""+((com.jaspersoft.jasperserver.api.metadata.user.domain.User)parameter_LoggedInUser.getValue()); //$JR_EXPR_ID=8$                              <-------------------------------------------------------> 2. com.jaspersoft.jasperserver.api.metadata.user.domain.User cannot be resolved to a type                 value = ""+((com.jaspersoft.jasperserver.api.metadata.user.domain.User)parameter_LoggedInUser.getValue()); //$JR_EXPR_ID=8$                              <-------------------------------------------------------> 3. com.jaspersoft.jasperserver.api.metadata.user.domain.User cannot be resolved to a type                 value = ""+((com.jaspersoft.jasperserver.api.metadata.user.domain.User)parameter_LoggedInUser.getValue()); //$JR_EXPR_ID=8$                              <-------------------------------------------------------> 3 errors     at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:191)     at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:499)     at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)     at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) Link to comment Share on other sites More sharing options...
twmoore Posted January 27, 2012 Share Posted January 27, 2012 I think brooneyx1 might have left the defaultValueExpression for LoggedInUserName. I have done something similar with iReports. I have attached what I use. I tried to find the webpage that documents com.jaspersoft.jasperserver.api.metadata.user.domain.User but can't find it. There are a number of other methods you can call for the class.Code: <parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/> <parameter name="LoggedInUsername" class="java.lang.String" isForPrompting="false"> <defaultValueExpression><![CDATA[(Object)$P{LoggedInUser}.getUsername()]]></defaultValueExpression> </parameter> Link to comment Share on other sites More sharing options...
txemacarcar Posted January 27, 2012 Share Posted January 27, 2012 Sorry, I got the error because I was running on iReport. Once uploaded to the server works fine and displays the user data correctly.Thank you very much for your help! Link to comment Share on other sites More sharing options...
brooneyx1 Posted January 27, 2012 Share Posted January 27, 2012 Yes, sorry about leaving out that important peice of information. The report will only work in jasperserver, not in iReport ! Link to comment Share on other sites More sharing options...
vbouq Posted March 14, 2012 Author Share Posted March 14, 2012 Works fine. Ty Link to comment Share on other sites More sharing options...
hgothankar Posted June 11, 2019 Share Posted June 11, 2019 Hi,I am using Jasper 7 version, is LoggedInUser parameter deprecated for this version. I am not able to import user interface. 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