You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "wicket@geofflancaster.com" <wi...@geofflancaster.com> on 2010/03/02 18:03:29 UTC

add attributes to options elements within a palette

Is it possible to add attributes to elements within a palette?

I'd like to assign the "title" attribute so i can have tooltips.

--------------------------------------------------------------------
mail2web.com – What can On Demand Business Solutions do for you?
http://link.mail2web.com/Business/SharePoint



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


Re: add attributes to options elements within a palette

Posted by themugprogrammer <pa...@transport.wa.gov.au>.
this is how i achieve adding tool tips to a wicket palette - basically
overrode the method that conctructs the html for each of the options in the
palette panes which is the onComponentTagBody in the AbstractOptions class.
The code is almost identical to that in AbstractOptions onComponentTagBody
method except that i inject the a title and subsequent value into each of
the options tag.

Tested in both Firefox and IE :) - probably more elegant solutions but it's
one that works.

       conditionCodePalette = new Palette("conditionCodePalette", new
Model(chosenList), new Model(availableList), renderer, 11, false){
          
            @Override
            protected Component newChoicesComponent(){
                return new ConditionCodeChoices("choices", this){
                    private static final long serialVersionUID = 1L;

                    @Override
                    protected Map&lt;String, String&gt;
getAdditionalAttributes(Object choice){
                        return null;
                    }
                };
            }
        };
    }
    
    //overriding the choices class wicket Palette uses so we can inject
    //tool tips into the palettes options.
    private class ConditionCodeChoices extends AbstractOptions{
        
        public ConditionCodeChoices(String id, Palette palette){
           super(id, palette);
        }
        
        @Override
        protected Iterator getOptionsIterator(){
            return getPalette().getUnselectedChoices();
        }
        
        @Override
        protected void onComponentTagBody(MarkupStream markupStream,
ComponentTag openTag){
            final AppendingStringBuffer buffer = new
AppendingStringBuffer(128);
            Iterator options = getOptionsIterator();
            IChoiceRenderer renderer = getPalette().getChoiceRenderer();

            while (options.hasNext()){
               Object choice = options.next();


                final CharSequence id;
                {
                    String value = renderer.getIdValue(choice, 0);

                    if (getEscapeModelStrings()){
                        id = Strings.escapeMarkup(value);
                    }
                    else{
                        id = value;
                    }
                }

                final CharSequence value;
                {
                    Object displayValue = renderer.getDisplayValue(choice);
                    Class<?> displayClass = displayValue == null ? null :
displayValue.getClass();

                    String displayString =
getConverter(displayClass).convertToString(displayValue,
                        getLocale());
                    displayString = getLocalizer().getString(displayString,
this, displayString);

                    if (getEscapeModelStrings()){
                        value = Strings.escapeMarkup(displayString);
                    }
                    else{
                        value = displayString;
                    }
                }

                buffer.append("\n<option title='"+value+"'
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>");

            }

            buffer.append("\n");

            replaceComponentTagBody(markupStream, openTag, buffer);
        }
        
    }

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/add-attributes-to-options-elements-within-a-palette-tp1844870p3551244.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