You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Bruno Borges <br...@gmail.com> on 2011/03/28 02:52:09 UTC

Set all form fields to output markup id automatically

I'm developing a project with Scala + Wicket and I wanted to set that all
form components have their markup id output automatically
(setOutputMarkupId(true)).

Any idea?

Cheers,


Bruno Borges
www.brunoborges.com.br
+55 21 76727099

"The glory of great men should always be
measured by the means they have used to
acquire it."
 - Francois de La Rochefoucauld

Re: Set all form fields to output markup id automatically

Posted by Clint Checketts <ch...@gmail.com>.
If this is specific to a particular form you could use A formcompoment
visitor to iterate over each child and call setOutputMarkupId

On Sunday, March 27, 2011, Bruno Borges <br...@gmail.com> wrote:
> I was looking for a better way (optimized too) to achieve this, considering
> that I'm using Scala.
>
> I admit I'm not an expert on Scala though. :-)
>
>
>
>
> Bruno Borges
> www.brunoborges.com.br
> +55 21 76727099
>
> "The glory of great men should always be
> measured by the means they have used to
> acquire it."
>  - Francois de La Rochefoucauld
>
>
>
> On Sun, Mar 27, 2011 at 9:56 PM, James Carman <ja...@carmanconsulting.com>wrote:
>
>> A quick way to set it by default would be to use a
>> IComponentInitializationListener.
>>
>> On Sun, Mar 27, 2011 at 8:52 PM, Bruno Borges <br...@gmail.com>
>> wrote:
>> > I'm developing a project with Scala + Wicket and I wanted to set that all
>> > form components have their markup id output automatically
>> > (setOutputMarkupId(true)).
>> >
>> > Any idea?
>> >
>> > Cheers,
>> >
>> >
>> > Bruno Borges
>> > www.brunoborges.com.br
>> > +55 21 76727099
>> >
>> > "The glory of great men should always be
>> > measured by the means they have used to
>> > acquire it."
>> >  - Francois de La Rochefoucauld
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Set all form fields to output markup id automatically

Posted by Martin Grigorov <mg...@apache.org>.
On Wed, Mar 30, 2011 at 10:18 PM, Matthew Pennington <
matt@profounddecisions.co.uk> wrote:

> On 30/03/2011 19:44, Martin Grigorov wrote:
>
>> @Bruno: this is interesting question. You should ask it in scala-users@.
>> I
>> think this should be possible with some implicit declaration.
>>
>> @Matthew: Do you use org.apache.wicket.markup.html.form.FormComponentLabel
>> ?
>>
> Going through the app and changing all the non-functioning plain html form
> labels to wicket FormComponentLabels is on my job list to do before it's
> finished!
>
> So yeah, I'm aware of it, but while that component helps reduce the coding
> burden it still means that every single form component now needs a second
> wicket component creating and adding to the form *just to make the html work
> the way you would expect it to work.* That is tedious and it's additional
> plumbing code just for the sake of "making things work" so it strikes me as
> inherently undesirable. Wicket is fantastic at keeping code out of the html,
> it just seems to fly in the face of that ethos that it then forces me to
> write the html labels in the code.
>
> Given that at some point in the processing cycle Wicket must be setting the
> ID of the form component labels, it seems a shame that it can't also detect
> any label that has a for attribute for the id it's altering and update the
> for attribute as well. I'm sure there are many good reasons why that
> wouldn't work but to my inexperienced mind it's a real pity! You'd still
> have the gotcha of discovering that Wicket was changing your ID values, but
> you'd never have to worry about keeping their attendant HTML labels in sync
> because Wicket could just do that for you?
>

I remember someone asked for 'wicket:for' attribute:
<label wicket:for="someId"></label><input wicket:id="someId" .../>

I think it is not hard to implement with IMarkupFilter.
Look for 'wicket:for' in Google/Nabble. Maybe there is some stopper and
that's why it is not already implemented. Otherwise just add a RFE.

>
> Matt
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: Set all form fields to output markup id automatically

Posted by Matthew Pennington <ma...@profounddecisions.co.uk>.
On 30/03/2011 19:44, Martin Grigorov wrote:
> @Bruno: this is interesting question. You should ask it in scala-users@. I
> think this should be possible with some implicit declaration.
>
> @Matthew: Do you use org.apache.wicket.markup.html.form.FormComponentLabel ?
Going through the app and changing all the non-functioning plain html 
form labels to wicket FormComponentLabels is on my job list to do before 
it's finished!

