Hi, thanks for the tip.. unfortunately , I tried this, (a shorter version at
least..)
add( new DropDownChoice("userProfile.city",
new PropertyModel(this.getModel(), "userProfile.city"),
new LoadableDetachableModel() {
@Override
protected Object load() {
return sysMultivaluesProvider.getMVList("CITY");
}
}
)
);
but the problem is the same the selected value is persisted into the
database but when I edit the record the value is not "selected" in the
dropdown.. any clues?
I'm obviously missing something!!
TIA
On Thu, Jan 7, 2010 at 1:43 PM, Kogel, Jonck-van-der <
[email protected]> wrote:
> Hi,
> I also had this problem once. It turned out to have to do with my list
> of choices becoming stale. I solved this by putting the choices in a
> LoadableDetachableModel.
>
> ie:
>
> IModel<List<YourObject>> yourObjectsModel = new
> LoadableDetachableModel<List<YourObject>>() {
> @Override
> protected List<YourObject> load() {
> return yourObjectService.findAll();
> }
>
> };
>
> add(new YourDropDownChoice<YourObject>("foo",
> new PropertyModel<YourObject>(yourModel, "bar"),
> yourObjectsModel));
>
>
> ________________________________
>
> From: Facundo Miquel [mailto:[email protected]]
> Sent: donderdag 7 januari 2010 15:18
> To: [email protected]
> Subject: DropDownChoice and selected value...
>
>
> Hello all..
>
> First of all, I know that this has been discussed here, I searched the
> archives but could not find an answer, or at least understand one, so
> please If someone can help me I would greatly appreciate it...
>
>
> I have a small problem with Drop Down Choices and the selected value
> when editing an existing record... and I wanted to validate that I'm
> doing things the correct way.. and if so.. if there is a known issue....
>
> the scenario is as follows...
>
> I created an extended class (just to simplify my work) to generate DDC
> from a multivalues tables (aka, a table where one holds different types
> of things.. countries, cities, status codes, etc..).
>
> The rest of the mail will be in RED for readability...
>
> In my tables I'm required to store the code and not the value so
> basically I created the following class..(these are fractions.. I'm
> attaching the actual clasess..)
>
> public class mvDropDownChoice extends DropDownChoice {
> ...
> static List mvValues = null;
> @SuppressWarnings("serial")
> public mvDropDownChoice(String id, String mvCode, IModel model) {
> super(id, new PropertyModel(model,
> id),sysMultivaluesProvider.getMVList(mvCode),new IChoiceRenderer() {
> public String getDisplayValue(Object object) {
> SysMultivalues mv = (SysMultivalues) object;
> return mv.getMvMeaning();
> }
> public String getIdValue(Object object, int index) {
> if (index == -1)
> return null;
> return ((SysMultivalues)mvValues.get(index)).getMvCode();
> }
> });
> mvValues = sysMultivaluesProvider.getMVList(mvCode);
> }
> ...
> ..
>
>
> now I call this in the following way..
> ---
> ....
> import net.databinder.valid.hib.ValidDataForm;
>
> @AuthorizeInstantiation(Roles.USER)
> public class updateUserProfile extends Panel{
>
> private static final long serialVersionUID = 2834437668800017171L;
> EditForm form;
> ...
> public updateUserProfile(String id, String userId) {
> super(id);
> final Integer userIdInt = Integer.parseInt(userId);
> add(form = new EditForm("userProfileForm",
> Long.parseLong(userId.trim())));
>
>
>
>
> }
>
>
>
>
> protected class EditForm extends ValidDataForm {
> @SuppressWarnings({ "serial", "unchecked" })
> public EditForm(String id, Long userId) {
> super(id, SecUsers.class,userId);
> add(new TextField("userName").setRequired(true));
> .....
> add(new mvDropDownChoice("userProfile.country","COUNTRY",
> this.getModel()));
> .....
>
> and this generates the following HTML output
> --
> <select name="userProfile.country" class="select"
> wicket:id="userProfile.country">
> <option selected="selected" value="">Choose One</option>
>
> <option value="ARG">Argentina</option>
> <option value="UY">Uruguay</option>
> </select>
>
> ---
>
>
> Wich is correct, O have the code.. as the value. the description as the
> user readable choice.. the CODE is persisted to the database (AKA in a
> select country from sec_users the country is returned ARG | UY and not
> Argentina | Uruguay which is what I need..) but my problem as stated
> before is that I can't get the choice to come up with the correct
> selected value (Argentina / Uruguay) and it always comes out with
> "Choose One"..
>
>
>
>
> TIA
>
>
>
>
>