Thanx for the tip. It work on some cases. I found a pattern. For instance, if
a component (be it a textfield or a DropDownChoice) has it self a Model, for
instance a PropertyModel, the instance variables of the class that is used
on the form model (CompoundPropertyModel) are not filled.
EXAMPLE
the form:
public class ImovelHabitacionalForm extends Form {
private final ImovelHabitacionalInput
imovelHabitacionalInput = new ImovelHabitacionalInput();
...........
public ImovelHabitacionalForm() {
super(ID);
setModel(new
CompoundPropertyModel(imovelHabitacionalInput));
buildForm();
}
/*The components creations */
private void buildForm() {
/*TRANSACTION TYPES*/
List transactionTypes =
TipoTransaccaoFacade.getTipoTransaccoes();
transactionType = new
DropDownChoice("transactionType", transactionTypes);
/*DISTRICTS*/
DistritosModel
distritosModel = new DistritosModel();
selectedDistrito = new
SelectedChoice(); /*class with a instance variable "selectedChoice" and
getter and setter*/
distritosDDC = new
DropDownChoice("distritos", new PropertyModel(selectedDistrito,
"selectedChoice"), distritosModel);
/*PRICE*/
priceTextField = new
TextField("price");
/*AREA*/
/*Class with a variable name
area and a getter and a setter*/
private TextFieldAreaModel
areaModel = new TextFieldAreaModel();
areaTextField = new
TextField("area", new PropertyModel(areaModel, "area"));
}
}
/*Part of the user input class used on the form model*/
private class ImovelHabitacionalInput implements IClusterable {
private String district= "";
private String transactionType= "";
private String price= "";
private String area = "";
/*GETTERS AND SETTERS*/
}
When the form is submited happens that the transactionType and the price
variables on the class ImovelHabitacionalInput are filled with the values
inserted by the user, but the district and the area dont. the diferences
between the textfields and the dropdownchoices is that the transactionType
and the price doesn't have a model itself.
Does any one knows why if a model is supllyed to a form model, the
respective instance variables are not filled, even more, those getters and
setters are not called (in debug mode i noticed that too).
Thanks a lot everyone
MARCO SANTOS
Marcin Palka wrote:
>
> The code below works just fine for me. Instead of using complex type as a
> model object for a drop down I use an instance of IChoiceRenderer to
> control what's used for an id and what's displayed as a value.
>
> User user = ....;
> setModel(new CompoundPropertyModel(user));
> ....
> add(new DropDownChoice("usrRole", SystemRole.asStringList(),
> new IChoiceRenderer() {
>
> @Override
> public String getDisplayValue(Object object) {
> return Enum.valueOf(SystemRole.class,
> object.toString()).getRoleName();
> }
>
> @Override
> public String getIdValue(Object object, int index) {
> if (index == -1) {
> return SystemRole.SALESMAN.toString();
> }
> return SystemRole.asStringList().get(index);
> }
> }).setRequired(true));
>
> The combo items are populated from Enum values:
>
> public enum SystemRole {
>
> SYS_ADMIN("Administrator systemu"),
> SERVICEMAN("Serwisant"),
> NETWORK_ADMIN("Administrator sieci"),
> SALESMAN("Pracownik punktu"),
> ANY("Bez roli");
> private final String roleName;
>
> SystemRole(String roleName) {
> this.roleName = roleName;
> }
>
> public String getRoleName() {
> return roleName;
> }
> private static List stringList;
>
> public static List asStringList() {
> if (stringList == null) {
> stringList = new ArrayList();
> for (SystemRole sr : values()) {
> stringList.add(sr.toString());
> }
> }
> return stringList;
> }
> }
>
> And this is how model object looks like:
>
> public class User {
> private Integer usrId;
> private String usrLogin;
> private String usrPasswrd;
> private String usrEmail;
> private String usrMobile;
> private String usrLandline;
> private String usrFirstName;
> private String usrLastName;
> private String usrRole;
> }
>
> Hope this helps :-)
>
> cheers,
> Marcin
>
>
--
View this message in context:
http://www.nabble.com/CompoundPropertyModel-and-Combobox-tp23733910p23771469.html
Sent from the Wicket - User mailing list archive at Nabble.com.