So yeah, I'm aware of it, but while that component helps reduce the 
coding burden it still means that every single form component now needs 
a second wicket component creating and adding to the form *just to make 
the html work the way you would expect it to work.* That is tedious and 
it's additional plumbing code just for the sake of "making things work" 
so it strikes me as inherently undesirable. Wicket is fantastic at 
keeping code out of the html, it just seems to fly in the face of that 
ethos that it then forces me to write the html labels in the code.

Given that at some point in the processing cycle Wicket must be setting 
the ID of the form component labels, it seems a shame that it can't also 
detect any label that has a for attribute for the id it's altering and 
update the for attribute as well. I'm sure there are many good reasons 
why that wouldn't work but to my inexperienced mind it's a real pity! 
You'd still have the gotcha of discovering that Wicket was changing your 
ID values, but you'd never have to worry about keeping their attendant 
HTML labels in sync because Wicket could just do that for you?

Matt


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Set all form fields to output markup id automatically

Posted by Martin Grigorov <mg...@apache.org>.
@Bruno: this is interesting question. You should ask it in scala-users@. I
think this should be possible with some implicit declaration.

@Matthew: Do you use org.apache.wicket.markup.html.form.FormComponentLabel ?

On Tue, Mar 29, 2011 at 11:29 AM, Matthew Pennington <
matt@profounddecisions.co.uk> wrote:

>
>  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).
>>
> The only problem with this argument is that ID fields are a part of the
> HTML syntax, via the "for" attribute of a html label...
>
> I've only recently started using wicket and I think it's *fantastic* but
> the only thing I don't like is the way it changes the ID value of elements.
> I'm sure it's necessary for the way Wicket works and I'm sure it's an issue
> that's been discussed by wicket people before, but it came as a pretty nasty
> surprise to me when I discovered it half way through writing my first
> application (it doesn't seem to me to be very well flagged up for such a
> major issue).
>
> Obviously I'm a newb, but the the only solution I am aware of to the
> problem is to rewrite every label on every form as a wicket component. That
> seems to run against the wicket philosophy of keeping the html and the code
> separate.
>
> I realize nothing in life is perfect, but so far it's the *only* thing
> about wicket that *isn't* perfect... :)
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: Set all form fields to output markup id automatically

Posted by Matthew Pennington <ma...@profounddecisions.co.uk>.
> 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).
The only problem with this argument is that ID fields are a part of the 
HTML syntax, via the "for" attribute of a html label...

I've only recently started using wicket and I think it's *fantastic* but 
the only thing I don't like is the way it changes the ID value of 
elements. I'm sure it's necessary for the way Wicket works and I'm sure 
it's an issue that's been discussed by wicket people before, but it came 
as a pretty nasty surprise to me when I discovered it half way through 
writing my first application (it doesn't seem to me to be very well 
flagged up for such a major issue).

Obviously I'm a newb, but the the only solution I am aware of to the 
problem is to rewrite every label on every form as a wicket component. 
That seems to run against the wicket philosophy of keeping the html and 
the code separate.

I realize nothing in life is perfect, but so far it's the *only* thing 
about wicket that *isn't* perfect... :)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Set all form fields to output markup id automatically

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Sun, Mar 27, 2011 at 11:43 PM, Bruno Borges <br...@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*

Re: Set all form fields to output markup id automatically

Posted by Bruno Borges <br...@gmail.com>.
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.

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?

Bruno Borges
www.brunoborges.com.br
+55 21 76727099

"The glory of great men should always be
measured by the means they have used to
acquire it."
 - Francois de La Rochefoucauld



On Sun, Mar 27, 2011 at 11:15 PM, James Carman
<ja...@carmanconsulting.com>wrote:

> You could use an aspect.  However, the calling of the
> IComponentInstantiationListeners already occurs in-line during the
> constructor execution, so adding your logic (which is merely setting a
> flag) shouldn't be too much overhead, really.  It shouldn't be any
> different (other than pushing a stack frame) than just adding the
> setOutputMarkupId() call into the constructor yourself (which I guess
> you could do by running a locally-modified version of Wicket).
>
> On Sun, Mar 27, 2011 at 9:21 PM, Bruno Borges <br...@gmail.com>
> wrote:
> > I was looking for a better way (optimized too) to achieve this,
> considering
> > that I'm using Scala.
> >
> > I admit I'm not an expert on Scala though. :-)
> >
> >
> >
> >
> > Bruno Borges
> > www.brunoborges.com.br
> > +55 21 76727099
> >
> > "The glory of great men should always be
> > measured by the means they have used to
> > acquire it."
> >  - Francois de La Rochefoucauld
> >
> >
> >
> > On Sun, Mar 27, 2011 at 9:56 PM, James Carman <
> james@carmanconsulting.com>wrote:
> >
> >> A quick way to set it by default would be to use a
> >> IComponentInitializationListener.
> >>
> >> On Sun, Mar 27, 2011 at 8:52 PM, Bruno Borges <br...@gmail.com>
> >> wrote:
> >> > I'm developing a project with Scala + Wicket and I wanted to set that
> all
> >> > form components have their markup id output automatically
> >> > (setOutputMarkupId(true)).
> >> >
> >> > Any idea?
> >> >
> >> > Cheers,
> >> >
> >> >
> >> > Bruno Borges
> >> > www.brunoborges.com.br
> >> > +55 21 76727099
> >> >
> >> > "The glory of great men should always be
> >> > measured by the means they have used to
> >> > acquire it."
> >> >  - Francois de La Rochefoucauld
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Set all form fields to output markup id automatically

