Hi,

these lines don't make sense:

                codeAutoComplete = new AutoCompleteTextField<Code>(
                                "code",
                                new PropertyModel<Code>(codeModel.getObject(), 
"code"),
                                getAutocompleteRenderer()) {


If codeModel contains a Code instance, why are binding the autocomplete on a "code" property of the code object? It should the following:

                codeAutoComplete = new AutoCompleteTextField<Code>(
                                "code",
                                codeModel,
                                getAutocompleteRenderer()) {

Sven

On 03/10/2013 02:41 PM, grazia wrote:
I have a panel containing an autocomplete. The autocomplete contains its own
converter.
The model of the page that contains the autocomplete-panel should be updated
to the converted object of the autocomplete, and it does, but (here it shows
my lack of wicket knowledge) somehow it gets set once with the full
converted object, and once with an object where only the name field of the
object has been set (the rest being null).

Here is a skeleton of the code (Panel and page where it is used)

public class NewPanel extends Panel {

final Component targetComponent;
final AutoCompleteTextField<Code> codeAutoComplete;

        public NewPanel(final String id,
                        final IModel<Code> codeModel, final Component 
component) {
                super(id);
                this.targetComponent = component;

                codeAutoComplete = new AutoCompleteTextField<Code>(
                                "code",
                                new PropertyModel<Code>(codeModel.getObject(), 
"code"),
                                getAutocompleteRenderer()) {

                        @Override
                        protected Iterator<Code> getChoices(String input) {
                          (...)
                         }
                       @Override
                        public final IConverter getConverter(Class type) {
                                return new IConverter() { (...) }
                       };
                       codeAutoComplete.add(new
AjaxFormComponentUpdatingBehavior(
                                "onchange") {

                        private static final long serialVersionUID = 1L;

                        @Override
                        protected void onUpdate(AjaxRequestTarget target) {
                                
codeModel.setObject(codeAutoComplete.getConvertedInput());
                                target.add(targetComponent);

                        }
                });
                codeAutoComplete.setType(Code.class);
                add(codeAutoComplete);

}

public class NewCodeAssociationPage extends WebPage {

private IModel<Code> pascodeModel = new Model<Code>(new Code());
final Set<Code> codeList = new HashSet<Code>();
        
final IModel<List&lt;Code>> associatedCodes = new
LoadableDetachableModel<List&lt;Code>>() {
                @Override
                protected List<Code> load() {
                        (...)
                };
        };

final IModel<List&lt;Code>> availableCodes = new
LoadableDetachableModel<List&lt;Code>>() {

                @Override
                protected List<Code> load() {
                        if (codeModel.getObject() != null) {
                                codeList.add(codeModel.getObject());
                        }
                        codeList.addAll(associatedCodes.getObject());
                        return new ArrayList<Code>(codeList);
                }
        };
public NewCodeAssociationPage() {


final Form<Code> form = new Form<Code>("form");
                final Palette<Code> palette = new Palette<Code>("palette",
                                associatedCodes, availableCodes,
                                new ChoiceRenderer<Code>("code", "codeId"), 25, 
false);
                palette.setOutputMarkupId(true);

                final NewCodePanel codePanel = new NewCodePanel(
                                "codeAutoCompletePanel", codeModel, palette);
}

}

THe set codeList in the NewCodeAssociationPage ends up containing a
"converted" Code object ( so, something looking like
Code[code=ABCDE,codeId=30] AND also the same just with the code name
specified: Code[code=ABCDE,codeId=null] So, it ends up showing twice in my
palette.
THere is something incorrect I do with the autocomplete panel and the model,
and I have not understood what it is. I would greatly appreciate any pointer
in the right direction.



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/on-models-and-Panels-tp4657131.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to