You can do exactly what you asked in less than 40 lines of code - and not be
bound to the class name in the HTML (which you shouldn't do).  Here's how:

IN YOUR APPLICATION CLASS:

    @Override
    protected void init() {
        super.init();
        registerConventionalComponent("feedbackPanel", FeedbackPanel.class);
        registerConventionalComponent("submitLink", SubmitLink.class);
        registerConventionalComponent("submitButton", Button.class);
    }
    private void registerConventionalComponent(String id, Class<? extends
Component> clazz) {
        getPageSettings().addComponentResolver(new
ConventionalComponentResolver(id, clazz));
    }
    private static final class ConventionalComponentResolver implements
IComponentResolver {
        private static final long serialVersionUID = 1L;
        private final String mID;
        private final Class<? extends Component> mComponentClass;

        public ConventionalComponentResolver(String id, Class<? extends
Component> clazz) {
            mID = id;
            mComponentClass = clazz;
        }
        public boolean resolve(MarkupContainer container, MarkupStream
markupStream, ComponentTag tag) {
            CharSequence wicketId = tag.getString("wicket:id");
            if (mID.equals(wicketId)) {
                container.autoAdd(createInstance(), markupStream);
                // Yes, we handled the tag
                return true;
            }
            // We were not able to handle the tag
            return false;
        }
        private Component createInstance() {
            try {
                return
mComponentClass.getConstructor(String.class).newInstance(mID);
            } catch (Exception ex) {
                throw new WicketRuntimeException("Error creating component
instance of class: " + mComponentClass.getName(), ex);
            }
        }
    }
NIFTY!!  I hadn't written any IComponentResolver's before - but wanted to
try it.  Wicket is AWESOME!!  It makes it so easy to customize the framework
to YOUR needs without imposing one person's ideas on another person.
-- 
Jeremy Thomerson
http://www.wickettraining.com

On Thu, Nov 27, 2008 at 2:05 AM, Alex Objelean
<[EMAIL PROTECTED]>wrote:

>
> Using AutoComponentResolver, you can add a feedback panel like this:
> <wicket:component
> class="org.apache.wicket.markup.html.panel.FeedbackPanel"/>
>
>
>
>
> Ricardo Mayerhofer wrote:
> >
> > I started to use wicket some time ago, and I'm really enjoying it. Best
> > framework ever.
> > But I've some suggestions.
> > I think wicket could be better if it had less boiler plate code. This
> > could be reduced by using CoC.
> > Take the FeedBackPanel for example, you always have to add the component
> > on the web page, even if no special handling is requires (which is almost
> > the case).
> > Wicket could have some reserved ids, so if I add a markup with id
> > feedbackPanel, a feedbackpanel component is automatically added to that
> > page.
> > Another example is SubmitLink component. No special handling required,
> but
> > for wicket sake the developer must add it on the java the page.
> >
>
> --
> View this message in context:
> http://www.nabble.com/Wicket-and-CoC-tp20706881p20714917.html
>  Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to