You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Java Programmer <jp...@gmail.com> on 2010/09/21 16:10:23 UTC

Palette model changing problem

Hello,
I have a problem with Palette component - I try to retain model
objects which were selected in Pallete, and update the list od choices
same time (in other word you have one set of available choices takes
2, than press some ajax button and get different set of choices, than
takes 3, so you should have 2+3 selected choices, but every time after
updating Pallete I got empty selected list).
Maybe you can look at the code:

    private void addKeywordPalette() {
        final IChoiceRenderer renderer = new IChoiceRenderer() { /not
important/ };
        keywordPallete = new Palette(Keyword.KEYWORDS, new
Model(selectedKeywordCategories), new PropertyModel(this,
"categories"), renderer, 10, true) {
            protected Recorder newRecorderComponent() {
                final Recorder recorder = super.newRecorderComponent();
                recorder.add(new AjaxFormComponentUpdatingBehavior("onchange") {
                    @Override
                    protected void onUpdate(AjaxRequestTarget
ajaxRequestTarget) {
                        //---- here I save model
                        selectedKeywordCategories =
(ArrayList<KeywordCategory>) keywordPallete.getModelCollection();
                        LOG.info("selectedKeywordCategories: " +
selectedKeywordCategories);
                    }
                });
                return recorder;
            }

        };
        keywordPallete.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true);
        add(keywordPallete);
    }
The button which updates Palette component looks like:

    private void addGetKeywordsButton() {
        final AjaxButton getKeywordsButton = new
AjaxButton(GET_KEYWORDS_BUTTON) {

            @Override
            protected void onSubmit(AjaxRequestTarget
ajaxRequestTarget, Form<?> form) {
                //this updates available choices which and renders
palette component via ajax
                final Set<KeywordCategory> categorySet =
keywordService.someServiceWhichReturnsKeywordAndCategory();
                categories = new ArrayList<KeywordCategory>(categorySet);
                ajaxRequestTarget.addComponent(keywordPallete);
            }
        };
        getKeywordsButton.add(new Image(IMAGE, ADD_IMAGE));
        selectKeywordsForm.add(getKeywordsButton);
    }

What could be wrong that new model isn't used (I use log4j and the
selectedKeywordCategories have selected objects, but Palette doesn't
use them)? Is there made a copy of that array, or something?

-- 
Best regards,
Adrian

http://www.codeappeal.com/

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