Hello,

I'm not sure if the Palette is the best component to support what you are looking for.

Have you considered using a DropDownChoice (which makes finding the selected item trivial) and then using a DataTable to show the 'selected' items?

Here is another approach with the Palette to add in an onclick event to each of the <option>'s that render in the choices component:

1. Palette.newChoicesComponent() creates a Choices<T> object. Choices<T> inherits from AbstractChoice<T> which has this method:
@SuppressWarnings("unchecked")
    @Override
protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)

At the bottom of the method it does:

    buffer.append("\n<option value=\"").append(id).append("\"");

Map<String, String> additionalAttributesMap = getAdditionalAttributes(choice);
            if (additionalAttributesMap != null)
            {
                for (String s : additionalAttributesMap.keySet())
                {
buffer.append(" " + s + "=\"" + additionalAttributesMap.get(s) + "\"");
                }
            }

            buffer.append(">").append(value).append("</option>");


I think this is the place to add in the "onclick" -> AJAX callback.

2. You can setup the Map for each choice by overriding the Palette.getAdditionalAttributesForChoices(T option) method.


I think something like:

new Palette<T>("p", choices, renderer, 5, true) {

            /* (non-Javadoc)
* @see org.apache.wicket.extensions.markup.html.form.palette.Palette#getAdditionalAttributesForChoices(T)
             */
            @Override
protected Map<String, String> getAdditionalAttributesForChoices(
                    T choice) {

Map<String, String>map = new LinkedHashMap<String, String>();

                map.put("onclick", createAjaxCallback(choice));
                return map;
            }

So each option might have its own ajax behaviour or a common one with a URL parameter that represents the clicked option.

When the ajax behaviour is activated you can update your image accordingly.

Regards,

Mike

Unfortunately your suggestion doesnt' work. That is because the "onchange" event only fires if i move an item from the left to the right box or vice versa. what i want is to get a notification when an item is clicked, not when it's moved. I managed to receive this notification by registering a onclick listener with the 'choicesComponent' as shown in the code of my inital mail. My problem is that i want to find out which precise item has been selected and use that information to get hold of the corresponding data object (in my case MediaItem) which contains a property 'filename'. This property i want to feed into an Image component to have it display the corresponding image to the selected item in the Palette.


Am 19.02.2010 14:34, schrieb Michael O'Cleirigh:
getRecorderComponent().add(new FormComponentUpdatingBehavior("onchange"){

protected void onUpdate(AjaxRequestTarget target) {
                            /**
I imagine something like this should do the trick, but i can't find anything like it:

                              Media m = getSelectedItem();
                              imgPanel.setFilname(m.getFileName());
                            */

Iterator selectedChoices = myPalette.getSelectedChoices();

// let the image panel do something with the selected choices.
                            target.addComponent(imgPanel);

});


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to