Remove all dropdown list items except selected using jQuery


So this example I can divided in to two parts.
1. When the drop-down list value already set from the back end.
2. Remove drop-down option when user change the drop down list values.

When the drop-down list value already set from the back end.
That means the drop-down data already defined from the back end and we need to display the drop-down list data according to the data came from the back end.
For example, If there are several locations available in the system and according to the login user location we need to customize the drop down list for the user.
If the user location is "Matara" we need to remove all other locations from drop-down and display "Matara" to user as the location.


Here I unable to set the drop-down value from back end, so I have to set the value in document ready function using jQuery.


So it remove the values other than selected.

Remove drop-down option when user change the drop down list values.
When the time user change the drop down, It only remain the selected option and other options are removed.


Now we have drop-down list with Fruits(Grapes, Bananas, Oranges and Apples).
So we need to remove the options other than selected option.
For example, If user select Apples, then drop-down list only contains Apples, other options should be removed.


Output displays Select Fruit and Apple
If you want to remove Select fruit option also, You can remove :eq(0) from onChange function.



Java / Struts - File Upload (csv as zip) , Save , Unzip & Rename

This is simple file upload example with Struts and Java.
You can find the sample project at end of the tutorial.

First I have to describe the requirements.
  1. We need to upload the csv file as a zip file.
  2. We Need to save and unzip the zip file .
  3. Get the csv file and rename
According to the requirement the csv file size is more than 100Mb.
For that reason user need to zip the file and it help's to reduse the file size.
For example if original csv file size is 350Mb, after zip it is around 65Mb so its easy to upload with less bandwidth (:)).
First you need to create project using Maven(You can find the sample project at end of the tutorial).
struts.xml


   
My index.jsp redirected to upload.Action so it is return the UploadFile.jsp
   

In here my Action class is UploadFileAction and it contains uploadFile methaod that contains the file uploading functionality.
I have use the file saving location as struts parameter (filesPath) and it will be directly accessed by the action class using getters and setters.

I have use to struts intercepter for validate the file size and define the maximum file size.


Also that intercepter use to allowed only zip files. That means user can only upload the zip files they can't upload other file types.

  
This execAndWait intercepter do the important job here.
When you uploading large size of file it getting long time to upload(it will depends on you internet connection).

Apache Struts 2 Documentation Say's
Source : https://struts.apache.org/docs/execute-and-wait-interceptor.html

Execute and Wait Interceptor


The ExecuteAndWaitInterceptor is great for running long-lived actions in the background while showing the user a nice progress meter.
This also prevents the HTTP request from timing out when the action takes more than 5 or 10 minutes.
This interceptor also supports using an initial wait delay.

Here I use delay and it is optional (delay - an initial delay in millis to wait before the wait page is shown (returning wait as result code))
Until file upload success, reloading the uploadDataWait page by Execute and Wait Interceptor.

   
uploadFile method in UploadFileAction is calling three methds in FilesUtill class.

After successful upload the zip file and extracted csv file can find the given location. Also user redirected to UploadFileSuccess page.




For more details you can use given working sample source codes.

Download

Jasper Report - Sort Report Content By Report Variable



In here I’m using

Product Version: Jaspersoft iReport Designer Professional 5.0.0
Java                    : 1.6.0_45
System               : Windows 7

First create jasper report variable, in this example it is Expenditure_order.
According to my requirement it is type of String and calculation nothing and Reset type Report.


After that we need to define variable expression for sorting.

In my case there are 3 expenditure types. Let’s say Recurrent, Public Debt and Capital.
So I need to sort this as Recurrent, Capital and Public Debt.
When I use Ascending order it return Capital, Public Debt and Recurrent.
When I use Descending order it return Recurrent, Public Debt and Capital.
So I’m not able to use Ascending or Descending order for these criteria.
So I have used variable expression for change the sort order.
Now click on ok button and then we have a sorted variable.


Then move to the jasper report query window using this icon.


In Query window there is a button called Sort options.


Click on Sort options button and then you can get Sorting window.
In here we can add sort field in to the report.
Click on Add field button the and then you can get Add/Modify parameter window.


In Add/Modify parameter window, you can select sort by variable,
According to the example it is Expenditure_order and you can define sort type also.
Then click on ok button


So now we add the sorting variable successfully.
If you need you can remove or modify the sorting variable.
Also you can add more than one variable if you required.
Click on close button to exit.


Click on button to exit from query window.


After this report content ordered according to requirement (Recurrent, Capital and Public Debt). 

Jasper Report - Return Sub Report Variable Value in to Main Report


In here I’m using

Product Version: Jaspersoft iReport Designer Professional 5.0.0
Java                    : 1.6.0_45
System                  : Windows 7

First you need to create a variable inside your sub report
In this example I have created the variable called SUB_Rec_Year_2_249 as Big decimal.
And get Sum of the Variable expression value with reset type of Report

Then In your Main report, create variable with Name and Type. In this example it is GET_SUB_Rec_Year_2_249 as Big decimal.
So this variable calculation type should be System and also reset type should be None.
So the select the sub report that imported to the main report and view the properties. In the properties , you can find Return values 
Then click on Return value icon, and then you can see the set of return values from sub report in to main report. But initially it not display anything, After you setting the return values it display the Sub report Variable (A variable from sub report) and Destination Variable(Variable name inside main report)



In this Return value window, click on Add button then it display the Sub report and Main report variable mapping window. This window contains two drop down boxes, sub report variable and local destination variable.
In this sub report dropdown list normally not display the variable names that we created. So please copy the exact variable name from sub report the paste here. According to the example this sub report variable name should be SUB_Rec_Year_2_249. Then local destination variable drop down, select the variable that we created to get return value from sub report. According to the example this local destination variable name should be GET_SUB_Rec_Year_2_249. Calculation type is Nothing and click on Ok button.

Then you can see this sub report and main report variable mapping added in to the return values mapping list. In here you can modify or delete the variable mapping if you needed.

So now you can get the sub report variable value using the main report variable.
In practical scenario, You can get this return values below the sub report inclusion

Just Started


Just Simple Step to Learn, Understand and Share Something