2012-04-27 35 views
1

我想在LazyLoading Datatable中設置類似這樣的內容,我無法使用下面的代碼。如何使用Datatable設置目標元素的值LazyLoading

<p:dataTable var="studyPlanList" value="#{editBean.lazyModel}" 
       paginator="true" rows="10" 
       paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" 
       rowsPerPageTemplate="5,10,15" selectionMode="single" 
       selection="#{editBean.selectedStudyPlan}" 
       id="studyPlanTable"> 
      <p:ajax event="rowSelect" listener="#{editBean.onRowSelect}" update=":studyPlanEditForm:display" > 
      </p:ajax> 
      <p:column headerText="StudyPlan" sortBy="#{studyPlanList.name}" filterBy="#{studyPlanList.name}"> 
      <h:outputText value="#{studyPlanList.name}"/> 
      </p:column> 
     </p:dataTable> 

而不是p:列,如果它是h:鏈接它工作,我想實現類似的結果;請幫助。

+0

您好Matt Handy,已發佈表代碼。請檢查。 – user1281029 2012-04-27 10:15:05

回答

1

這是從f:setPropertyActionListener的Facelet標記文檔:

註冊與 最接近父UIComponent自定義操作

所以你需要一個觸發行動,使相關的UIComponent一個ActionListener實例這行得通。這可能是h:commandButtonh:commandLink。下面是一個簡單的例子:

<h:commandButton action="#{editBean.submitAction}" value="Select"> 
    <f:setPropertyActionListener target="#{editBean.name}" 
           value="#{studyPlanList.name}" /> 
</h:commandButton> 

由於您使用Primefaces,你可以看看的p:dataTable行選擇功能。這是一個example from the showcase

UPDATE:

類型的選擇應該是一樣的行元素的類型。我從您的代碼看到selection="#{editBean.selectedStudyPlan.name}"但它應該是

selection="#{editBean.selectedStudyPlan}" 
+0

您好我試圖給這樣的,但我沒有得到我的變量studyPlanList爲null的值。請幫助。 \t \t \t – user1281029 2012-04-27 09:24:27

+0

如果使用showcase中描述的行選擇功能,則不需要此事件偵聽器(偵聽器方法簽名是錯誤的)。選定的行自動設置爲您在'' – 2012-04-27 09:30:00

+0

'selection'屬性中指定的字段。但是該對象在託管bean中反映爲null,因爲該行中顯示的是實際值。 – user1281029 2012-04-27 09:44:13

相關問題