2012-05-08 23 views
0

這裏我再次遇到了一個JSF問題,這次它更多地是關於richfaces(4.2.1 final,JSF 2)。我有一個有眼的DataTable並想添加新的項目。對象的列表是Journey,每個屬性都有getter和setter。表格創建得很好(列表中已經有一些項目)。現在我點擊「添加新條目」按鈕:使用彈出面板創建新數據對象失敗

<a4j:commandButton ajax="true" value="Neue Fahrt hinzufügen" 
    actionListener="'{editorBean.prepareCreateJourney}" render="createJourneyPopupForm" 
    oncomplete="#{rich:component('createJourneyPopup')}.show()" /> 

的editorBean是SessionScoped,該方法被稱爲properply創造的Journey一個新的對象調用currentJourney。一個彈出來了,應該讓我插入一些輸入:

<rich:popupPanel id="createJourneyPopup" modal="true"> 
    <h:panelGrid id="createJourneyPopupForm" columns="3"> 
     <h:outputLabel for="currentId" value="ID" /> 
     <h:inputText id="currentId" 
      value="#{editorBean.currentJourney.journeyNumber}" /> 
     <rich:message for="currentId" /> 
     [...and more...] 
    </h:panelGrid> 

    <a4j:commandButton value="Save" 
     execute="currentId currentTrainType operator"> 
     <f:ajax event="click" listener="#{editorBean.doCreateJourney}" 
      render=":vmsEditorForm:resultTable" /> 
     <rich:componentControl target="createJourneyPopup" operation="hide" /> 
    </a4j:commandButton> 
    <a4j:commandButton value="Abbrechen" 
     onclick="#{rich:component('createJourneyPopup')}.hide();" /> 
</rich:popupPanel> 

當我點擊該按鈕,方法doCreateJourney被調用,但currentJourney是空的。在創建它之後,它是默認的Journey對象。沒有調用者被調用,在輸入字段上做暗示。

我檢查了兩次名字,還有getters和setters for alle需要的對象。我試圖改變範圍,但沒有效果。對象是相同的,在我創建Journey(id=151)的準備方法中,在保存方法中它仍然是Journey(id=151)

這是怎麼回事?我不能很難做出一些對話來創建和編輯數據對象。感謝您的聆聽和您的幫助!

回答

1

爲了正確提交數據,您需要將輸入和commandButtons包裝在一個表單中。

<rich:popupPanel id="createJourneyPopup" modal="true"> 
    <h:form> 
     ... the content of your popupPanel 
    </h:form> 
</rich:popupPanel> 

問候,

+0

好了,我看了看這裏的類似的編輯對話框:http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=dataTable&sample=dataTableEdit 而popupPanel與相同。但是你是對的,創建兩種形式並在第一個之外包含對話框是正確的。這是工作!謝謝! – Felix