You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by minusquampefekt <mi...@yahoo.de> on 2010/02/19 13:32:52 UTC

Palette: access selected/clicked item

hi fellow wicket users,

i have some trouble to access the currently selected item of a Palette 
component. By selected i mean the item which is highlighted if  a user 
clicks on any of the items within the palette. i need that access 
because i want to update an Image component which renders an image which 
reflects the selected item

here is the (simplified) piece of code i use to get notified if the 
palette is clicked:

final Palette palette = new Palette("palette", mediaModel, paletteModel 
, renderer, 10, true) {
                 private static final long serialVersionUID = 
-5683120408447757525L;

                 @Override
                 protected void onBeforeRender() {
                     super.onBeforeRender();

                     getChoicesComponent().add(new 
AjaxFormComponentUpdatingBehavior("onclick") {
                         private static final long serialVersionUID = 
-6216894553871444828L;

                         @Override
                         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());
                             */
                             target.addComponent(imgPanel);
                         }
                     });
                 }
             };


max


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


Re: Palette: access selected/clicked item

Posted by minusquampefekt <mi...@yahoo.de>.
thanks a lot mike!



Am 19.02.2010 22:12, schrieb Michael O'Cleirigh:
> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


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


Re: Palette: access selected/clicked item

Posted by Michael O'Cleirigh <mi...@rivulet.ca>.
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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


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


Re: Palette: access selected/clicked item

Posted by minusquampefekt <mi...@yahoo.de>.
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Palette: access selected/clicked item

Posted by Michael O'Cleirigh <mi...@rivulet.ca>.
Hello,

Inside the Palette there is a Recorder<T> which is basically a 
customized HiddenField that holds the id of each selected element.


/**
      * Returns recorder component. Recorder component is a form 
component used to track the
      * selection of the palette. It receives <code>onchange</code> 
javascript event whenever a
      * change in selection occurs.
      *
      * @return recorder component
      */
     public final Recorder<T> getRecorderComponent()
     {
         return recorderComponent;
     }

So myPalette.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);

});

This should give you what you want.

Regards,

Mike
> i have some trouble to access the currently selected item of a Palette 
> component. By selected i mean the item which is highlighted if  a user 
> clicks on any of the items within the palette. i need that access 
> because i want to update an Image component which renders an image 
> which reflects the selected item
>
> here is the (simplified) piece of code i use to get notified if the 
> palette is clicked:
>
> final Palette palette = new Palette("palette", mediaModel, 
> paletteModel , renderer, 10, true) {
>                 private static final long serialVersionUID = 
> -5683120408447757525L;
>
>                 @Override
>                 protected void onBeforeRender() {
>                     super.onBeforeRender();
>
>                     getChoicesComponent().add(new 
> AjaxFormComponentUpdatingBehavior("onclick") {
>                         private static final long serialVersionUID = 
> -6216894553871444828L;
>
>                         @Override
>                         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());
>                             */
>                             target.addComponent(imgPanel);
>                         }
>                     });
>                 }
>             };
>
>
> max
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


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


Re: Palette: access selected/clicked item

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

I've answered you at https://stackoverflow.com/a/44812495/497381

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Wed, Jun 28, 2017 at 10:12 PM, anin82 <ni...@gmail.com> wrote:

> Hi,
>
> were you able to find a solution for this issue? I have a similar problem
> where I would like to access the selected item in the left panel before it
> is moved to the right side. The ultimate objective is to have another
> button
> along with the custom Palette buttons that I can use to perform action on
> after selecting it from the list.
> Thanks in advance.
>
> --
> View this message in context: http://apache-wicket.1842946.n
> 4.nabble.com/Palette-access-selected-clicked-item-tp1892875p4678161.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Palette: access selected/clicked item

Posted by anin82 <ni...@gmail.com>.
Hi,

were you able to find a solution for this issue? I have a similar problem
where I would like to access the selected item in the left panel before it
is moved to the right side. The ultimate objective is to have another button
along with the custom Palette buttons that I can use to perform action on
after selecting it from the list.
Thanks in advance. 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Palette-access-selected-clicked-item-tp1892875p4678161.html
Sent from the Users forum mailing list archive at Nabble.com.

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