Java 使用Play框架从html选择表单检索数据

Java 使用Play框架从html选择表单检索数据,java,select,playframework,Java,Select,Playframework,正如标题所说,我试图从html选择表单中检索所选项目。我试着用下面的代码来做,但它不起作用!城市值始终为空,但地址字段返回正确的值 form.html: #{extends '/Admin/admin.html' /} #{form @save(id)} #{ifErrors} <p class="error"> Please correct these errors. </p> #{/ifErr

正如标题所说,我试图从html选择表单中检索所选项目。我试着用下面的代码来做,但它不起作用!城市值始终为空,但地址字段返回正确的值

form.html:

#{extends '/Admin/admin.html' /}
 #{form @save(id)}

    #{ifErrors}
        <p class="error">
            Please correct these errors.
        </p>
    #{/ifErrors}

    <p>
        <label>Adresse</label>
        <input type="text" name="adress" value="${flash.adress}" id="adress" />
        <span class="error">#{error 'adress' /}
    </p>
    <p>
        <label>Ville</label>
        <select size="1" >
            #{list items:cities, as:'city'}
                <option name="city" id="city" value="${flash.city}">${city}</option>
            #{/list}
        </select>
        <span class="error">#{error 'city' /}
    </p>
    <p>
        <input type="submit" value="Publier l'annonce" />
    </p>

 #{/form}

它不会那样工作,它应该是这样的:

public static void save(long id, String adress, @Required String city){ 
    // in order or so I think...: get the city ID or whatever, process all the data and save
    System.out.println(city);
    Admin.index();
}
我相信还有另一种方法是你正在寻找的:

它不会那样工作,它应该是这样的:

public static void save(long id, String adress, @Required String city){ 
    // in order or so I think...: get the city ID or whatever, process all the data and save
    System.out.println(city);
    Admin.index();
}
我相信还有另一种方法是你正在寻找的:

您必须将选择标签命名为非选项标签,并且必须使用正确的字段:

<select size="1" name="city.id">
            #{list items:cities, as:'city'}
                <option value="${city.id}">${city.name}</option>
            #{/list}
</select>

有关绑定的更多信息,请参阅文档:

您必须命名您的选择标记而不是选项标记,并且必须使用正确的字段:

<select size="1" name="city.id">
            #{list items:cities, as:'city'}
                <option value="${city.id}">${city.name}</option>
            #{/list}
</select>
有关绑定的更多信息,请参见文档: