I'm filling a form with data from a CompoundPropertyModel
. My TextArea
and DateTextField
get their value by using the name of the field of the Model as the Id so it will look for a Model in it's parents and find the value through reflection, as described in http://ift.tt/2z0uAEg. But I fail to get this working for my DropDownChoice
. The value stays null.
Would love to hear if someone knows what I'm doing wrong. Currently have a workarround in place where I give a PropertyModel
of the FotoGroep
to my DropDownChoice
constructor.
Class:
public class ImageControlForm<T extends Foto> extends StatelessForm<Foto> {
private TextArea<String> beschrijving;
private DateTextField datum;
private DropDownChoice<FotoGroep> groep;
public ImageControlForm(String id, CompoundPropertyModel<Foto> fotoModel) {
super(id, fotoModel);
setMultiPart(true);
setDefaultModel(fotoModel);
add(maakBeschrijvingField());
add(maakDatumField());
add(maakGroepField());
}
private TextArea<?> maakBeschrijvingField() {
beschrijving = new TextArea<>("beschrijving");
return beschrijving;
}
private DateTextField maakDatumField() {
datum = new DateTextField("datum", "d/M/yy");
datum.add(new DatumPicker());
return datum;
}
private DropDownChoice<FotoGroep> maakGroepField() {
Order sortOrder = Helper.createOrder("naam", SortOrder.ASC);
List<FotoGroep> fotoGroepen = databaseService.getPictureGroups(sortOrder);
groep = new DropDownChoice<>("fotoGroep", fotoGroepen, new ChoiceRenderer<FotoGroep>("naam", "fotoGroepId"));
groep.isRequired();
return groep;
}
Foto:
@Entity
@Table(name = "XS_FOTO")
public class Foto extends BasisModel implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "FOTO_ID")
private Long fotoId;
@Column(name = "BESCHRIJVING", nullable = true)
private String beschrijving;
@Column(name = "DATUM", nullable = true)
@Temporal(TemporalType.DATE)
private Date datum;
@ManyToOne
@JoinColumn(name = "FOTO_GROEP_ID", nullable = false)
private FotoGroep fotoGroep = new FotoGroep(Long.valueOf(12));
(getters and setters)
FotoGroep:
@Entity
@Table(name = "XS_FOTO_GROEP")
public class FotoGroep extends BasisModel implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "FOTO_GROEP_ID")
private Long fotoGroepId;
@Column(name = "NAAM", nullable = false)
private String naam;
(getters and setters)
Aucun commentaire:
Enregistrer un commentaire