游戏形式! 2.5

时间:2015-11-24 09:51:31

标签: playframework playframework-2.0 ebean

我玩了! 2.2我升级到2.5的项目。但是,自升级以来,我遇到了数据库问题,看起来配置错误或遗漏。 似乎没有保存更改,并且表单也不起作用。

我在 application.conf

中声明了ebeans指令
ebean.default= ["models.*"]

然后当然在plugins.sbt和build.sbt中加载模块。 我的代码示例,我有一个设备:

@Entity
public class Device extends Model {

    @Id
    public Long id;

    @Constraints.Required
    public String name;

    @Constraints.Required
    public String ipAddress;

    @Constraints.Required
    public String uniqueId;

    @OneToMany(mappedBy="device")
    public List<Sensor> sensors = new ArrayList<>();

    @OneToMany(mappedBy="device")
    public List<Action> actions = new ArrayList<>();

    @OneToOne
    public LogItem latestError;

    @Version
    public Timestamp lastUpdate;

    public boolean debugMode;

    public boolean statusLed;

    public static Finder<Long, Device> find = new Finder<Long, Device>(
            Long.class, Device.class
    );

    public List<ValidationError> validate() {
        /*
        List<ValidationError> errors = new ArrayList<ValidationError>();
        if (User.byEmail(email) != null) {
            errors.add(new ValidationError("email", "This e-mail is already registered."));
        }
        return errors.isEmpty() ? null : errors;
        */
        return null;
    }
}

这是我的控制者:

public static Result add() {
    Form<Device> deviceForm = Form.form(Device.class);
    return ok(editView.render(deviceForm, null));
}

这个模板:

@(deviceForm: Form[Device], device: Device)

    @if(deviceForm.hasGlobalErrors) {
        <ul>
        @deviceForm.globalErrors.foreach { error =>
            <li>error.message</li>
        }
        </ul>
    }


    @main("Edit a device") {

        @if(deviceForm("id").value == "" || deviceForm("id").value == null) {
            <h2>Add the device</h2>
        } else {
            <h2>Update the device</h2>
        }

        @helper.form(action = routes.Devices.update()) {

            @helper.inputText(
                deviceForm("name"),
                '_label -> "Device name"
            )

            @helper.inputText(
                deviceForm("ipAddress"),
                '_label -> "IP Address"
            )

            @helper.inputText(
                deviceForm("uniqueId"),
                '_label -> "Unique ID"
            )

            @helper.checkbox(
                deviceForm("statusLed"),
                '_label -> "Status light"
            )

            @helper.checkbox(
                deviceForm("debugMode"),
                '_label -> "Debug mode"
            )

            @if(device != null){
            <div>Sensors:</div>
            <div>
            <table class="adminTable">
            @for(sensor <- device.sensors) {
              <tr>
              <td>@sensor.value</td>
              <td><a href="@routes.Sensors.edit(sensor.id)">edit<a/> | <a href="@routes.Sensors.delete(sensor.id)">delete</a></td>
              </tr>
            }
            </table>
            </div>
            }
            @if(deviceForm("id").value != "" && deviceForm("id").value != null) { <div>Last updated: @device.lastUpdate.format("dd MMM yy - HH:mm:ss")</div> }
            <div>
                <input type="hidden" name="id" value="@deviceForm("id").value">
                <input type="submit" value="Submit">
            </div>
        }

        <a href="@routes.Devices.index()">Cancel</a>
    }

当我填写所有字段并单击“提交”时,我收到以下错误:

[error] p.c.s.n.PlayDefaultUpstreamHandler - Cannot invoke the action
java.lang.IllegalStateException: JSR-303 validated property 'name' does not have a corresponding accessor for data binding - check your DataBinder's configuration (bean property versus direct field access)
    at play.data.Form.bind(Form.java:372) ~[play-java_2.11-2.4.4.jar:2.4.4]
    at play.data.Form.bindFromRequest(Form.java:222) ~[play-java_2.11-2.4.4.jar:2.4.4]
    at controllers.Devices.update(Devices.java:44) ~[classes/:na]
    at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$4$$anonfun$apply$4.apply(Routes.scala:558) ~[classes/:na]
    at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$4$$anonfun$apply$4.apply(Routes.scala:558) ~[classes/:na]
    at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:136) ~[play_2.11-2.4.4.jar:2.4.4]
    at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$14$$anon$3$$anon$1.invocation(HandlerInvoker.scala:127) ~[play_2.11-2.4.4.jar:2.4.4]
    at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:70) ~[play_2.11-2.4.4.jar:2.4.4]
    at play.GlobalSettings$1.call(GlobalSettings.java:67) ~[play_2.11-2.4.4.jar:2.4.4]
    at play.core.j.JavaAction$$anonfun$7.apply(JavaAction.scala:94) ~[play_2.11-2.4.4.jar:2.4.4]
Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'name' of bean class [models.Device]: Bean property 'name' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
    at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:731) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:722) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.validation.AbstractBindingResult.rejectValue(AbstractBindingResult.java:108) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at play.data.Form.bind(Form.java:366) ~[play-java_2.11-2.4.4.jar:2.4.4]
    at play.data.Form.bindFromRequest(Form.java:222) ~[play-java_2.11-2.4.4.jar:2.4.4]
    at controllers.Devices.update(Devices.java:44) ~[classes/:na]
    at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$4$$anonfun$apply$4.apply(Routes.scala:558) ~[classes/:na]
    at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$4$$anonfun$apply$4.apply(Routes.scala:558) ~[classes/:na]
    at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:136) ~[play_2.11-2.4.4.jar:2.4.4]
[error] application - 

我还有一个预先填充的记录,当我编辑它时,表单字段都是空的。但是,调试显示数据存在,并且从对象本身生成的列表“传感器”也会出现。

所以Play中的配置一定有问题! 2.5,但我无法弄清楚是什么。

1 个答案:

答案 0 :(得分:1)

这似乎是一个缓存问题。使用:

activator clean
activator clean-files

并重建项目解决了这个问题。