Hi!

Normally this should work just fine:

otReasonDropDown = new DropDownChoice("otReason", new PropertyModel
(commentAndOtReason, "otReasonText"), ldm2);
otReasonDropDown.setNullValid(false);

So my guess is that either commentAndOtReason is null (unlikely, as that
would throw an NPE in the other code you provided)
or commentAndOtReason.otReasonText is null.

The PropertyModel (and any model for that matter) is a simple container to
pull a value out for display/use and push a value back (e.g. on form
submit).

If you put a breakpoint on the line where you construct the DropDownChoice,
you can inspect the variable commentAndOtReason to see what is inside.

Should that not be the issue, and the
variable commentAndOtReason.otReasonText contains text, then it means that
between construction and render of your page, the commentAndOtReason is
updated and/or its contents are updated.

If you still cannot figure it out, please provide a quickstart that
demonstrates your issue. That will help others (like me) to spot the
underlying issue quickly.

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 14 december 2023 bij 19:27:30, Nelligan, Steven M (snell...@illinois.edu)
schreef:


Help, I am new to Wicket...and have taken over a project with wicket
version 1.4.18.

I need to add another DropDownChoice in my application.
I was able to create the add logic, but the change logic is not working as
expected.
I've been working on this for a couple of weeks, and still could not get it
working.
Following is a snip of code causing the problem:
otReasonDropDown = new DropDownChoice("otReason", new PropertyModel
(commentAndOtReason, "otReasonText"), ldm2);
otReasonDropDown.setNullValid(false);
if (commentAndOtReason.getOtReasonText() != null) {
//
otReasonDropDown.setDefaultModelObject(commentAndOtReason.getOtReasonText()
+ "");
otReasonDropDown.setDefaultModelObject(commentAndOtReason.getOtReasonText()
+ "");
}
String s3 = ((String) otReasonDropDown.getModelObject());
String s31 = ((String)otReasonDropDown.getDefaultModelObjectAsString());
int i3 = 1; //debugging
timeCardForm.add(otReasonDropDown);

The variable commentAndOtReason.otReasonText contains the string I want the
dropdown list to show as a default.

But the dropdown list is not showing any default, but rather an empty
value.
If I select the dropdownlist, it shows the select list, including what I
want as a default value.

How do I setup DropDownChoice to have the value in
commentAndOtReason.otReasonText show as the current value(default value).

Thanks,
Steven M Nelligan
SENIOR SOFTWARE DEVELOPER

Reply via email to