Translate

Showing posts with label JasperSoft Studio. Show all posts
Showing posts with label JasperSoft Studio. Show all posts

Friday, 21 November 2014

Jasper Report- JRException: Image read failed

 This Exception comes generally when you try to export the report on Jasper Server in PDF Format, or from iReport, then due to the error in some of the image or all the images, which is producing the error.

So to overcome this issue, you could set following properties of the image:

1. Firstly you could simply setting the Cache Property to true
2. If that does not resolves the issue then you can set the property Error type to Blank


Hope that this helps.

Cheers!!


Monday, 24 March 2014

Using Styles in Jasper Reports

We have been accustomed to use style sheets or CSS in our HTML codes, parallel to that we can use Styles in Jasper Reports also. It provides same utilities like conditional, non -conditional and could be applied on  any element in the Report.

Now how to create styles, there are two methods basically:
1. External Style Sheet (jrtx file)
2. Declaring Internal Styles in the report itself.

The advantages of using external Style sheet is that it provides modularity and re-usability of the style over large number of reports using similar kind of styles. On the other hand, Internal styles would only contains the styles definitions for a particular report.

How to apply styles in the reports(iReport).

1. Locate the Styles node in the Report Inspector.
2. Right Click on the node and add a new Style
3. Then you could define the properties of the Style in the in the properties pane. Properties like background-color,forecolor, outline,.. etc/
4. You could even click on the Style and add a conditional Style and define conditional styles, like alternate coloring and much more.
5. After defining the styles now in the application part, locate the element onto which you want to apply the style.
6. Select the particular style in the property called Style(could be found in the properties pane) of the Element.

I have created a simple tutorial video demonstrating the Styles in Jasper Reports. Click Here

Download the sample demonstrated in the video tutorial from here. The ZIP file contains :
1. The JRXML File
2. The jrtx Style.

The Sample uses the Sample database so no need to worry about the datasource.

Happy Coding.

How to display the Username of the user who logged into JasperServer

Many a times we require the name of the person who logged into the Jasper Server and according to this information we are able to show/hide the elements on report, or simpley to log the user name we can use it.

So how to achieve this ? 


We can create parameters in our report, with a specific name and datatype. Then these parameters will be automatically filled when the report is executed by JasperReports Server.
LoggedInUsername (java.lang.String), with no default value. Then, we can use $P{LoggedInUsername} in a text field, in a query, in a printWhenExpression, etc ...
This is a built in parameter which gets filled with the User Details when report is run on Jasper Server.
Note that the report if run in iReport, would get a null value. So for the correct results it is necessary that we deploy the report onto JasperServer.



Parameter Name
Type
Notes
LoggedInUser
User
Not usable in query input control,
 but is used as parameter to report
LoggedInUsername
String
Of logged in user
LoggedInUserFullName
String
Of logged in user
LoggedInUserEmailAddress
String
Of logged in user
LoggedInUserEnabled
Boolean
Is logged in user enabled?
LoggedInUserExternallyDefined
Boolean
Is logged in user externally defined?
 ie. authenticated externally
LoggedInUserTenantId
String
Of logged in user. Only relevant in 
Pro/Enterprise.
LoggedInUserRoles
Collection<string>
Current set of roles of logged in user. 
Useful for $X parameter
LoggedInUserAttributes
Map<string, string>
Not usable in query input control, but is 
used as parameter to report.
 Empty map if no attributes
LoggedInUserAttributeNames
Collection<string>
User profile attribute names. Useful for
 $X parameters. Empty collection if no
 
attributes
LoggedInUserAttributeValues
Collection
-
LoggedInUserAttribute_<attribute name>
String
Attribute value for matched attribute name (like "att1") on the user. Empty string if no match. Only provided if defined in a query or as a report parameter.

Using the above parameters we could easily get various important information which could help in defining the roles. 

Happy Coding.!!

Friday, 17 January 2014

All you want to know about Scriptlets!!


First question which comes to mind after coming across this word Scriptlet is that does it have any relationships with scripts, if yes then what scripts, the answer  to this question is No it does not have any relation with scripts.    Scriptlets basically act as an interface between the Jasper Reports and Java. It provides much of flexibility to the reporting as now we can introduce user defined functions.

Scriptlet is nothing but a java class which is extended with either
1. net.sf.jasperreports.engine. JRAbstractScriptlet
2. net.sf.jasperreports.engine.JRDefaultScriptlet.

