0
votes

I have a working datatable that can list out restaurant objects. I want to delete/edite the selected ones but when I select one the following exception shows up:

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

Here is the table:

    <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>

Now all ids appear in the table but on selection the exception shows up. I tried to do everything according to the primefaces example. But they didn't even have the rowKey attribute.

Heres the bean if thats relevant.

@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

1
did you debug RestaurantEditBean.selected method? also does your bean name camelCase? - HRgiger
@HRgiger RestaurantEditBean.selected is that a method? I thought that was a field. According to the primefaces.org/showcase/ui/data/datatable/lazy.xhtml that property should be an object with the same type of the list. @Named("RestaurantEditBean") it looks like this. - Miklós Kosárkár
yes but it calls setSelected to assign field value because your field is encapsulated. Also your bean name looks ok, just add a break point to this.selected = selected; and check parameter in debug mode. - HRgiger
The flow doesn't even reach that part of the code. Heres a screenshot of the network. link - Miklós Kosárkár
Why is the annotation @EJB positioning over the managed bean RestaurantEditBean? What magic is being played by it? How is the exception coming from org.springframework while using EJBs? - Tiny

1 Answers

0
votes

I found out that I did a terrible mistake. In my LazyDataModel I had to override a function.

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

The issue was cause by the previous Long.getLong(rowKey) and that one returned null.