-1

I use Primefaces to display a lazy list of cars. As soon as I want to filter or select I get the message; Target Unreachable, 'street' returned null.

public class Car implements Serializable {

  private Map<String, Object> street;
  private UUID id;
  private String brand;
}

my datatable

    <p:dataTable id="cars" editable="true" editMode="cell" var="car"
            value="#{carListView.cars}"
            selection="#{carListView.selectedCar}"
            lazy="true" widgetVar="carsTable">
            <p:column headerText="Id">
                <h:outputText value="#{car.id}"/>
            </p:column>
            <p:column headerText="brand">
                <h:outputText value="#{car.brand}"/>
            </p:column>
            <p:column headerText="country" filterBy="#{car.street.city.country}">
                <h:outputText value="#{car.street.city.country}"/>
            </p:column>

    </p:datatable>

my view:

public class CarListView implements Serializable {

  @Inject
  LazyCarModel cars
  private Car car;
  private Car selectedCar;

  @Postconstruct
  public void init(){
    Car = new Car();
    selectedCar = new Car();

  }
}

and my load:

    @Override
    public List<Car> load(int first, int pageSize, String sortField,SortOrder sortOrder,Map<String, Object> filters) {

        myList = carService.getCars();
        return myList

    }

Can anyone figure out what s wrong with this code ?

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
Jean
  • 601
  • 1
  • 10
  • 26
  • Do you have proper getter setter methods in the Car class for all attributes including street? – A_C Dec 05 '18 at 08:08
  • Also, how do you expect this #{car.street.city.country} to get resolved, the street attribute in the Car class is a Map – A_C Dec 05 '18 at 08:09
  • thanks fors your answer, i dont have getter/setter. I declared it as a Map as the street object has often been changed. I will try to create a real ' street' object and see hox ti goes – Jean Dec 05 '18 at 08:12
  • Yes, please create a proper Street class and use it. Also, you should have proper getter/setter methods in order for the code to function properly. – A_C Dec 05 '18 at 08:15
  • Also, I would suggest revisiting your data model/ class hierarchy. Car -> Street -> City -> Country doesn't seem to be a good model to me. – A_C Dec 05 '18 at 08:16
  • it s not my actual model. I took it as an example – Jean Dec 05 '18 at 08:27
  • Your title (about car) and text (about street) still are not aligned... Please pay more attention in creating good questions. And check the duplicate. All is in there! – Kukeltje Dec 05 '18 at 09:21
  • Possible duplicate of [Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable](https://stackoverflow.com/questions/30128395/identifying-and-solving-javax-el-propertynotfoundexception-target-unreachable) – Kukeltje Dec 05 '18 at 09:23

1 Answers1

0

You should create proper getter/setter methods in your Car class.

Also, this #{car.street.city.country} won't resolve correctly because street is a Map in the Car class.

Create a Street class which embeds the proper data model which you want. Then use it in the street attribute datatype in the Car class.

A_C
  • 905
  • 6
  • 18