You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ricardo Mayerhofer <ri...@gmail.com> on 2008/12/12 14:15:33 UTC
Re: Wicket and CoC
Very nice indeed. Based on your example I build my own:
public class ConventionalComponentResolver implements IComponentResolver {
public boolean resolve(MarkupContainer markupContainer, MarkupStream
markupStream, ComponentTag componentTag) {
CharSequence wicketId = componentTag.getString("wicket:id");
if ( "submitLink".equals(wicketId) ) {
markupContainer.autoAdd(new SubmitLink( "submitLink" ),
markupStream);
return true;
}
....
Nino.Martinez wrote:
>
> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Wicket-and-CoC-tp20706881p20975432.html
Sent from the Wicket - User 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