You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Pills <pi...@hmcrecord.ch> on 2007/11/28 11:34:10 UTC

Use a custom converter (IntegerToMyClass)

Hello,

I've a textfield that accept an integer (it represents a foreign key). 

I would like it to be converted as an instance of MyClass before updating my
model.

But I don't know how to specifiy a custom converter for a field...

I would like to implement this converter like this:
<code>
Integer i = (Integer) myfield.getValue();
MyClass m = new MyClassDAO().findById(i);
return m;
</code>

Is it possible?
-- 
View this message in context: http://www.nabble.com/Use-a-custom-converter-%28IntegerToMyClass%29-tf4887609.html#a13989621
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


Re: Use a custom converter (IntegerToMyClass)

Posted by Johan Compagner <jc...@gmail.com>.
It seems to me that you just want a Label (with the persons name)
and a button (that pops up a person search)

Because what does that text field really do?
can somebody really type something in it?


On Nov 28, 2007 8:12 PM, Sébastien Piller <pi...@hmcrecord.ch> wrote:

> Johan Compagner a écrit :
> > Are you using wicket 1.3?
> > Then you can add a person convertor (toObject/toString)
> > But a txt field for the complete person that sounds very strange.
> > What do you want to edit?? Do yu want to  choose a person? Or do you
> > want to edit a preoperty of that person?
> >
>
>
> Yes, I'm using 1.3 rc1.
>
> In my case, I need a text field to store a foreign key referencing a
> person (assign a person to a record of another table). I don't use
> dropdownchoice or else because I've got a large number of people in my
> table, and a ddc with thousands of options may not be usable.
>
> In place, I use a textfield and a link on its right, which allows the
> user to search a person in a popup (on a pagined list) or manually input
> the Person ID if already known.
>
> I'm using Hibernate too. On the form submit, the integer foreign key
> need to be converted to an instance of Person (and thats why I need to
> use a custom converter).
>
> I don't know if there is a better way to fit my needs, but this one works
> ;)
>

Re: Use a custom converter (IntegerToMyClass)

Posted by Johan Compagner <jc...@gmail.com>.
Are you using wicket 1.3?
Then you can add a person convertor (toObject/toString)
But a txt field for the complete person that sounds very strange.
What do you want to edit?? Do yu want to  choose a person? Or do you
want to edit a preoperty of that person?



On 11/28/07, Pills <pi...@hmcrecord.ch> wrote:
>
>
> Johan Compagner wrote:
> >
> > Converters are (in 1.3 especially) are String -> X (or X -> String)
> >
> > so browser string input converted to a model value.
> > So how do you already get an integer? Because that should be converted by
> > a
> > converter already.
> >
> > johan
> >
>
> Well, I wrote this code:
> person = new TextField("person", new PropertyModel(formTarget, "person"),
> Integer.class)
>
> So it accepts only integers... but I guess it's wrong, I'd better to write
> this
> person = new TextField("person", new PropertyModel(formTarget, "people"),
> Person.class)
>
> But in that case, I don't know how to convert the browser string to a
> model's object and the model's object to a string (representing it's foreign
> key). I've overriden the field's "convertInput" method, so now it's able to
> convert string -> Person (I don't know if it's the right way). But for the
> other conversion I don't know what to override....
>
>
> Thank you for your help ;)
> --
> View this message in context:
> http://www.nabble.com/Use-a-custom-converter-%28IntegerToMyClass%29-tf4887609.html#a13991029
> 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
>
>

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


Re: Use a custom converter (IntegerToMyClass)

Posted by Pills <pi...@hmcrecord.ch>.
Sorry, I made some big mistakes (again). 
http://cwiki.apache.org/WICKET/using-custom-converters.html#Usingcustomconverters-Usingcustomconverters
This document  helped me very much ;)
-- 
View this message in context: http://www.nabble.com/Use-a-custom-converter-%28IntegerToMyClass%29-tf4887609.html#a13993032
Sent from the Wicket - User mailing list archive at Nabble.com.

Re: Use a custom converter (IntegerToMyClass)

Posted by Pills <pi...@hmcrecord.ch>.

Johan Compagner wrote:
> 
> Converters are (in 1.3 especially) are String -> X (or X -> String)
> 
> so browser string input converted to a model value.
> So how do you already get an integer? Because that should be converted by
> a
> converter already.
> 
> johan
> 

Well, I wrote this code:
person = new TextField("person", new PropertyModel(formTarget, "person"),
Integer.class)

So it accepts only integers... but I guess it's wrong, I'd better to write
this
person = new TextField("person", new PropertyModel(formTarget, "people"),
Person.class)

But in that case, I don't know how to convert the browser string to a
model's object and the model's object to a string (representing it's foreign
key). I've overriden the field's "convertInput" method, so now it's able to
convert string -> Person (I don't know if it's the right way). But for the
other conversion I don't know what to override....


Thank you for your help ;) 
-- 
View this message in context: http://www.nabble.com/Use-a-custom-converter-%28IntegerToMyClass%29-tf4887609.html#a13991029
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


Re: Use a custom converter (IntegerToMyClass)

Posted by Johan Compagner <jc...@gmail.com>.
Converters are (in 1.3 especially) are String -> X (or X -> String)

so browser string input converted to a model value.
So how do you already get an integer? Because that should be converted by a
converter already.

johan



On Nov 28, 2007 11:34 AM, Pills <pi...@hmcrecord.ch> wrote:

>
> Hello,
>
> I've a textfield that accept an integer (it represents a foreign key).
>
> I would like it to be converted as an instance of MyClass before updating
> my
> model.
>
> But I don't know how to specifiy a custom converter for a field...
>
> I would like to implement this converter like this:
> <code>
> Integer i = (Integer) myfield.getValue();
> MyClass m = new MyClassDAO().findById(i);
> return m;
> </code>
>
> Is it possible?
> --
> View this message in context:
> http://www.nabble.com/Use-a-custom-converter-%28IntegerToMyClass%29-tf4887609.html#a13989621
> Sent from the Wicket - User mailing list archive at Nabble.com<http://nabble.com/>
> .
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>