yes checking for enabled there is fine
(thats why wicket also does for setting the enabled attribute)

johan



On 10/27/07, nico <[EMAIL PROTECTED]> wrote:
>
> Johan Compagner schrieb:
> > why aren't you subclassing button and have a button that has that
> > modifier and use that one on all your forms?
> >
> doh! thanks, i haven't seen that obvious possibility
> ..is it right, to check wether the button is enabled in the
> onComponentTag event before putting the attribute?
> to use the class simply add it by calling this.add(new
> I18nButton("button.id", new Model("buttontxt.key")); from
> within your component.
>
> import org.apache.wicket.Component;
> import org.apache.wicket.behavior.AbstractBehavior;
> import org.apache.wicket.markup.ComponentTag;
> import org.apache.wicket.markup.html.form.Button;
> import org.apache.wicket.model.IModel;
>
> /**
> * Internationalized button class
> */
> public class I18nButton extends Button {
>
>    /**
>     * The attribute modifier for i18n
>     */
>    private class I18nAttributeModifier extends AbstractBehavior {
>
>        private String attribute;
>        private String value;
>
>        public I18nAttributeModifier(String attribute, String value) {
>            this.attribute = attribute;
>            this.value = value;
>        }
>
>        /**
>         * @see
> org.apache.wicket.behavior.AbstractBehavior#onComponentTag(
> org.apache.wicket.Component,
>         *      org.apache.wicket.markup.ComponentTag)
>         */
>        public void onComponentTag(final Component component, final
> ComponentTag tag)
>        {
>            if (isEnabled(component))
>            {
>                tag.getAttributes().put(attribute, getString(value));
>            }
>        }
>    }
>
>    public I18nButton(final String id, final IModel model) {
>        super(id, model);
>        if (model.getObject() instanceof String) {
>            String key = (String)model.getObject();
>            add(this.new I18nAttributeModifier("value", key));
>        } else
>            new OperationNotSupportedException("Model needs to contain
> an object of type String.");
>    }
> }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to