COOL!!! :)

Jeremy Thomerson wrote:
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.

--
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to