On Sun, Mar 27, 2011 at 11:43 PM, Bruno Borges <bruno.bor...@gmail.com>wrote:

> For now, I simply did this:
>
>      object autoMarkupId extends IComponentInstantiationListener {
>         def onInstantiation(component: Component) {
>            if (component.isInstanceOf[FormComponent[_]]) {
>               component.setOutputMarkupId(true)
>               component.setMarkupId(component.getId())
>            }
>         }
>      }
>
>      getComponentInstantiationListeners().add(autoMarkupId);
>
> I've been playing with this technic, of having all Form components
> outputing
> their ids as is. Of course, this is application-specific, and Wicket should
> not take this to its core.
>

I personally would suggest *not* having that second line
"component.setMarkupId(component.getId())" there.  Let Wicket generate the
IDs for you so that they're all unique on a page.  Your approach above
breaks using two EmailAddressTextField (fake example class) components on
the same page.

Designers should use css class to style.  An occasional ID that isn't
attached to a Wicket component can also help (div surrounding content
section, etc).

But it seems that improves development time, when the web designer codes CSS
> and HTML with the application running on his machine. No more code like
>
>  wicket:id="foo" id="foo"
>
> Now, I'm considering to implement a different way to define a Wicket
> component in the HTML:
>
>   <div id="w_foo">
>   </div>
>
>  add(new WebMarkupContainer("foo"));
>
> What you guys think of this?
>

This approach of coding in the markup and automagic generation of components
has been discussed numerous times.  It's not in line with Wicket's core
principles, so we won't add it, but we've made it easy enough to add it to
your own app.  However, watch out: the example you give above is useless -
it just creates a markup container.  So, the next request will be "let me
configure that component by adding attributes in the markup; maybe I can
have 'property='firstName'' to show that this should be a label that
displays the first name".  Now you're programming in markup - you might as
well use PHP!  :P

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*

Reply via email to