Question

I am trying to get a remove button on every row of a dynamically generated table using JSTL. All of the database fields come through no problem using the forEach method and generate the table. When I try to do the same for the ID (integer & table Primary Key) it gives the error "Property 'cars_id' not found on type logon.Car". They Id can be extracted from the result list using resultList.get(1).getID() and it prints to jsp page on the screen no problem.

Is there any thing I am missing here? Any IDeas?

MY JSP:

 <% 
List<Car> resultList = new ArrayList<Car>();
resultList=(List<Car>)request.getAttribute("ResultList");

%>
<table border="1">
<thead title="Current Cars"/>
<tr><th>Make:</th><th>Model:</th><th>Year:</th><th>Colour:</th><th>Information:</th></tr>
<tbody>
<c:forEach items="${ResultList}" var="car">
<tr>
    <td>${car.carMake}</td>
    <td>${car.model}</td>
    <td>${car.carYear}</td>
    <td>${car.carColour}</td>
    <td>${car.information}</td>
  <td>
        <form action="CarServlet" method="get">
            <input type="hidden" name="carId" value="${car.cars_id}" />
            <input type="submit" value="Remove" name="remove">
        </form>
    </td> 
</tr>
</c:forEach>
</tbody>
</table>

My Car.java

@Entity
@Table(name = "cars")
public class Car {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int cars_id;

@Column(name = "cars_make")
private String carMake;

@Column(name = "year")
private String carYear;

@Column(name = "colour")
private String carColour;

@Column(name="information")
private String information;

@Column(name="model")
private String carModel;

//NOTE:"user_id" below in (@JoinColumn(name="user_id"))...is the name
//of the field in my sql that corresponds to id from User table 

    @ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({ @JoinColumn(name = "user_id", referencedColumnName="id") })
private User user;



public User getUser() {
    if (user == null) {
        user = new User();
    }
    return user;
 }

public void setUser(User user) {
    this.user = user;
}

    public int getCar_id() {
    return cars_id;
}

public void setCar_id(int cars_id) {
    this.cars_id = cars_id;
}

public String getCarMake() {
    return carMake;
}

public void setCarMake(String carMake) {
    this.carMake = carMake;
}

public String getModel() {
    return carModel;
}

public void setModel(String carModel) {
    this.carModel = carModel;
}

public String getCarYear() {
    return carYear;
}

public void setCarYear(String carYear) {
    this.carYear = carYear;
}

public String getCarColour() {
    return carColour;
}

public void setCarColour(String carColour) {
    this.carColour = carColour;
}

public String getInformation() {
    return information;
}

public void setInformation(String information) {
    this.information = information;
}
 }
Was it helpful?

Solution

${car.cars_id} should be ${car.car_id}

The EL field name should match the bean method name instead of the class field itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top