Total Pageviews

2011/10/24

Grouping Data in Reports

Report groups are a flexible way to show grouped data based on one or more certain fields, or even on generic expression, that is, a group can be defined based on the specific column.

Here we will build a report to show the list of 違章案件派查明細表, 審理人員 will be grouped together, that is, the manger (suppose the report is for a manager) will know which violation case is reponsible by which 審理人員.

Follow the listed steps:
1. Go to File | New… | Report, select Simple Blue, and press Launch Report Wizard.
2. Set JavaBean as report's datasource: http://albert-myptc.blogspot.com/2011/06/how-toi-make-java-bean-datasource.html
3. Click Report Name | Right Click | Add Report Group, and New Group Wizard. Fill in Group Name | Choose field name | click Next, and Click Finish


4. You can see group header and group footer in your Report Inspector
5. Click group header | check "Start on a new page" and "Reset page number"

6. Report header and column header should all put into group header
7. JavaBean attriubtes will be dragged and dropped into detail band

8. Drag and drop group count variable to summary field

 9. Done.

How to start group data on a new page

Problem
I had some problems as I built a group by report
1. Each group data should start on a new page.
2. page number should be reset



Solution
1. Move report header from title band to group header band

2. Click group header


3. Check two checkboxs, including "Start on a new page" and "Reset page number"


Here has some group options:
Option Description
Name This is the name of the group. You can modify the name by just clicking on the button next to the name.
Start on a new page If this checkbox is checked, then the group starts on a new page.
Start on a new column If this checkbox is checked, then the group starts on a new column.
Reset page number When the group changes, the page number is reset if this option is checked.
Reprint header If you want to reprint the group header on each page, check this option.
Min Height to Start New Page If the value is greater than 0 (zero), it is considered as the minimum height required to keep the group on the current page.
Footer Position This option allows us to specify where to place the group footer. The available place options are Normal, Stack at bottom, Force at bottom, and Collate at bottom.
Keep Together This is a flag that prevents the group from splitting on two separate pages/columns.

Demo
It split to two pages as bellowing:


2011/10/13

How to Prevent a SQL Injection Attack

Reference: http://www.dzone.com/links/r/how_to_prevent_a_sql_injection_attack.html




1. Patch your SQL server regularly
2. Limit the use of dynamic queries
3. Escape user input
4. Store database credentials in a separate file
5. Use the principle of least privilege
6. Turn magic quotes off
7. Disable shells
8. Disable any other DB functionality you don’t need
9. Test your code

2011/10/11

How to add record sequence number in JasperReports

Requirement
I would like to add record sequence number in the first column.


How to do it?
1. Open iReport
2. Utilize the build-in variable, COLUMN_COUNT, drag and drop to specific location.




2011/10/07

如何在iReport中設定欄位高度依據其內容而延展

Problem
當textfield中,資料長度過長時,過長的部份會被截掉,希望若遇到過長的部份能夠折行處理。



Solution
利用iReport打開jrxml file,點選特定的textfield

將Stretch With Overflow此選項打勾即可。
 

Result



2011/10/05

How to count the total number of records in JasperReports

Objective
We would like to show the total number of records at the end of report: 

How to do it
It's very easy and straightforward, just utilize the build-in variable (REPORT_COUNT), drag and drop the build-in variable into report. That's all.




2011/09/23

There are no resources that can be added or removed from the server


Today I simply would like to deploy my ear file to WAS (Web Application Server) as usual. 


But it fail to find my EAR file:
 

I spent more than two hours to find its root cause and solution. But it's still in vain.
Finally, I decide to give up. I just switch to another workspace and check out source code from SubVersion, then it's going to normal. I don't know why!
 

2011/09/22

2011/09/21

2011/09/17

net.sf.json.JSONException: org.apache.openjpa.lib.util.ParseException

Scenario
當使用者輸入異常代號,系統要自動帶出違章編號徵銷管理代號應納金額已納金額等欄位。

 


Problem
在Controller,我們會去呼叫後端service class,根據使用者所輸入的異常代號進行搜尋,帶回符合條件的entity(i.e. NIGT900),但是在轉成JSONObject的時候,出現下列錯誤訊息:
net.sf.json.JSONException: org.apache.openjpa.lib.util.ParseException: Errors occurred while creating property descriptors for the following properties: [RefreshFromDataCache, CacheMarshallers, jdbc.QuerySQLCache, jdbc.CollectionId, AccessIntent].
at net.sf.json.JSONObject._fromBean(JSONObject.java:987) ~[json-lib-2.3-jdk15.jar:na]


Root Cause
由於回傳的entity(i.e. NIGT900)有一個資料型態為Timestamp的欄位,導致會出現此錯誤



Solution
利用JsonConfig將timeStamp欄位exclude掉

Result



2011/09/15

How to Organize Imports Automatically in Eclipse

Problem
When using Eclipse, I find myself typing Ctrl+Shift+O several times, to organize imports (usually imports which are no longer required, generating warnings).



Solution
Preferences->Java->Editor->Save Actions->Check "Perform the selected actions on save" --> Check "Organize Imports"



See....after save action had been trigger, it will organize imports automatically
 

2011/09/10

tutorials point

一個還不錯的技術學習網站: http://www.tutorialspoint.com/index.htm


2011/09/09

JPA Annotation @JoinColumn / @JoinColumns 應用

Scenario
我們在利用JPA(Java Persistence API)的時候,code generator會自動幫table之間有關連的部份產生出來,但是在實際應用上,有可能table之間沒有關連性,但是卻需要來做join抓取資料的需求。


此時就要自行在該entity上宣告變數與join的欄位。若是single column的狀況下,可以採用@JoinColumn,若是composite column的話,可以採用@JoinColumns


Demo
NIGT001與NIGT007雖然沒有relationship,但是在實際應用上,常會做JOIN,彼此透過single column來做Join





在原本的NIGT001增加nigt007此attribute,並產生setter/getter methods,註明兩張table之間的relationship,name的部份是NIGT001的欄位,referencedColumnName的部份是NIGT007的欄位名稱,此二table彼此是透過上述欄位來進行join
 




NIGT001與NIGT022雖然沒有relationship,但是在實際應用上,常會做JOIN,彼此透過composite column來做Join





在原本的NIGT001增加nigt022此attribute,並產生setter/getter methods,註明兩張table之間的relationship,name的部份是NIGT001的欄位,referencedColumnName的部份是NIGT022的欄位名稱,此二table彼此是透過上述欄位來進行join




Checkbox/Radio Button filters with jQuery

Scenario
當使用者輸入查詢條件,並按下查詢按鈕,系統會自動將符合條件的資料呈現於data grid中,使用者選擇某筆資料,點選查詢

當使用者點選查詢後,系統會將資料庫的資料帶入dialog中:
 
系統會根據欄位值來決定radio button要預設選擇哪一個,以及決定checkbox是否要打勾


 Radio button



原本的寫法:


採用filter的寫法:


Checkbox

 原本的寫法:

 採用filter的寫法:


有關filter的文件,請參考:http://api.jquery.com/filter/