You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ian MacLarty <ia...@gmail.com> on 2009/05/18 05:01:52 UTC

shorter input names

Hi,

Is there a way to get wicket to generate shorter name attributes for
input elements?  I have a largish form and most of the data being sent
to the server is the names of the input elements.

Cheers,
Ian.

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


Re: shorter input names

Posted by Ian MacLarty <ia...@gmail.com>.
On Mon, May 18, 2009 at 4:44 PM, Jan Kriesten
<kr...@mail.footprint.de> wrote:
>
> Hi Ian,
>
>> Thanks for that.  For your solution to work it looks like wicket would
>> need to only call getInputName at most once for each input (since
>> subsequent calls would return different names).  Is that how it works?
>
> no, within the trait I override the 'def getInputName' from Wicket with a 'val
> getInputName' - i.e. even when Wicket is calling it more than once it is still
> only evaluated once. That's another nice thing Scala provides... :-)
>

Ah!  Thanks for clarifying that.

Ian.

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


Re: shorter input names

Posted by Jan Kriesten <kr...@mail.footprint.de>.
Hi Ian,

> Thanks for that.  For your solution to work it looks like wicket would
> need to only call getInputName at most once for each input (since
> subsequent calls would return different names).  Is that how it works?

no, within the trait I override the 'def getInputName' from Wicket with a 'val
getInputName' - i.e. even when Wicket is calling it more than once it is still
only evaluated once. That's another nice thing Scala provides... :-)

Best regards, --- Jan.


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


Re: shorter input names

Posted by Ian MacLarty <ia...@gmail.com>.
Hi Jan,

Thanks for that.  For your solution to work it looks like wicket would
need to only call getInputName at most once for each input (since
subsequent calls would return different names).  Is that how it works?

I'm still learning Scala, but so far I find it a compelling alternative to Java.

Cheers,
Ian.

On Mon, May 18, 2009 at 3:10 PM, Jan Kriesten
<kr...@mail.footprint.de> wrote:
>
> Hi Ian,
>
>> Is there a way to get wicket to generate shorter name attributes for
>> input elements?  I have a largish form and most of the data being sent
>> to the server is the names of the input elements.
>
> it is by overriding the method 'getInputName' on every FormComponent and
> returning a stable identifier over requests - though this is pretty horrible
> task to do.
>
> If you're using Scala instead of Java things are getting better, though. I
> defined the following trait (aka implemented interface):
>
> ---
> object FormInputNameId {
>  private var currId = 0
>
>  private def getName = {
>    if( currId==Integer.MAX_VALUE-1 ) currId=1 else currId = currId + 1
>    "fid:" + currId
>  }
> }
>
> trait FormInputNameId[T] extends FormComponent[T] {
>  override val getInputName: String = FormInputNameId.getName
> }
> ---
>
> This trait can be attached to any FormComponent with just something like
>
> val newFormComponent = new TextField( "id" ) with FormInputNameId
>
> The Scala compiler does the rest for you (one of my favorite features of Scala
> to have real reusable code!).
>
> Best regards, --- Jan.
>
> ---------------------------------------------------------------------
> 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: shorter input names

Posted by Jan Kriesten <kr...@mail.footprint.de>.
Hi Ian,

> Is there a way to get wicket to generate shorter name attributes for
> input elements?  I have a largish form and most of the data being sent
> to the server is the names of the input elements.

it is by overriding the method 'getInputName' on every FormComponent and
returning a stable identifier over requests - though this is pretty horrible
task to do.

If you're using Scala instead of Java things are getting better, though. I
defined the following trait (aka implemented interface):

---
object FormInputNameId {
  private var currId = 0

  private def getName = {
    if( currId==Integer.MAX_VALUE-1 ) currId=1 else currId = currId + 1
    "fid:" + currId
  }
}

trait FormInputNameId[T] extends FormComponent[T] {
  override val getInputName: String = FormInputNameId.getName
}
---

This trait can be attached to any FormComponent with just something like

val newFormComponent = new TextField( "id" ) with FormInputNameId

The Scala compiler does the rest for you (one of my favorite features of Scala
to have real reusable code!).

Best regards, --- Jan.

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