JSF開發問題和解決

來源:互聯網
上載者:User

1、在<f:subview>裡的<h:commandLink>的action不執行

很多時候<f:subview>是在包含頁面的情況下被用到(例如包含一個導航頁面),而被包含的頁面裡如果有非JSF標籤(如<a>)的時候,必須額外使用<f:verbatim>包含它才不會報錯。問題是<f:verbatim>包含的內容是不算在JSF的Component Tree裡的,因此這裡的<h:commandLink>的action就不會被執行了。解決的辦法是不要在<f:verbatim>裡用<h:commandLink>,即盡量全部使用JSF的標籤比較不容易出問題。參考連結

2、還是在<f:subview>裡,action屬性的方法雖然執行了,但不能轉到faces-config裡定義的目標頁面

檢查faces-config.xml裡<from-view-id>,如果頁面被包含的話,則<from-view-id>可能應為"/*",而不是如"/navigatorbar.jspx"這樣。

3、結合EMF使用時,頁面拋出找不到屬性異常“Error getting property 'xxx' from bean of type XXXX”

EMF產生的XXXImpl裡的構造方法是protected修飾的,改為public即可。(注意修改@generated修飾,否則下次重建時會被覆蓋回來)

另(不僅限於EMF的情況):如果一個Bean裡有兩個同名但參數不同的方法,例如Customer有getRecords()和getRecords(int year)這兩個方法,則在JSF頁面裡用#{customer.value}會拋出同樣的異常,我暫時還不確定是EL的問題還是JSF實現(我用的trinidad)的問題,部分異常stack如下所示:

嚴重: Servlet.service() for servlet faces threw exceptionjavax.faces.el.PropertyNotFoundException: Error getting property 'xxx' from bean of type XXXX    at com.sun.faces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:107)    at com.sun.faces.el.impl.ArraySuffix.evaluate(ArraySuffix.java:167)    at com.sun.faces.el.impl.ComplexValue.evaluate(ComplexValue.java:151)    at com.sun.faces.el.impl.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:243)    at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:173)    at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:154)    at org.apache.myfaces.trinidad.bean.FacesBeanImpl.getProperty(FacesBeanImpl.java:66)    at org.apache.myfaces.trinidad.component.UIXComponentBase.getProperty(UIXComponentBase.java:1100)    at org.apache.myfaces.trinidad.component.UIXIterator.getValue(UIXIterator.java:415)    at org.apache.myfaces.trinidad.component.UIXCollection._flushCachedModel(UIXCollection.java:1127)    at org.apache.myfaces.trinidad.component.UIXCollection.encodeBegin(UIXCollection.java:511)    at org.apache.myfaces.trinidadinternal.uinode.UIComponentUINode._renderComponent(UIComponentUINode.java:317)    at org.apache.myfaces.trinidadinternal.uinode.UIComponentUINode.render(UIComponentUINode.java:279)

解決的辦法是把帶參數的那個方法改名。 

4、從session裡刪除一個bean

ValueBinding binding =FacesContext.getCurrentInstance().getApplication().createValueBinding("#{MyBean}");binding.setValue(context, null);

參考連結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.