2011年8月28日 星期日

Java 序列化(Serialization)

序列化的意思就是把物件儲存後(file or database),在從中取出還會是原物件狀況,包含屬性等。

首先必須實作 Serializable interface,這個介面沒有任何method。

該物件的屬性如果是 primitive type會自動被序列化。

如果非primitive type沒有實作Serializable就會丟出 Runtime Exception

或者我們不想讓這個非primitive type不被序列化,就在這屬性加上transient

如果兩個物件共同指向相同非privitive type的A物件,且儲存時使用相同ObjectOutputStream,此時只會存一份A物件。如果儲存時分別使用不同ObjectOutputStream,當然就會有各自一份不同的A物件。

細節說明和範例可參考

2011年8月12日 星期五

Got an UiBinder useSafeHtmlTemplates warning on GWT compiling

When I was running a sample MVP application of GWT , show an error

[WARN] [helloMVP] Configuration property UiBinder.useSafeHtmlTemplates is false! UiBinder SafeHtml integration is off,
leaving your users more vulnerable to cross-site scripting attacks. This property will default to true in future releases of GWT



Solution is add one line in Contacts.gwt.xml


  







2011年8月10日 星期三

To decorate java code in google blogger with SyntaxHighlighter

  • Go to SyntaxHighlighter and download ( I used 3.0.83 release )
  • Unzip the file you download and  upload 
               the files(shCore.js、shBrushJava.js) in syntaxhighlighter_3.0.83\scripts               and (shCore.css、shCoreEclipse.css、shThemeEclipse.css) in syntaxhighlighter_3.0.83\styles
              to your web space ( On-line ) or https://sites.google.com/site/yours/

                                             I upload these files to my google site

 




                                              change the template in your blogger




add some html code as below

 
save the setting!

So , now you can decorate your code in blogger !
In editor of blogger , as following
<pre class="brush:java" name="code" >
      java code
</pre >

It is easy to use for html and javaScript and so on as above . See the configuration of SyntaxHighlighter for more advanced feature.









2011年8月8日 星期一

GWT Note 2

Event and Event handler

有四種方式來實作UI介面與事件觸發處理的關係
1.handler獨立成一個class,這樣會多很多class file不好review code和維護。
public class GwtEvents implements EntryPoint {
   ...
   public void onModuleLoad() {
     textfield = new TextBox();
     textfield.addKeyUpHandler(new MyHandler(this));
     ...
   }//end onModuleLoad
}//end class

public class MyHandler implements KeyUpHandler {
   ...
   public void onKeyUp(KeyUpEvent event) {
   ...
   }
}//end class

2.直接實作handler
public class GwtEvents implements EntryPoint, KeyUpHandler {
   ...
   public void onModuleLoad() {
     textfield = new TextBox();
     textfield.addKeyUpHandler(this);
     ...
    }

   public void onKeyUp(KeyUpEvent event) {
   ...
   }

}//end class


3. (Named)Inner class
public class GwtEvents implements EntryPoint { 
   public void onModuleLoad() { 
      textfield = new TextBox(); 
      textfield.addKeyUpHandler(new MyHandler()); 

   private class MyHandler implements KeyUpHandler { 
     public void onKeyUp(KeyUpEvent event) { 
     ... 
    } 

   }//end onModuleLoad 
}//end class 
4.Anonymous inner classes
public class GwtEvents implements EntryPoint { 
   ... 
   public void onModuleLoad() { 
     textfield = new TextBox(); 
     textfield.addKeyUpHandler(new KeyUpHandler() { 
     @Override 
     public void onKeyUp(KeyUpEvent event) { 
      ... 
     } 
    }); 
   }//end onModuleLoad 
}//end class 
請依情況選擇2、3的作法,避免用方法4。

GWT Note 1

今天遇到一個很怪的情況,怎麼加xxx.gwt.xml在已含有*.gwt.xml的project內就是會跑不起來,訊息如下:
[ERROR] [gwtevents1] - Unable to find 'gwtevents1.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
...
[ERROR] [gwtevents4] - Unable to find 'gwtevents4.gwt.xml' on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?

這四個新加入的都出現一樣的錯誤,後來才找到問題:就是不要跑原先存留在eclipse內的執行設定,也就是刪除舊的執行設定 Run => Run Configurations => delete old configuration 或對project按右鍵=>Run As => Web Application

這種問題的解決挺難找的= = ,如果習慣用ant或maven來build,不要仰賴eclipse就不會遇到這種鳥事。

2011年8月5日 星期五

GWT Note

最近開始進入GWT的開發模式,所以一定會有不熟悉的地方,也就容易產生錯誤。
這邊就來把遇到的問題記起來吧!

在eclipse建立一個練習的GWT專案後,想要在這個專案跑一個以上的entry http://www.blogger.com/img/blank.gifpoint,http://www.blogger.com/img/blank.gif所以就會有一個以上的xxx.gwt.xml,那不想讓這兩個module(GWT是定義一個module一個entry point,討論12)包到彼此的client code,很簡單的方式就是切不同的path(或說package)

for example :
gwtapp1.gwt.xml
...
<module rename-to='gwtapp1'>
<source path='client/app1'/>
</module>

gwtapp2.gwt.xml
...
<module rename-to='gwtapp2'>
<source path='client/app2'/>
</module>

就是path不同,這樣就不會把gwtapp1的clinet code也被compile成gwtapp2的code了!

注意rename-to的值就是war內的一個目錄專放java to javaScipt的地方,還有就是path是用 / 斜線(slash or forward slash。 \ 反斜線是叫 backslash),我一開始是用"點" 所以會被google plugin的compiler說 "GWT compilation failed" 。= =;;;

COVID-19 確診經歷紀實

原本以為真的是天選之人,就算先前家裡兩個小孩都確診都逃過了(可能有中獎但無症狀吧),不過就在2023年六月18日破解自認為天選之人的"心態",為什麼可以確認就是這天中獎的呢?因為在前都是居家上班,到人多的室內場所都會戴口罩,就剛好這天傍晚原本只想說要去附近的國...