Now we need to identify which class we need to extend based upon the usage, JRAbstractSriptlet contains a number of abstract methods that must be overridden in every implementation, developer must implement all the abstract methods whereas JRDefaultScriptlet contains default empty implementations of every method in JRAbstractScriptlet, a developer is only required to implement those methods he/she needs for their project.

Now following listed are the methods that will be called by the report engine at the appropriate time, during report filling phase.

public void beforeReportInit()
Called before report initialization.
public void afterReportInit()
Called after report initialization.
public void beforePageInit()
Called before each page is initialized.
public void afterPageInit()
Called after each page is initialized.
public void beforeColumnInit()
Called before each column is initialized.
public void afterColumnInit()
Called after each column is initialized.
public void beforeGroupInit(String groupName)
Called before the group specified in the parameter is initialized.
public void afterGroupInit(String groupName)
Called after the group specified in the parameter is initialized.
public void beforeDetailEval()
Called before each record in the detail section of the report is evaluated.
public void afterDetailEval()
Called after each record in the detail section of the report is evaluated.



Except these we can also use User defined custom functions, I have already posted about them in my previous post here is the link-

Few important facts which need to be kept in mind using scriptlets are-
  1. When we do a System.out.println in any of the function then it does not directly print in the report, many a times people have some misconception but to remind System.out.println  is a console command and prints the value in the Report console, that is called the Report output window.
  2.  These functions are fired when the Jasper Print object is created, and it is created when a JRXML runs.


Now after creating our scriptlet classes and packaging  it into a jar file we are ready to use it in our Jasper Report created either in iReport or JasperSoft Studio.

Follow the following  steps to implement scriptlets in iReport
  1.  Add the Scriptlet jar file in the classpath by clicking on the Tools(Menu Bar) à Options à Classpath Tab  and add the Jar file here.
  2.  Locate the Report Inspector Window
  3.  There is a node called Scriptlet, expand the node and we could see REPORT
  4.  You can create a another scriptlet label by right clicking the scriptlet label and then select Add
  5. Now locate the new element called Scriptlet1 under the node SCRIPTLET. (Check Fig-1)
  6.  Navigate to the properties of the Scriptlet1 there could be seen Name, Scriptlet Class and Description.
  7. Now you can enter the desired name for the scriptlet.
  8.  Scriptlet Class  is the fully qualified path of the scriptlet class in the JAR File.
  9.  Description is for the describing the role of the scriptlet ( Check Fig-2)



Follow the following  steps to implement scriptlets in  JasperSoft Studio
  1.  Add the Scriptlet jar file in the classpath by clicking on the Project(Menu Bar) à Properties, then select Java Build Path and external JAR File.
  2.  Locate the Outline window
  3.  There is a node called Scriptlet, expand the node and we could see REPORT_SCRIPTLET
  4.  You can create a another scriptlet label by right clicking the scriptlet label and then select Create Scriptlet (As in Fig 1)
  5. Now locate the new element called Scriptlet_1 under the node SCRIPTLETS.
  6.  Navigate to the properties of the Scriptlet_1 there could be seen Name, Class and Description.
  7. Now you can enter the desired name for the scriptlet.
  8.  Class is the fully qualified path of the scriptlet class in the JAR File.
  9.  Description is for the describing the role of the scriptlet.  (As in Fig 2)




Now until now we have success fully linked the scriptlet JAR with the iReport/JasperSoft Studio, now we need to understand that how can it be used in the report in order to get the desired outputs from the scriptlet or basically from the JAVA end.

To use the scriptlet functions in either iReport/ JasperSoft Studio following are the steps:
  1.  When we successfully create a new scriptlet under the scriptlet node, and define the properties of the scriptlet we could  see a new parameter formed under the Parameter node.
  2.  Locate the scriptlet parameter, you can find the parameter as by default it is named as ( {name of the scriptlet defined}_SCRIPTLET )
  3. Then wherever you want to use any function of the scriptlet, you just need to use as:
    ( {name of the scriptlet defined}_SCRIPTLET ).function Name


That is all we need to implement to use scriptlet in Jasper Reports, hope that the above description and methodology helps to grasp important points.

Here is a sample using the sample database, you can try the above customization too.

                                            ======SAMPLE========


Hope this clears your doubt for this topic. Still if you face any issues or problems then you can add a comment below.


Happy Coding!!