1

大家晚上好

我正在尝试更新页面中的字段并不断抛出异常。

我有一个主要对象“汽车”,它有一个“模型”的外键

当我建立我的页面时,我创建了一个选择框来列出所有模型。所以现在当我选择一个模型并提交表单时,我得到下面抛出的异常。只要我不包含模型字段,Car 表中的所有字段都会更新。一旦我尝试包含模型字段,代码就会在提交时中断。

org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/sellcar.jsp at line 28

25:                                             <c:forEach items="${cars}" var="car">
26:                                                     <option
27:                                                             value='<c:out value="${car.model.modId}"/>'
28:                                                             <c:if test="${car.model.model == status.value.model}">SELECTED</c:if>>
29:                                                             <c:out value="${car.model.model}" />
30:                                                     </option>
31:                                             </c:forEach>


**Stacktrace:**
        org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:111)
        org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
        org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1045)
        org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:810)
        org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:723)
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
        org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:360)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause 
javax.el.PropertyNotFoundException: Property 'model' not found on type java.lang.String
        javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:214)
        javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:191)
        javax.el.BeanELResolver.property(BeanELResolver.java:300)
        javax.el.BeanELResolver.getValue(BeanELResolver.java:81)
        javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
        org.apache.el.parser.AstValue.getValue(AstValue.java:123)
        org.apache.el.parser.AstEqual.getValue(AstEqual.java:38)
        org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
        org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:938)
        org.apache.jsp.WEB_002dINF.jsp.sellcar_jsp._jspx_meth_c_005fif_005f0(sellcar_jsp.java:847)
        org.apache.jsp.WEB_002dINF.jsp.sellcar_jsp._jspx_meth_c_005fforEach_005f0(sellcar_jsp.java:791)
        org.apache.jsp.WEB_002dINF.jsp.sellcar_jsp._jspService(sellcar_jsp.java:107)
        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:111)
        org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
        org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1045)
        org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:810)
        org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:723)
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
        org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:360)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
</b>

我的模型:

车:

package com.usedcarsearch.domain;

// Generated Feb 19, 2013 10:31:37 PM by Hibernate Tools 3.4.0.CR1

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;

/**
 * Car generated by hbm2java
 */