Posted by James Carman <ja...@carmanconsulting.com>.
You could use an aspect.  However, the calling of the
IComponentInstantiationListeners already occurs in-line during the
constructor execution, so adding your logic (which is merely setting a
flag) shouldn't be too much overhead, really.  It shouldn't be any
different (other than pushing a stack frame) than just adding the
setOutputMarkupId() call into the constructor yourself (which I guess
you could do by running a locally-modified version of Wicket).

On Sun, Mar 27, 2011 at 9:21 PM, Bruno Borges <br...@gmail.com> wrote:
> I was looking for a better way (optimized too) to achieve this, considering
> that I'm using Scala.
>
> I admit I'm not an expert on Scala though. :-)
>
>
>
>
> Bruno Borges
> www.brunoborges.com.br
> +55 21 76727099
>
> "The glory of great men should always be
> measured by the means they have used to
> acquire it."
>  - Francois de La Rochefoucauld
>
>
>
> On Sun, Mar 27, 2011 at 9:56 PM, James Carman <ja...@carmanconsulting.com>wrote:
>
>> A quick way to set it by default would be to use a
>> IComponentInitializationListener.
>>
>> On Sun, Mar 27, 2011 at 8:52 PM, Bruno Borges <br...@gmail.com>
>> wrote:
>> > I'm developing a project with Scala + Wicket and I wanted to set that all
>> > form components have their markup id output automatically
>> > (setOutputMarkupId(true)).
>> >
>> > Any idea?
>> >
>> > Cheers,
>> >
>> >
>> > Bruno Borges
>> > www.brunoborges.com.br
>> > +55 21 76727099
>> >
>> > "The glory of great men should always be
>> > measured by the means they have used to
>> > acquire it."
>> >  - Francois de La Rochefoucauld
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Set all form fields to output markup id automatically

Posted by Bruno Borges <br...@gmail.com>.
I was looking for a better way (optimized too) to achieve this, considering
that I'm using Scala.

I admit I'm not an expert on Scala though. :-)




Bruno Borges
www.brunoborges.com.br
+55 21 76727099

"The glory of great men should always be
measured by the means they have used to
acquire it."
 - Francois de La Rochefoucauld



On Sun, Mar 27, 2011 at 9:56 PM, James Carman <ja...@carmanconsulting.com>wrote:

> A quick way to set it by default would be to use a
> IComponentInitializationListener.
>
> On Sun, Mar 27, 2011 at 8:52 PM, Bruno Borges <br...@gmail.com>
> wrote:
> > I'm developing a project with Scala + Wicket and I wanted to set that all
> > form components have their markup id output automatically
> > (setOutputMarkupId(true)).
> >
> > Any idea?
> >
> > Cheers,
> >
> >
> > Bruno Borges
> > www.brunoborges.com.br
> > +55 21 76727099
> >
> > "The glory of great men should always be
> > measured by the means they have used to
> > acquire it."
> >  - Francois de La Rochefoucauld
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Set all form fields to output markup id automatically

Posted by James Carman <ja...@carmanconsulting.com>.
A quick way to set it by default would be to use a
IComponentInitializationListener.

On Sun, Mar 27, 2011 at 8:52 PM, Bruno Borges <br...@gmail.com> wrote:
> I'm developing a project with Scala + Wicket and I wanted to set that all
> form components have their markup id output automatically
> (setOutputMarkupId(true)).
>
> Any idea?
>
> Cheers,
>
>
> Bruno Borges
> www.brunoborges.com.br
> +55 21 76727099
>
> "The glory of great men should always be
> measured by the means they have used to
> acquire it."
>  - Francois de La Rochefoucauld
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org