2015-12-21 33 views
0

我有一個可以列出餐廳對象的工作數據表。 我想刪除/ edite中選擇的,但是當我選擇一個下列異常顯示出來:Primefaces選中的行ID == null

org.springframework.dao.InvalidDataAccessApiUsageException: The given id must not be null! 

下面是表:

<h:form id="restaurantForm"> 
    <p:dataTable var="restaurant" 
      value="#{restaurantLazyBean.lazyDataModel}" paginator="true" 
      rows="10" rowsPerPageTemplate="5,10,50" id="carTable" lazy="true" 
      selectionMode="single" selection="#{RestaurantEditBean.selected}" 
      rowKey="#{restaurant.id}" 
      paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"> 
      <p:ajax event="rowSelect" 
       listener="#{RestaurantEditBean.onRowSelect()}"/> 

      <p:column headerText="ID"> 
       <h:outputText value="#{restaurant.id}" /> 
      </p:column> 
     </p:dataTable> 

    </h:form> 

現在所有ID出現在表中,但在選擇出現異常。 我試着根據primefaces的例子做所有事情。但他們甚至沒有rowKey屬性。

繼承人豆如果多數民衆贊成在相關。

@Named("RestaurantEditBean") 
@ViewScoped 
@EJB(name = "ejb.RestaurantService", beanInterface = RestaurantService.class) 
public class RestaurantEditBean { 
@EJB 
private RestaurantService restaurantService; 
private RestaurantDTO selected; 

public void onRowSelect(SelectEvent event) { 
    selected = ((RestaurantDTO) event.getObject()); 
} 

public RestaurantService getRestaurantService() { 
    return restaurantService; 
} 

public void setRestaurantService(RestaurantService restaurantService) { 
    this.restaurantService = restaurantService; 
} 

public RestaurantDTO getSelected() { 
    return selected; 
} 

public void setSelected(RestaurantDTO selected) { 
    this.selected = selected; 
} 

}

Primefaces:5.3 JSF:2.2

+0

你調試過RestaurantEditBean.selected方法嗎?你的bean的名字也是駱駝嗎? – HRgiger

+0

@HRgiger RestaurantEditBean.selected是一種方法嗎?我認爲那是一個領域。根據http://www.primefaces.org/showcase/ui/data/datatable/lazy.xhtml 該屬性應該是具有相同類型的列表的對象。 @Named(「RestaurantEditBean」)它看起來像這樣。 –

+0

是的,但它調用setSelected來分配字段值,因爲您的字段被封裝。此外,你的bean名稱看起來不錯,只需添加一個斷點到this.selected = selected;並在調試模式下檢查參數。 – HRgiger

回答

0

我發現我做了一個可怕的錯誤。 在我的LazyDataModel中,我不得不重寫一個函數。

@Override 
    public RestaurantDTO getRowData(String rowKey) { 
     Long id = Long.parseLong(rowKey); 
     return restaurantService.findById(id); 
     } 

該問題是由前面的Long.getLong(rowKey)引起的,而且一個返回null。