public class Car implements java.io.Serializable {

private Integer carId;
private Make make;
private State state;
private Model model;
private City city;
private String vin;
private int year;
private String image;
private String engine;
private String trans;
private String mileage;
private BigDecimal price;
private String color;
private BigDecimal hwyMpg;
private BigDecimal cityMpg;
private String address;
private String accessories;
private String comments;
private Set buyers = new HashSet(0);
private Set ownerships = new HashSet(0);
private Set carSearchLists = new HashSet(0);

public Car() {
}

public Car(Make make, State state, Model model, City city, int year,
        String engine, String trans, String mileage) {
    this.make = make;
    this.state = state;
    this.model = model;
    this.city = city;
    this.year = year;
    this.engine = engine;
    this.trans = trans;
    this.mileage = mileage;
}

public Car(Make make, State state, Model model, City city, String vin,
        int year, String image, String engine, String trans,
        String mileage, BigDecimal price, String color, BigDecimal hwyMpg,
        BigDecimal cityMpg, String address, String accessories,
        String comments, Set buyers, Set ownerships, Set carSearchLists) {
    this.make = make;
    this.state = state;
    this.model = model;
    this.city = city;
    this.vin = vin;
    this.year = year;
    this.image = image;
    this.engine = engine;
    this.trans = trans;
    this.mileage = mileage;
    this.price = price;
    this.color = color;
    this.hwyMpg = hwyMpg;
    this.cityMpg = cityMpg;
    this.address = address;
    this.accessories = accessories;
    this.comments = comments;
    this.buyers = buyers;
    this.ownerships = ownerships;
    this.carSearchLists = carSearchLists;
}

public Integer getCarId() {
    return this.carId;
}

public void setCarId(Integer carId) {
    this.carId = carId;
}

public Make getMake() {
    return this.make;
}

public void setMake(Make make) {
    this.make = make;
}

public State getState() {
    return this.state;
}

public void setState(State state) {
    this.state = state;
}

public Model getModel() {
    return this.model;
}

public void setModel(Model model) {
    this.model = model;
}

public City getCity() {
    return this.city;
}

public void setCity(City city) {
    this.city = city;
}

public String getVin() {
    return this.vin;
}

public void setVin(String vin) {
    this.vin = vin;
}

public int getYear() {
    return this.year;
}

public void setYear(int year) {
    this.year = year;
}

public String getImage() {
    return this.image;
}

public void setImage(String image) {
    this.image = image;
}

public String getEngine() {
    return this.engine;
}

public void setEngine(String engine) {
    this.engine = engine;
}

public String getTrans() {
    return this.trans;
}

public void setTrans(String trans) {
    this.trans = trans;
}

public String getMileage() {
    return this.mileage;
}

public void setMileage(String mileage) {
    this.mileage = mileage;
}

public BigDecimal getPrice() {
    return this.price;
}

public void setPrice(BigDecimal price) {
    this.price = price;
}

public String getColor() {
    return this.color;
}

public void setColor(String color) {
    this.color = color;
}

public BigDecimal getHwyMpg() {
    return this.hwyMpg;
}

public void setHwyMpg(BigDecimal hwyMpg) {
    this.hwyMpg = hwyMpg;
}

public BigDecimal getCityMpg() {
    return this.cityMpg;
}

public void setCityMpg(BigDecimal cityMpg) {
    this.cityMpg = cityMpg;
}

public String getAddress() {
    return this.address;
}

public void setAddress(String address) {
    this.address = address;
}

public String getAccessories() {
    return this.accessories;
}

public void setAccessories(String accessories) {
    this.accessories = accessories;
}

public String getComments() {
    return this.comments;
}

public void setComments(String comments) {
    this.comments = comments;
}

public Set getBuyers() {
    return this.buyers;
}

public void setBuyers(Set buyers) {
    this.buyers = buyers;
}

public Set getOwnerships() {
    return this.ownerships;
}

public void setOwnerships(Set ownerships) {
    this.ownerships = ownerships;
}

public Set getCarSearchLists() {
    return this.carSearchLists;
}

public void setCarSearchLists(Set carSearchLists) {
    this.carSearchLists = carSearchLists;
}

}

模型:

        package com.usedcarsearch.domain;

        // Generated Feb 19, 2013 10:31:37 PM by Hibernate Tools 3.4.0.CR1

        import java.util.HashSet;
        import java.util.Set;

        /**
         * Model generated by hbm2java
         */
        public class Model implements java.io.Serializable {

            private Integer modId;
            private String model;
            private Set cars = new HashSet(0);

            public Model() {
            }

            public Model(String model) {
                this.model = model;
            }

            public Model(String model, Set cars) {
                this.model = model;
                this.cars = cars;
            }

            public Integer getModId() {
                return this.modId;
            }

            public void setModId(Integer modId) {
                this.modId = modId;
            }

            public String getModel() {
                return this.model;
            }

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

            public Set getCars() {
                return this.cars;
            }

            public void setCars(Set cars) {
                this.cars = cars;
            }

        }

