<f:subview> 中 <h:commandLink> 的 action 不執行現象:包含頁面 (如導航欄) 使用 <f:subview>,被包含頁面含非 JSF 標籤 (如 <a>) 時需用 <f:verbatim> 包裹,但 <f:verbatim> 內容不在組件樹中,導致內部 <h:commandLink> action 失效。
解決:避免在 <f:verbatim> 中使用 JSF 組件,盡量全用 JSF 標籤。
<f:subview> 中 action 執行但無法導航至 faces-config.xml 定義頁面現象:action 方法執行了,但頁面不跳轉。
解決:檢查 faces-config.xml 中 <from-view-id>,若頁面被包含,應設為 "/*" 而非具體路徑 (如 "/navigatorbar.jspx")。
現象:Error getting property 'xxx' from bean of type XXXX。
原因 1:EMF 生成的 XXXImpl 建構子為 protected,改為 public (注意保留 @generated 標記防重新生成覆蓋)。
原因 2:Bean 中存在同名不同參數方法 (如 getRecords() 和 getRecords(int year)),EL 解析衝突。
解決:重命名帶參數方法。
堆疊追蹤片段:
javax.faces.el.PropertyNotFoundException → PropertyResolverImpl → ArraySuffix → ComplexValue → ExpressionEvaluatorImpl → ValueBindingImpl → FacesBeanImpl → UIXComponentBase → UIXIterator → UIXCollection
代碼方案:
ValueBinding binding = FacesContext.getCurrentInstance()
.getApplication().createValueBinding("#{MyBean}");
binding.setValue(context, null);
將 Bean 綁定值設為 null 即可從作用域移除。
<f:verbatim> 用法。from-view-id 慎用通配符。public,避免重載屬性讀取器。ValueBinding API 而非直接操作 Map。