2015年12月30日 星期三

Netbeans IDE 的字型設定

預設字型 (Default fonts)

預設字型會用在 menus, dialogs, views 等地方。要改變字型的大小, 需設定 netbeans.conf 中的 netbeans_default_options 屬性值。在該屬性中加入"--fontsize 16" 的參數, 預設字型便會改成 16 大小。

例如以下設定:
netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true -J-Dfile.encoding=UTF-8 --fontsize 18"

netbeans.conf 檔案位於 [Netbeans_Home]/etc

預設字型大小設為 18, 結果如下:



這是 fontsize 16 的結果:





參考資料:
  1. FaqFontSize (http://wiki.netbeans.org/FaqFontSize)

2015年12月29日 星期二

Code Beautifier -- 程式碼排版

常常為程式碼排版困擾嗎? 試試不同的 On-line source code beautifier 或其它方法


在 Blogger 上用 Google Code Prettify 及 GitHub Gist 顯示程式碼 (不修改範本的懶人招數) 文章中介紹了不同鑲程式碼到 blogger 的方法, 非常值得一看.

On-Line Source Code Beautifier

Blogger 

2015年11月30日 星期一

magpi 設計線上表單, 利用行動裝置收集資料


Joel Selanikio: The surprising seeds of a big-data revolution in healthcare





Oracle Forms 的過去, 現在, 與未來


Oracle Form 產品經理 Michael Ferrante 介紹 Oracle Forms 的新功能及未來發展. 



Demo 的新功能:

  • Color Scheme
  • 在 Oracle Forms 中使用 JavaScript
  • Form 11gR2 的 guiMode 功能讓 Forms Applet 和 google map 在同個 browser 中顯示。



2015年11月21日 星期六

JSF 中的 UIInput Component 也是一種 UIOutput Component. 為什麼這樣設計呢?



UIInput 元件的被設計用來顯示資料給 User 並接受請求的參數, 所以 UIInput UIOutput 元件的子類別之一。參考 [1] 的說明就會清楚了.


那麼, UIInput 元件如果有使用 Converter 或者 Validator,是在那個階段執行 Converter 或者 Validator 呢? 預設是在 Process Validators 階段套用 Converter 進行型別轉換及使用 Validator 進行資料驗證。

驗證通過後發生什麼事? 如果驗證通過,JSF 會 queue 一個 ValueChangeEvent 事件,並 Broadcast 到註冊的 Listener 去。

Reference:

  1.  https://docs.oracle.com/javaee/6/api/javax/faces/component/UIInput.html

JSF tag 中的 binding 屬性有什麼作用呢? 何時使用?


參考 StackOverflow 中的這篇文章, 瞭解 JSF 中的 Component Binding 的功能及使用時間。

What is component binding in JSF? When it is preferred to be used?

簡單來說, 當你要在 Backing Bean 中控制 UIComponent 時, 便要使用到 Component  Binding 的功能。


延伸閱讀:

2015年11月20日 星期五

查詢常用的 regexp 表示式, 如 email 的 regexp 表示式


常常為了特定常用用途的 regexp 表示式傷腦筋嗎? 像是 email. 現在, 可以到 RegExLib.com 網站去查詢.

http://regexlib.com/Search.aspx?k=email&c=1&m=-1&ps=20

Java 語言的 Regexp:

^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$;
Ref: http://emailregex.com/#comment-1900789300




2015年11月11日 星期三

Oracle Forms Builder 11gR2 安裝手冊

Oracle Forms Builder 11gR2 安裝手冊 
2015/11/12

Oracle Form Builder 的安裝需要多個步驟及設定。本手冊提供 Oracle Form Builder 11gR2 的安裝提供完整說明及指引。安裝設定過程包括以下部份:  WebLogic Application Server ,Oracle Form Builder,JRE 8 ,及WebUtil 功能。

 全文


使用 Bootstrap 3 – A short and Quick Guide

使用 Bootstrap 3 – A short and Quick Guide


1. 使用 CDN 方式在 Web Application 中使用 Bootstrp 3 CSS framework


:  link to external style sheets.
加入 Java scripts


  
  rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">  
 
   
  rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" integrity="sha384-aUGj/X2zp5rLCbBxumKTCw2Z50WgIr1vs/PFN4praOTvYXWlVyh2UtNUU0KAUhAX" crossorigin="anonymous">  
 
  
   
 

2. Using container and container-fluid class

The Container sets the width and paddings of the contents.
You can have more than one container in the body. But, you cannot nest a container within another.
If you want your page to fill with the whole screen, you can use container-fluid class.



3. 切割版面




Bootstrap 將版面分割成 12 columns. 當螢幕大小變化時,這些 column 的位置便會調整。支援的螢幕寬度為:
  • ·        Extra Small (xs): < 768px
  • ·        Small (sm): >=768, <992 span="">
  • ·        Medium (md): >=992, <1200 span="">
  • ·        Large (lg): >= 1200

列用來做水平切割。一列中可以有多個內容區塊的, 內容區塊的長度最寬為 12 columns。以下的程式將一個列分成 2 個內容區塊,這些區塊的寬度分別為 3 9 columns




每個 div 在不同的螢幕寬度下可有不同 的寬度:
  • ·        col-xs-n: 指定在 Extra Small 寬度下區塊的寬度為 n columns
  • ·        col-sm-n: 指定在 Small 寬度下區塊的寬度為 n columns
  • ·        col-md-n: 指定在 Medium 寬度下區塊的寬度為 n columns
  • ·        col-lg-n: 指定在Large寬度下區塊的寬度為 n columns


上例中,若為Medium 寬度,則該列切中的區塊寬度分別為3 6 Columns。若為xs 寬度,則該列切中的區塊寬度分皆為12 columns,此時 div#content 會自動換到下一列。

4. Jumbotron 大型看板


直接套用 jumbtron classh1 p 的內容會被大。

5. Menu 的製作

Menu 的製作使用 ul 標籤並套用 nav, nav-pills, nav-stacked 3 個樣式來完成。


6. Button 的樣式


可用樣式:
  • ·        btn btn-defualt
  • ·        btn btn-primary
  • ·        btn btn-success
  • ·        btn btn-warning
  • ·        btn btn-danger


7. Navigation Bar 的製作



navigation 放在 container 中。
navigation bar 相關的 class:
  • ·        navbar navbar-default navbar-fixed-top: 固定在上方的 navigation bar
  • ·        navbar navbar-default navbar-bottom: 固定在下方的navigation bar


navigation bar 中的清單項目有關的 class
  • ·        navbar-header: Navigation bar 的最左邊的內容。
  • ·        nav navbar-nav: 靠右對齊的導覽元素
  • ·        nav navbar-nav navbar-right: 靠右對齊的導覽元素


8. 表單中的控制項及其說明資訊


Standard rules for all three form layouts[1]:
  • ·        Always use form role="form" (helps improve accessibility for people using screen readers)
  • ·        Wrap labels and form controls in  div class="form-group" (needed for optimum spacing) label control div.form-group 包在一起。
  • ·        Add class .form-control to all textual  input, textarea, and select elementsForm 中的控制項元素使用 form-control 類別

Example :


表單中的每個欄位可以在其前或後加入文字說明。在一個 .form-group 中使用另個 div 把欄位及其說明包起來,並套用 .input-group。說明的文字使用 包起來並套用 .input-grou-addon 類別並指定該  span  id。在要說明的欄位中加入屬性 aria-describedby 其指為 說明的文字的 span  ID 值。



9. ICON 

Bootstrap 提供多達 250 種的 icon,這些 icon 是由 Glyphicon.com 提供的。


使用時在 中先套用 glyphicon 類別後再套用 glyphicon-xxx 類別。例如:
便會煩示信封的 icon


10. 參考資料

[3] Bootstrap 3, http://getbootstrap.com/


2015年11月10日 星期二

在 JSF Page 中如何依條件顯示特定元件

在 JSF Page 中如何依條件顯示特定元件? 例如, 當 user login 後在 nav bar 上顯示 logout icon. 若尚未login 則顯示 login icon. 
請參考 Stackoverflow 中的這則討論 How to use if, else condition in jsf to display image. 可以使用的選項:
  • c:if
  • c:choose
  • render attribute for the UIComponent

2015年11月9日 星期一

Cookie Helper


對處理 Cookie 很煩嗎? 試試這個 Cookie Helper.
原作者: Vasil Lukach, 2014/01/05
Source: http://stackoverflow.com/questions/20934016/how-to-add-cookie-in-jsf

1:  public class CookieHelper {  
2:   public void setCookie(String name, String value, int expiry) {  
3:    FacesContext facesContext = FacesContext.getCurrentInstance();  
4:    HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();  
5:    Cookie cookie = null;  
6:    Cookie[] userCookies = request.getCookies();  
7:    if (userCookies != null &amp;&amp; userCookies.length &gt; 0 ) {  
8:      for (int i = 0; i &lt; userCookies.length; i++) {  
9:        if (userCookies[i].getName().equals(name)) {  
10:          cookie = userCookies[i];  
11:          break;  
12:        }  
13:      }  
14:    }  
15:    if (cookie != null) {  
16:      cookie.setValue(value);  
17:    } else {  
18:      cookie = new Cookie(name, value);  
19:      cookie.setPath(request.getContextPath());  
20:    }  
21:    cookie.setMaxAge(expiry);  
22:    HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();  
23:    response.addCookie(cookie);  
24:   }  
25:   public Cookie getCookie(String name) {  
26:    FacesContext facesContext = FacesContext.getCurrentInstance();  
27:    HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();  
28:    Cookie cookie = null;  
29:    Cookie[] userCookies = request.getCookies();  
30:    if (userCookies != null &amp;&amp; userCookies.length &gt; 0 ) {  
31:      for (int i = 0; i &lt; userCookies.length; i++) {  
32:        if (userCookies[i].getName().equals(name)) {  
33:          cookie = userCookies[i];  
34:          return cookie;  
35:        }  
36:      }  
37:    }  
38:    return null;  
39:   }  
40:  }  

2015年8月19日 星期三

JSF 選擇式元件的使用

JSF 選擇式元件的使用

2015/08/20

簡介

介紹  h:selectManyListBox,h:selectOneListBox,h:selectOneMenu,f:selectItems
等標籤的使用方式。

使用 產生不同形式的網頁中選擇式元件,如 List BoxCheck Box ListRadio ListMenu,參考下圖[1]:


body 中使用 f:selectItem 或者 f:selectItems 帶入可選擇的清單項目。

f:selectItem 的使用上,使用該標籤的 itemLabel itemValue 屬性來設定選單項目的標籤及標籤值 ,使用範例可參考[2]

相較於 f:selectItem 需手動列舉項目清單,使用 f:selectItems 可以自動地將 Collection 或者 Arrary 轉成清單項目。Collection Array 中的成員需是 SelectItem 物件或者 Java Object[3]

以下說明使用 f:selectItems 的方式,一為項目清單使用 SelectItem 物件表示,另一為使用 Java Object 表示。



回傳 SelectItem Collection 產生項目清單

Backing beans

#45-47 getOptions() 方法傳回 SelectItem List




JSF Page

#13 中的 value 屬性是對應到  cashier backing bean 中的 newsLetters property

HTML Output



Rendered Results



回傳 Java Object Collection 產生項目清單


Backing Bean

Company class 下定義的 Employee 子類別:


#41~43 定義的Company 類別的 getEmployee() 傳回 Employee List

JSF Page

使用 取得項目清單值。 中的 value 屬性指向 backing bean 中傳回 Java Object Array 的屬性; var 屬性為 Array 中的 Object; itemLabel 設為 Object 中做為標籤名稱的 propertyitemValue 設為Object 中做為標籤值的 property


HTML Output



Rendered Result




2015年8月6日 星期四

Custom Component 簡介

Custom Component 簡介

hychen39@gmail.com

Steps to create a custom component[1]:

Step 1: 建立一個javax.faces.component.UIComponent 的子類別。使用 @FacesComponent  annotation 註冊此元件。
Step 2: 若要將元件顯示的工作委由另一個 Render class 處理,則建立一個 javax.faces.render.Renderer 子類別。此為選項步驟。使用 @FacesRenderer annotation 註冊此 Renderer
Step 3: 建立一個 Tag Library Descriptor,宣告使用客製元件時所使用的custom tag。在TLD 檔中宣告客製元件的 namespace, tag name, component type,  attribute (optional)等。使用 @FacesComponent 註冊元件只能宣告元件的 namespace, tag name, component type,不能宣告元件的屬性,元件的屬性需在 TLD 檔中宣告。在 JSF2.2 以後,若使用 @FacesComponent( createTag=true) 時,若不需要標籤屬性可以不要建立 TLD 檔。TLD 檔名稱結尾需為 taglib.xml,檔案必須位置 [context_root]/WEB-INF下。此外,需在 web.xml 註冊此 TLD 檔,註冊的方式為使用 param
>,如下:
<context-param>
        <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
        <param-value>/WEB-INF/your_tag.taglib.xml</param-value>

param>

Step 4: JSF 頁面中引入客製標籤的 name space 並使用 custom tag.

建立一個javax.faces.component.UIComponent 的子類別。

custom tag 都會對應到一個 UIComponent 的子類別。實務上會建立 javax.faces.component.UIComponentBase 子類別,該子類別已實作 UIComponent class 中的抽象方法。也可以直接建立 UIOutputUIInput、或者 UICommand 子類別,視元件的用途而定。


覆寫 UIComponentBase 的方法

當建立 UIComponentBase 子類別時,還必須覆寫其 getFamily():String 方法,傳回元件所屬的元件族群(Component Family)JSF 會利元件所屬的元件族群及 Renderer type 來選擇適合元件使用的 Render[2]
若要元件本身要負責 Renderer 的工作,則必須負責decode encode 兩個階段的工作。在decode 階段需將請求中的參數取出放到元件的 submittedValue  屬性。接著再進行轉換及驗證的動作,成功後才會放到元件中的 value 屬性中(或稱 Local Value)。在 decode 階段需覆寫以下的方法:
·         decode()
encode 階段,要將元件中的 value 屬性的取出,並輸出成 HTML 元件。此時需覆寫以下三個方法:
·         encodeBegin()
·         encodeChildren()
·         encodeEnd()

委任 Renderer 工作給 javax.faces.render.Renderer class

若客製元件要將 Render 工作,則需將工作委外給 javax.faces.render.Renderer 類別。Renderer 類別的工作內容就是執行 decode encode 兩個階段的工作。

Renderer class 的建立步驟如下:
1.       建立 javax.faces.render.Renderer子類別並覆寫 decode encode 階段會被呼叫的方法,包括:
·         decode()
·         encodeBegin()
·         encodeChildren()
·         encodeEnd()
2.       JSF 中註冊 Renderer
可以使用 @FacesRender annotation 或者在 faces-config.xml [3]中進行註冊

3.       UIComponent 子類別中:
·         覆寫 getFamily():String 方法,傳回的字串需和註冊時使用的 標籤內容一致。
·         設定其 rendererType 屬性,其值需和 Step 2 所註冊的 Readerer Renderer Type 一致。使用 UIComponent setRenderType() 設定 renderType 屬性。或者直接覆寫元件的 getRenderType():String 使其傳回註冊的 Render Type
完成上述設定後,JSF 會自動由 Render Kit 中找到指定的 Family 下的 render type 類別並自動建立物件實體讓我們使用。



Annotation 和其在 faces-config.xml 中的對應的 XML



Tag Library Descriptor


Decoding 階段會做的事及使用到的類別及方法

取得請求的 client id

facesContext.getExternalContext.getRequestParameterMap() 方法取得存放請求參數的Requests Map
取得 Request Map 中的參數requestMap.get(Object Key) 或者 requestMap.containsKey(Object Key):boolean

UIComponent  相關的操作

取得 client id

uIComponent.getClientID(FacesContext) 取得 UIComponent client id (Return a client-side identifier for this component)
例如,下圖中的 UIComponent Client id monthSpinner


取得UIComponent 中的屬性

取得 UIComponent 中的屬性 uIComponent.getAttributes().get(Object Key)
uIComponent.getAttributes() 會傳回存放 attributes map 物件。

設定 UIComponent submittedValue特性及 local value

request 的值存到 UIInput 元件的 submittedValue property,以準備進行 Validation,使用 uIInput.setSubmittedValue() 執行上述的動作[6]。這個動作是發生在 Apply Request Phase。在 Process Validators Phase,若 UIInput 中的 submittedValue 轉換並驗證通過,使用 uIInput.setValue() 將轉換後的值設定到 UIInput 元件的 Local Value 中。

觀察Request Map 中的值如何產生

以下例子說明 Request Map 中的值的產生
當按下 month spinner > 按鈕時,會 submit formForm id spinnerForm。在spinnerForm 中有2 input field,其 id 分別為 spinnerForm:monthSpinner spinnerForm:yearSpinner

參考下圖,當 submit form 時,以下的參數會被提出
1.       #6 spinnerForm = “SpinnerForm
2.       #14 spinnerForm:monthSpinner = “1”
3.       #14 spinnerForm:monthSpinner.more = “>”
4.       #21 spinner:yearSpinner = “2010”

以下是在 Netbeans 中觀察到的 Request Map 中的值。



Encoding 階段會做的事及使用到的類別及方法

取得 Response Writer

需取得 Response Writer 將回應寫到輸出串流傳給 browser。使用 facesContext.getResponseWriter():ResponseWriter 取得 Writer

取得 UIComponent 中的: client ID,  local values attributes


要取得 UIComponent Client ID,使用 uIComponent.getClientID(facesContext):String
取得 UIComponent 中的 Local value,使用 uIComponent.getValue():Object
取得 UIComponent 中的 attribute,使用 uIComponent.getAttributes.get(Object Key):Object

Render a HTML element

要開使輸出 HTML element,使用 responseWriter.startElement(String name, UIComponent Component):void,其中:
·         Name: HTML Tag 的元素
·         Component 是對應到此元素 UIComponent,該元件中的 pass-through attributes 會被直接寫出到 HTML 元素成為該元素的屬性。
當執行 responseWriter.startElement() 後,便可使用 responseWriter. writeAttribute(String name, Object value, String property) 輸出該元素的屬性,其中:
·         name: HTML 元素中的屬性名稱
·         value: HTML 元素中的屬性值
·         property: UIComponent 中對應到此元素的 property 或者 attribute。若沒有則給 null[7]。在 JSF 2.1 版中此參數好像尚未被使用[8]
結束輸出使用 responseWriter.endElement(String name)




[3] 使用faces-config.xml 註冊component Renderer 的方式在 JSF 2.2 版本中好像行不通。
[4] E. Burns & C. Schalk, JavaServer Faces: The Complete References, McGraw Hill, 2010, p309
[5] E. Burns & C. Schalk, JavaServer Faces: The Complete References, McGraw Hill, 2010, p319
[6] https://docs.oracle.com/javaee/6/api/javax/faces/component/UIInput.html