Total Pageviews

2011/06/04

how to Set JavaBean DataSource in iReport

Setup Classpath

1. iReport --> Preferences

2. Click Classpath tab --> Click "Add Folder"

3. Choose class folder --> Click "Choose"

4. Check "Reloadable" checkbox --> Click OK

Create a new report template
1. File --> New


2. Choose "Blank A4" --> Click "Open This Template"

3. Assign report name and location, Click "Next"


4. Click Finish

5. Right Click -->Edit Query

6. Choose "JavaBean DataSource"-->Assign "class name"-->Click Read Attriutes

7. Choose "selected attributes" --> Click "add selected attributes"

8. Click OK

9. Unfold "Fields", then you can see the attributes we added before will show under Fields

10. Drag "Department" field into template. Then DONE.


2011/06/02

利用enumeration type來做下拉選單

我們在開發的時候,會遇到某些下拉選單不是從資料庫抓出來的,寫死在jsp好像不太恰當,寫在property file再抓出來又有點麻煩,如下圖所示,輸出格式、法務科別、下授類別等,下拉單內容很固定、又不需要放在資料庫:


這邊我建議用Java的enumeration type來建立下拉選單。步驟如下(以法務科別為例):

1. 建立enumeration class (若下選選單有增減,只要修改enumeration即可)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
   package gov.fdc.nig.enumeration;
   
   /**
    * 法務科別 enumeration
    *
    * @author albert
    *
    */
   public enum LegalSectionEnum {
   
       SECTION1("1.法務一科", "1"), SECTION2("2.法務二科", "2"), ALL("3.全部", "3");
   
       private final String label;
       private final String value;
   
       public String getLabel() {
           return label;
       }
   
       public String getValue() {
           return value;
       }
   
       private LegalSectionEnum(String label, String value) {
           this.label = label;
           this.value = value;
       }
   
       public static void main(String args[]) {
           LegalSectionEnum[] enumArr = LegalSectionEnum.values();
           for (LegalSectionEnum enumeration: enumArr) {
               System.out.println("label=" + enumeration.getLabel() + ", value=" +
                   enumeration.getValue());
           }
       }
   }

2. 在NIGUtilsConroller增加一個method來抓取enumeration中所定義的values
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
   /**
    * 取得法務科別下拉單
    * 
    * @param res loadDelegationUnitList
    * @param session HttpSession
    * @throws IOException if exception happens
    */
   @RequestMapping(value = "/loadLegalSectionList", method = RequestMethod.POST)
   public @ResponseBody
   void loadLegalSectionList(final HttpServletResponse res, final HttpSession session)
   throws IOException {
       final JSONArray jsonArray = new JSONArray();
   
       try {
           final LegalSectionEnum[] enumArr = LegalSectionEnum.values();
   
           for (LegalSectionEnum enumeration: enumArr) {
               Map map = new HashMap();
               map.put("value", enumeration.getValue());
               map.put("name", enumeration.getLabel());
   
               jsonArray.add(map);
           }
       } catch (FDCDataAccessException e) {
           LoggerFactory.getLogger(this.getClass()).debug(
               "loadExportFormatList exception: " + e.getMessage());
       }
   
       res.setContentType(NigAccessKey.JKEY_CONTENT_TYPE);
       res.getWriter().write(jsonArray.toString());
   }


3. 在nig.utils.js增加一個function來取得法務科別下拉單


4. 在功能相對應的js,呼叫nig.utils.js所定義的JavaScript function


JavaScript function所定義的id,與下拉選單的id需要對應

2011/05/31

eclipse-fonts

Easily control Eclipse fonts size. Update site: http://eclipse-fonts.googlecode.com/svn/trunk/FontsUpdate/

Shortcuts -

CTRL+= : Increase fonts

CTRL+- : Decrease fonts

2011/05/28

My Travel Brain

Travel Map
I've been to 38 cities in 11 countries
Asia
China: Shenzhen
Hong Kong (SAR): Hong Kong Island
Japan: Asahikawa
Japan: Fukuoka
Japan: Hakodate
Japan: Hokkaido
Japan: Kyoto
Japan: Nagano
Japan: Nagoya
Japan: Onuma
Japan: Sapporo
Japan: Sendai
Japan: Tokyo
Malaysia: Kuala Lumpur
Singapore: Singapore
South Korea: Seoul
Taiwan: T'ai-nan
Taiwan: T'ai-pei
Taiwan: T'ao-yuan
Taiwan: Yilan City
Europe
France: Arles
France: Avignon
France: Carcassonne
France: Entrevaux
France: Gordes
France: Le Fugeret
France: Nice
France: Nimes
France: Paris
France: Roussillon
France: Saint-Paul
France: Sorgues
Italy: Milano
Monaco: Monte-Carlo
North America
Canada: Toronto

Utilize Commons BeansUtils to do copy object


2011/05/27

2011/5 France

摩納哥

尼斯

蔚藍海岸

St. Paul

Aix(Aix-en-Provence的首都)

Roussillon一隅

Gordes

Fontaine-de--Vaucluse(沃克呂姿碧泉村)

Pont St. Benezet(亞維農斷橋)

嘉德水道橋(Pont du Gard)

凱旋門

Carcasonne

Eiffel Tower

羅浮宮

聖母院

Eiffel Tower夜景


2011/04/07

Utilize Recursive Java Decompiler to Decompile Jar File



2. Unzip jd-gui-0.3.3.windows.zip and execute jd-gui.exe

3. assign jar file which you want to do decompile



4. File --> Save All Sources




6. Install Doxygen

7. Assign project name, source code directory, destination directory. And check "Scan
recursively"


8. Change to "Mode", and do some configuration

9. Change to "Output", and do some configuration

10. Change to "Diagram", and do some configuration

11. Click "Run" tab, and click "Run doxygen"

12. Check result

2011/04/01

Extract Method Refactoring Example

Extract Method is a refactoring operation that provides an easy way to create a new method from a code fragment in an existing member.

Using Extract Method, you can create a new method by extracting a selection of code from inside the code block of an existing member. The new, extracted method contains the selected code, and the selected code in the existing member is replaced with a call to the new method. Turning a fragment of code into its own method lets you quickly and accurately reorganize code for better reuse and readability.

Extract Method has the following benefits:
1. Encourages best coding practices by emphasizing discrete, reusable methods.
2. Encourages self-documenting code through good organization.
3. When descriptive names are used, high-level methods can read more like a series of comments.
4. Encourages the creation of finer-grained methods to simplify overriding.
5. Reduces code duplication.

實例說明
我們在Controller中,會撰寫新增、修改、刪除等method,其中在新增與修改的部份,會將前端form bean的value轉成entity class,然後再呼叫insert or update method,其code snippets如下:

Extract Method Refactoring三部曲
1. 選取要進行refactor的部分

2. 按右鍵-->Refactor-->Extract Method

3. 給予新的method name --> OK


檢查Refactor後的結果

Eclipse將原本set的動作抽離成一個獨立的method


insert與update的method中,原本重複的動作只要用covertBeanToEntity此method取代即可,避免code duplication