Spring MVC form:radiobuttons tag nicht die Einstellung value-Attribut
Hier ist der relevante code von meinem controller:
@ModelAttribute("store_location_types")
public StoreLocationType[] getStoreLocationTypes() {
return StoreLocationType.values();
}
Hier ist die definition von StoreLocationType, definiert in der gleichen Steuerung:
private enum StoreLocationType {
PHYSICAL("Physical"),
ONLINE("Online");
private String displayName;
private String value;
private StoreLocationType(String displayName) {
this.displayName = displayName;
this.value = this.name();
}
public String getDisplayName() {
return this.displayName;
}
public String getValue() {
return this.value;
}
}
Hier ist die entsprechende JSP-code:
<li>
<label>Location Type:</label>
<form:radiobuttons path="StoreLocationType" items="${store_location_types}" itemLabel="displayName" itemValue="value"/>
</li>
Ist das, was hier generiert wird, wenn die Seite gerendert wird:
<li>
<label>Location Type:</label>
<span>
<input id="StoreLocationType1" name="StoreLocationType" type="radio" value="">
<label for="StoreLocationType1">Physical</label>
</span>
<span>
<input id="StoreLocationType2" name="StoreLocationType" type="radio" value="">
<label for="StoreLocationType2">Online</label>
</span>
</li>
Die value-Attribute werden nicht aufgefüllt, mit dem "Wert" - Feld meiner enum. Was mache ich hier falsch? Was ich erwarten würde, zu sehen, ist diese:
<span>
<input id="StoreLocationType1" name="StoreLocationType" type="radio" value="PHYSICAL">
<label for="StoreLocationType1">Physical</label>
</span>
<span>
<input id="StoreLocationType2" name="StoreLocationType" type="radio" value="ONLINE">
<label for="StoreLocationType2">Online</label>
</span>
Dem value-Attribut des input-Tags sollte der Wert StorLocationType.ONLINE.getValue()
InformationsquelleAutor aamiri | 2013-06-22
Du musst angemeldet sein, um einen Kommentar abzugeben.
Kann ich nicht finden jedes problem in Ihrem code. Wenn ich es getestet habe funktioniert gut.
Aber in dem Fall können Sie es tun in einen einfacheren Weg. Sie müssen nicht fügen Sie die
value
Feld in der enum. Wenn Sie weglassen dieitemValue
Attribut<form:radiobuttons>
Frühling wird, setzen Sie den Namen der Instanzen von enum für den Wert vonitemValue
Attribut.So können Sie dies so tun.
Enum
JSP
InformationsquelleAutor Sanghyun Lee
Ich löste es über mehrere radiobutton-tags anstelle von einem einzelnen radiobuttons tag.
Hier ist der code der JSP:
Habe ich das gute Objekte aus der Datenbank, also in meinem Fall Wert war, die Id und der string angezeigt wurde der Beschreibung. Dies sollte aber die Arbeit mit enum zu.
InformationsquelleAutor Ena