[蟲?] JSF commandButton不斷觸發PostConstruct

作者: gmoz ( This can't do that. )   2014-05-28 16:33:30
問號應該要拿掉,的確是蟲 XD
剛剛遇到,弄了好一陣子也解決掉了
主要是在你的bean生命週期為ViewScoped時,
你想要在你的頁面上有顆commandButton,按下去可以call你bean裡面的method
這當然沒問題,放顆按鈕按呀按的就好
但其實這時候你的PostConstruct也會跟著不斷的被觸發,
如果你的PostConstruct是從GET裡面拿參數,這時就會Null Exception了
@PostConstruct
public void init(){
System.out.println("fired 打我呀笨蛋");
}
這也證實是JSF的bug了,請將Mojarra 升級為2.1.8之後的版本
將你平台moudules的 javax.faces.jar 置換掉即可
作者: luoqr (.....)   2014-05-28 23:25:00
什麼情境會用到viewscoped+postconstruct? :P
作者: gmoz ( This can't do that. )   2014-05-29 11:09:00
這裡是一般網頁用URL帶參數連來我的JSF網頁@@ 求更好做法
作者: luoqr (.....)   2014-05-29 12:40:00
FacesContext.getExternalContext.getRequestParameterMap?
作者: gmoz ( This can't do that. )   2014-05-29 13:51:00
因為我把這個放在PostConstruct裡面 按鈕觸發就NULL EXCEPTION了 QAQ...

Links booklink

Contact Us: admin [ a t ] ucptt.com