2011-04-05 45 views
4

我從RichFaces 3.3.3遷移到4.0,遇到了一個無法解決問題的問題。到目前爲止,我已經使用RichFaces的@ KeepAlive註釋來實現View的作用域,但是新版本4到目前爲止並沒有這樣的功能(據我所知)。所以我認爲@ViewScoped註釋將是自然的(快速的)替換,但它不起作用。 這是相關的代碼給我帶來麻煩。它呈現一張包含客戶名稱作爲鏈接的表格,所以當單擊名稱時,會彈出一個彈出窗口來編輯數據。它在v3.3.3中使用@KeepAlive工作,但不在v4中使用@ViewScoped(彈出窗口不會被調用)。RichFaces 4和@ViewScoped

頁:

<h:form prependId="false"> 
<rich:dataTable id="table" value="#{myBean.customers}" var="customer"> 
    <!--...headers...--> 
    <h:column> 
     <a4j:commandLink action="#{myBean.selectCustomer}" 
      oncomplete="#{rich:component('popup_customer_editor')}.show();" render="form_customer_editor"> 
      ${customer.name} 
      <f:setPropertyActionListener value="#{customer}" target="#{myBean.selectedCustomer}"/> 
     </a4j:commandLink> 
    </h:column> 
    <h:column>${customer.address}</h:column> 
</rich:dataTable> 
</h:form> 

<rich:popupPanel id="popup_customer_editor> 
    <h:form id="form_customer_editor"> 
    <!--...form fields...--> 
    </h:form> 
</rich:popupPanel> 

豆子:

@ManagedBean 
@ViewScoped //It was @KeepAlive before 
public class MyBean implements Serializable 
{ 
    private String name; 
    private String address; 
    private Customer selectedCustomer; //POJO class 
    //getters and setters 
    ... 
    public String selectCustomer() 
    { 
     name = selectedCustomer.getName(); 
     address = selectedCustomer.getAddress(); 

     return null; 
    } 
} 

任何幫助,將不勝感激

回答

3

有兩個原因,爲什麼你的行爲可能不被叫做:

  1. 你有af如果提交併且驗證/轉換失敗。如果您有驗證或轉換錯誤,則不會調用您的操作。您應該有一個<h:messages>以確保您能夠看到它,並且因爲它是a4j:clickLink將它放入如下所示的a4j:outputPanel<a4j:outputPanel ajaxRendered="true"><h:messages/></a4j:outputPanel>

  2. 你有<h:form>內的另一個<h:form>,和你想提交內部之一。你可以用螢火蟲追蹤這真的很容易。由於某種原因,JSF決定不做任何事情。

它看起來就像你在這裏做一些時髦的業務:

  1. 重新渲染形式。我在JSF2中重新渲染<h:form>(即他們停止工作)時遇到了嚴重的問題,使用richfaces模式面板,通過實現實際面板的方式變得可行,從而將元素從<body>元素的DOM中的任何位置移動到該面板。因此,我建議在表單中創建一個<h:panelGrid>,然後重新渲染那個表單。
  2. <f:setPropertyActionListener>。真?你應該有EL2一樣,所以你可以改變這一點:

    <a4j:commandLink action="#{myBean.selectCustomer}" 
        oncomplete="#{rich:component('popup_customer_editor')}.show();" 
        render="form_customer_editor"> 
         ${customer.name} 
        <f:setPropertyActionListener value="#{customer}" 
         target="#{myBean.selectedCustomer}"/> 
    </a4j:commandLink> 
    

<a4j:commandLink action="#{myBean.selectCustomer(customer)}" 
    oncomplete="#{rich:component('popup_customer_editor')}.show();" render="form_customer_editor" value=#{customer.name}"/> 

+0

感謝您的建議,但方法爲myBean。 selectCustomer(customer)沒有被調用。 – etercap 2011-04-05 16:16:00

+0

只是關於作用域的評論,RichFaces 4將不具有視圖範圍(a4j:keepAlive),因爲它現在可以從JSF 2獲得。 – 2011-04-05 16:25:01

+0

有兩個原因可能導致您的操作不能被調用: 1。您有一個提交的字段,驗證/轉換失敗。如果您有驗證或轉換器錯誤,則不會調用您的操作。你應該有一個''以確保你看到它,或者將開發階段設置爲web.xml中的開發(當我到達辦公室時,我會給你實際的片段)。 2.您在另一個「」內有一個'',並且您正在嘗試提交內部的一個。你可以用螢火蟲追蹤這真的很容易。 PS:我討厭stackoverflow格式。 – 2011-04-06 04:26:53