構築を使用して JSP から POST でバックエンドにデータを送信する際に問題があります。
<form:radiobuttons path="pvClCategory" items="${categoryList}" itemLabel="clcaCategory"/>
私の Jboss (バージョン 5) を送信した後、次のように表示されます。
HTTP Status 400 - description: The request sent by the client was syntactically incorrect ().
送信されたリクエストを表示する方法がわかりません。以下の構築を使用している場合、すべて正常に動作しますが、オブジェクトから 1 つの値だけをバインドするのではなく、オブジェクト全体をバインドします。
<form:radiobuttons path="pvClCategory.clcaCategory" items="${categoryList}" itemValue="clcaCategory" itemLabel="clcaCategory"/>
したがって、最初のフォーム構築 (オブジェクト全体をバインドする) で問題が発生します。フォームが適切に初期化されているということは、ラジオ オプションが正しく表示され、jsp サイトで正しい値が選択されていることを意味します。しかし、フォームを送信しようとすると問題が発生し、エラーが発生します (クライアントから送信された HTTP ステータス 400 要求が構文的に正しくありません)。理由はありますか?私が間違っていることは何ですか?
私のコード:
ClCategory の pvClCategory タイプという名前のフィールドを持つエンティティ クラス違反が 1 つあります。
@Entity
@Table(name="PV_VIOLATIONS")
public class Violation implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="VIOL_ID")
private Long id;
@ManyToOne
@JoinColumn(name="VIOL_CLCA_ID")
private ClCategory pvClCategory;
/* others fields and getters/setters */
}
それを Violation.pvClCategory フィールドにバインドするために必要な私の ClCategory エンティティ クラス:
@Entity
@Table(name="PV_CL_CATEGORIES")
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
public class ClCategory implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="CLCA_ID")
private long clcaId;
@Column(name="CLCA_CATEGORY")
private String clcaCategory;
@OneToMany(mappedBy="pvClCategory")
private List<Violation> pvViolations;
public ClCategory() {
}
public long getClcaId() {
return this.clcaId;
}
public void setClcaId(long clcaId) {
this.clcaId = clcaId;
}
public String getClcaCategory() {
return this.clcaCategory;
}
public void setClcaCategory(String clcaCategory) {
this.clcaCategory = clcaCategory;
}
public List<Violation> getPvViolations() {
return this.pvViolations;
}
public void setPvViolations(List<Violation> pvViolations) {
this.pvViolations = pvViolations;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (clcaId ^ (clcaId >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ClCategory other = (ClCategory) obj;
if (clcaId != other.clcaId)
return false;
return true;
}
}
この Violation クラスは、私のフォームの commandName プロパティで次のように使用されます (ファイル名: v.jsp):
<form:form action="../update" method="post" commandName="violation">
<form:radiobuttons path="pvClCategory" items="${categoryList}" itemLabel="clcaCategory"/>
<!-- other fields -->
<button type="submit" value="Apply Changes" class="button-default" >Apply</button>
</form:form>
私のコントローラー:
@Controller
@RequestMapping("/viol")
public class ViolationController {
@RequestMapping("edit/{violationId}")
public String edit(@PathVariable("violationId") long id, Map<String, Object> map) {
Violation violation = violationService.getViolation(id);
map.put("violation",violation);
map.put("categoryList", adminService.listCategories());
return "v";
}
}
構築フォームで理解しているように、radiobuttons path="" items=""パスはデータバインディングのプロパティであるため、アイテム内の配信リストからのオブジェクト全体をそれにバインドする必要があります。タイプ ClCategory のオブジェクトであるカテゴリの項目リストを入力します。送信後にエラーが表示されます。
form: radiobuttons path="pvClCategory.clcaCategory" items="${categoryList}" itemValue="clcaCategory" itemLabel="clcaCategory"を使用して、アイテム内のオブジェクトの文字列値のみをバインドする場合 (どちらの場合も同じオブジェクト リストが使用されます) ClCategory 型) の場合、フォームは正しく送信されますが、オブジェクトの値を 1 つだけバインドするのではなく、オブジェクト全体をバインドしたくありません。私が間違っていることを教えてください。