Java-传递“时获取对象属性中的空值”;这";

Java-传递“时获取对象属性中的空值”;这";,java,eclipse,scala,playframework-2.3,Java,Eclipse,Scala,Playframework 2.3,我一直在读《为Java而玩》一书,这本书非常精彩。我对Java还是相当陌生,但我一直在学习这些示例,我有点被第3章卡住了。可以在此处找到代码: 问题是,当我执行boundform.get()时,表单的实际属性似乎并没有使其成为“product”对象。我已经在Eclipse的调试器中暂停了此操作,所有值都在Form boundForm=productForm.bindFromRequest()行正确设置但当我进入product.save()时,它们就消失了 我的控制器、型号、路由和表单如下所示。如

我一直在读《为Java而玩》一书,这本书非常精彩。我对Java还是相当陌生,但我一直在学习这些示例,我有点被第3章卡住了。可以在此处找到代码:

问题是,当我执行boundform.get()时,表单的实际属性似乎并没有使其成为“product”对象。我已经在Eclipse的调试器中暂停了此操作,所有值都在
Form boundForm=productForm.bindFromRequest()行正确设置
但当我进入
product.save()
时,它们就消失了

我的控制器、型号、路由和表单如下所示。如果需要其他信息,请告诉我

Products.java(控制器)

details.scala.html

@(productForm: Form[Product])

@import helper._

@import helper.twitterBootstrap._

@main("Product form") {
    <h1>Product form</h1>
    @helper.form(action = routes.Products.save()) {
        <fieldset>
            <legend>Product (@productForm("name").valueOr("New"))</legend>
            @helper.inputText(productForm("ean"), '_label -> "EAN")
            @helper.inputText(productForm("name"),'_label -> "Name")
            @helper.textarea(productForm("description"), '_label -> "Description")
        </fieldset>
        <input type="submit" class="btn btn-primary" value="Save">
        <a class="btn" href="@routes.Application.index()">Cancel</a>
    }
}
@(产品形式:形式[产品])
@导入助手_
@导入helper.twitterBootstrap_
@主要(“产品形式”){
产品形式
@helper.form(action=routes.Products.save()){
产品(@productForm(“name”).valueOr(“New”))
@helper.inputText(productForm(“ean”),“_标签->“ean”)
@helper.inputText(productForm(“名称”),“U标签->名称”)
@text区域(productForm(“说明”),“\u标签->说明”)
}
}
我相信这是显而易见的。非常感谢你

请参阅的“处理绑定失败”部分。在
窗体上调用
.get()
是不安全的,因为如果存在验证错误,它将返回
null
。首选的方法是首先通过
hasrerrors()
检查错误,然后从那里处理它

if (boundform.hasErrors()) {
    /* There are errors somewhere in the form, 
    * return it to the view and display them there, 
    * or do whatever else you need to handle the error.
    */
    return badRequest(...);
} else {
    // A valid `Product`, proceed as normal.
    Product product = boundform.get();

    return ok(....);
}

SBT缓存问题。我运行了
activator clean
,一切正常

我开始粘贴GitHub repo中的所有文件,看看是否可以缩小范围。这导致了一组新的错误,这些错误将我带到了线程中有SBT缓存建议的位置

我很感激你的建议和错误方法的链接,LimbSoup。无论如何,我肯定会调查这些问题,我相信我将来可能会不止一次地引用你的答案


非常感谢大家。

我恐怕对Scala和Play知之甚少,但您可以尝试在表单的实际属性上设置断点。在Eclipse中,如果您在属性定义上设置断点,然后右键单击以获取“断点属性”,则在修改属性时将允许您触发断点。然后,当有东西将stacktrace设置为null时,您可以使用它查看stacktrace。非常感谢您的回复和对条件断点的介绍。我不知道你能做到!不幸的是,断点似乎没有被捕获。这可能是因为该值开始时为null,实际上没有更改吗?我尝试了
this.name==null
this.name.equals(null)
,但都没有被捕获。
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET     /                           controllers.Application.index()
GET     /products/                  controllers.Products.list()
GET     /products/new               controllers.Products.newProduct()
GET     /products/:ean              controllers.Products.details(ean: String)
POST    /products/                  controllers.Products.save()

# Map static resources from the /public folder to the /assets URL path
GET     /assets/*file               controllers.Assets.at(path="/public", file)
@(productForm: Form[Product])

@import helper._

@import helper.twitterBootstrap._

@main("Product form") {
    <h1>Product form</h1>
    @helper.form(action = routes.Products.save()) {
        <fieldset>
            <legend>Product (@productForm("name").valueOr("New"))</legend>
            @helper.inputText(productForm("ean"), '_label -> "EAN")
            @helper.inputText(productForm("name"),'_label -> "Name")
            @helper.textarea(productForm("description"), '_label -> "Description")
        </fieldset>
        <input type="submit" class="btn btn-primary" value="Save">
        <a class="btn" href="@routes.Application.index()">Cancel</a>
    }
}
if (boundform.hasErrors()) {
    /* There are errors somewhere in the form, 
    * return it to the view and display them there, 
    * or do whatever else you need to handle the error.
    */
    return badRequest(...);
} else {
    // A valid `Product`, proceed as normal.
    Product product = boundform.get();

    return ok(....);
}