汽车.hbm

        <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/
             Hibernate Mapping DTD 3.0//EN"
     "http://hibernate.sourceforge.net
             /hibernate-mapping-3.0.dtd">
    <!-- Generated Feb 19, 2013 10:31:37 PM by Hibernate Tools 3.4.0.CR1 -->
    <hibernate-mapping default-lazy="false">
     <class name="com.usedcarsearch.domain.Car" table="Car">
      <id name="carId" type="java.lang.Integer">
       <column name="carId"/>
       <generator class="identity"/>
      </id>
      <many-to-one class="com.usedcarsearch.domain.Make" 
              fetch="select" name="make">
       <column name="fkMakeId" not-null="true"/>
      </many-to-one>
      <many-to-one class="com.usedcarsearch.domain.State" 
               fetch="select" name="state">
       <column name="fkStateId" not-null="true"/>
      </many-to-one>
      <many-to-one class="com.usedcarsearch.domain.Model" 
               fetch="select" name="model">
       <column name="fkModelId" not-null="true"/>
      </many-to-one>
              <many-to-one class="com.usedcarsearch.domain.City" 
               fetch="select" name="city">
       <column name="fkZipCode" not-null="true"/>
      </many-to-one>
      <property generated="never" lazy="false" name="vin" type="string">
       <column length="25" name="vin"/>
      </property>
      <property generated="never" lazy="false" name="year" type="int">
       <column name="year" not-null="true"/>
      </property>
      <property generated="never" lazy="false" name="image" type="string">
       <column length="100" name="image"/>
      </property>
      <property generated="never" lazy="false" name="engine" type="string">
       <column length="45" name="engine" not-null="true"/>
      </property>
      <property generated="never" lazy="false" name="trans" type="string">
       <column length="45" name="trans" not-null="true"/>
      </property>
      <property generated="never" lazy="false" name="mileage" type="string">
       <column length="20" name="mileage" not-null="true"/>
      </property>
      <property generated="never" lazy="false" name="price" type="big_decimal">
       <column name="price" precision="11"/>
      </property>
      <property generated="never" lazy="false" name="color" type="string">
       <column length="20" name="color"/>
      </property>
      <property generated="never" lazy="false" name="hwyMpg" type="big_decimal">
       <column name="hwyMpg" precision="3" scale="1"/>
      </property>
     <property generated="never" lazy="false" name="cityMpg" type="big_decimal">
       <column name="cityMpg" precision="3" scale="1"/>
      </property>
      <property generated="never" lazy="false" name="address" type="string">
       <column length="50" name="address"/>
      </property>
      <property generated="never" lazy="false" name="accessories" type="string">
       <column length="100" name="accessories"/>
      </property>
      <property generated="never" lazy="false" name="comments" type="string">
       <column length="100" name="comments"/>
      </property>
      <set fetch="select" inverse="true" lazy="false" name="buyers"
       sort="unsorted" table="Buyer">
       <key>
        <column name="fkCarId" not-null="true"/>
       </key>
       <one-to-many class="com.usedcarsearch.domain.Buyer"/>
      </set>
      <set fetch="select" inverse="true" lazy="false" name="ownerships"
       sort="unsorted" table="Ownership">
       <key>
        <column name="fkCarId" not-null="true"/>
       </key>
       <one-to-many class="com.usedcarsearch.domain.Ownership"/>
      </set>
      <set fetch="select" inverse="true" lazy="false" name="carSearchLists"
       sort="unsorted" table="Car_Search_List">
       <key>
        <column name="fkCarId" not-null="true"/>
       </key>
       <one-to-many class="com.usedcarsearch.domain.CarSearchList"/>
      </set>
     </class>
    </hibernate-mapping>

JSP 代码:(我没有包含所有内容,只包含必要的内容)

 <spring:bind path="command.model">
 <select name='<c:out value="${status.expression}"/>'>
    <option value=""></option>
    <c:forEach items="${cars}" var="car">
    <option value='<c:out value="${car.model.modId}"/>'
    <c:if test="${car.model.model == status.value.model}">SELECTED</c:if>>
    <c:out value="${car.model.model}" />
    </option>
        </c:forEach>
      </select>

4

2 回答 2

1

我把它修好了。看来我必须在 Car.hbm 中添加外键属性,同时将外键变量、getter 和 setter 添加到 Car。

于 2013-03-06T04:54:51.293 回答
0

根据错误消息,您可能希望将第 28 行从:

status.value.model

status.value
于 2013-03-05T22:25:41.903 回答