You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by srm <sr...@schokokeks.org> on 2010/02/18 22:41:42 UTC

(Form) Use two TextFields for one object property?

Hi List,

the following may looked flawed, so I'm happy to hear your suggestions: I have a RegisterNewItem Form where a user can add new Items to a shop/database. I have items of type CD (audiocd) with an attribute PlayTime. I store this value as seconds and calculate the minutes to display at runtime. For adding a new CD, I thought that it would be inconvenient to have the user entering either seconds only, or how to agree on a format like Min:Sec OR Min.Sec etc. My idea now is to provide two textFields, one for the minutes and one for the additional seconds. Now I have no idea how to properly use the model of the textfields and the item-object, to calculate the seconds from both fields at submit time. Any help appreciated.

Please see the code from the Panel below (currently without a textfield for the playtime).

Regards,
Stephan


public class AddCDPanel extends AddItemPanel {
	
	
	/**
	 * auto-generated UID
	 */
	private static final long serialVersionUID = 5390579612171776545L;

	public AddCDPanel(String id) {
		super(id, new CD());

		TextField labelTextField = new TextField("label", new PropertyModel(itemToInsert,"label"));
		FeedbackLabel labelFeedback = new FeedbackLabel("label.feedback", labelTextField);
		addItemForm.add(labelTextField.setRequired(true));
		addItemForm.add(labelFeedback);
		
		TextField artistTextField = new TextField("artist", new PropertyModel(itemToInsert,"artist"));
		FeedbackLabel artistFeedback = new FeedbackLabel("artist.feedback", artistTextField);
		addItemForm.add(artistTextField.setRequired(true));
		addItemForm.add(artistFeedback);
		
	}
}


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


Re: (Form) Use two TextFields for one object property?

Posted by srm <sr...@schokokeks.org>.
Am 18.02.2010 um 23:08 schrieb Igor Vaynberg:

> <snip...snap>
> -igor
> 

Thank you,

I have to look into this as I have never directly worked with the
FormComponentModel.
Every day something new :)

Regards,
Stephan

> On Thu, Feb 18, 2010 at 2:02 PM, srm <sr...@schokokeks.org> wrote:
>> 
>> Am 18.02.2010 um 22:56 schrieb Andrew Lombardi:
>> 
>>> It depends what your domain object looks like, if it's just a simple string you'll have to save the results of those two textfield's in their own model, and then merge them in the onSubmit method.
>>> 
>> 
>> It's a int property. I was thinking about using the onSubmit method but
>> how will this interfere with the PropertyModel setting the value according to
>> TextField's value? Does this happen before onSubmit or after onSubmit?
>> 
>> If that happens before, I surely can overwrite the DO's property (set via the
>> PropertyModel) in the onSubmit().
>> 
>> Regards,
>> Stephan
>> 
>>> On Feb 18, 2010, at 1:41 PM, srm wrote:
>>> 
>>>> Hi List,
>>>> 
>>>> the following may looked flawed, so I'm happy to hear your suggestions: I have a RegisterNewItem Form where a user can add new Items to a shop/database. I have items of type CD (audiocd) with an attribute PlayTime. I store this value as seconds and calculate the minutes to display at runtime. For adding a new CD, I thought that it would be inconvenient to have the user entering either seconds only, or how to agree on a format like Min:Sec OR Min.Sec etc. My idea now is to provide two textFields, one for the minutes and one for the additional seconds. Now I have no idea how to properly use the model of the textfields and the item-object, to calculate the seconds from both fields at submit time. Any help appreciated.
>>>> 
>>>> Please see the code from the Panel below (currently without a textfield for the playtime).
>>>> 
>>>> Regards,
>>>> Stephan
>>>> 
>>>> 
>>>> public class AddCDPanel extends AddItemPanel {
>>>> 
>>>> 
>>>>      /**
>>>>       * auto-generated UID
>>>>       */
>>>>      private static final long serialVersionUID = 5390579612171776545L;
>>>> 
>>>>      public AddCDPanel(String id) {
>>>>              super(id, new CD());
>>>> 
>>>>              TextField labelTextField = new TextField("label", new PropertyModel(itemToInsert,"label"));
>>>>              FeedbackLabel labelFeedback = new FeedbackLabel("label.feedback", labelTextField);
>>>>              addItemForm.add(labelTextField.setRequired(true));
>>>>              addItemForm.add(labelFeedback);
>>>> 
>>>>              TextField artistTextField = new TextField("artist", new PropertyModel(itemToInsert,"artist"));
>>>>              FeedbackLabel artistFeedback = new FeedbackLabel("artist.feedback", artistTextField);
>>>>              addItemForm.add(artistTextField.setRequired(true));
>>>>              addItemForm.add(artistFeedback);
>>>> 
>>>>      }
>>>> }
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>> 
>>> 
>>> 
>>> To our success!
>>> 
>>> Mystic Coders, LLC | Code Magic | www.mysticcoders.com
>>> 
>>> ANDREW LOMBARDI | andrew@mysticcoders.com
>>> 2321 E 4th St. Ste C-128, Santa Ana CA 92705
>>> ofc: 714-816-4488
>>> fax: 714-782-6024
>>> cell: 714-697-8046
>>> linked-in: http://www.linkedin.com/in/andrewlombardi
>>> twitter: http://www.twitter.com/kinabalu
>>> 
>>> Eco-Tip: Printing e-mails is usually a waste.
>>> 
>>> ========================================================
>>> This message is for the named person's use only. You must not, directly or indirectly, use,
>>> disclose, distribute, print, or copy any part of this message if you are not the intended recipient.
>>> ========================================================
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> 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
> 


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


Re: (Form) Use two TextFields for one object property? (SOLVED)

Posted by Eelco Hillenius <ee...@gmail.com>.
> A thousand thanks. Works like a charm.
> Though I don't fully understand how the values are
> passed through the components/models.

It's three components, one parent (that holds the ultimate value) and
two children (that both hold values used to calculate the parent
value.

> convertinput() {
>    int mins=minutes.getconvertedinput();
>    int secs=seconds.getconvertedinput();
>    setconvertedinput(mins*60+secs);
> }

updates the parent (setConvertedInput) with one value that comes from
the minutes and seconds fields.

Eelco

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


Re: (Form) Use two TextFields for one object property? (SOLVED)

Posted by srm <sr...@schokokeks.org>.
> class lengthtextfield extends formcomponentpanel {
> private final textfield minutes;
> private final textfield seconds;
> 
> public lengthtextfield(string id, imodel<integer> model) {
>  super(id, model);
>  minutes=new textfield("min",new model(model.getobject()/60),integer.class);
>  seconds=new textfield("min",new model(model.getobject()%60),integer.class);
> }
> 
> convertinput() {
>    int mins=minutes.getconvertedinput();
>    int secs=seconds.getconvertedinput();
>    setconvertedinput(mins*60+secs);
> }
> }
> 
> <wicket:panel><input type="text" wicket:id="minutes"/>:<input
> type="text" wicket:id="seconds"/></wicket:panel>
> 
> -igor
> 

A thousand thanks. Works like a charm.
Though I don't fully understand how the values are
passed through the components/models.

Regards,
Stephan

> On Thu, Feb 18, 2010 at 2:02 PM, srm <sr...@schokokeks.org> wrote:
>> 
>> Am 18.02.2010 um 22:56 schrieb Andrew Lombardi:
>> 
>>> It depends what your domain object looks like, if it's just a simple string you'll have to save the results of those two textfield's in their own model, and then merge them in the onSubmit method.
>>> 
>> 
>> It's a int property. I was thinking about using the onSubmit method but
>> how will this interfere with the PropertyModel setting the value according to
>> TextField's value? Does this happen before onSubmit or after onSubmit?
>> 
>> If that happens before, I surely can overwrite the DO's property (set via the
>> PropertyModel) in the onSubmit().
>> 
>> Regards,
>> Stephan
>> 
>>> On Feb 18, 2010, at 1:41 PM, srm wrote:
>>> 
>>>> Hi List,
>>>> 
>>>> the following may looked flawed, so I'm happy to hear your suggestions: I have a RegisterNewItem Form where a user can add new Items to a shop/database. I have items of type CD (audiocd) with an attribute PlayTime. I store this value as seconds and calculate the minutes to display at runtime. For adding a new CD, I thought that it would be inconvenient to have the user entering either seconds only, or how to agree on a format like Min:Sec OR Min.Sec etc. My idea now is to provide two textFields, one for the minutes and one for the additional seconds. Now I have no idea how to properly use the model of the textfields and the item-object, to calculate the seconds from both fields at submit time. Any help appreciated.
>>>> 
>>>> Please see the code from the Panel below (currently without a textfield for the playtime).
>>>> 
>>>> Regards,
>>>> Stephan
>>>> 
>>>> 
>>>> public class AddCDPanel extends AddItemPanel {
>>>> 
>>>> 
>>>>      /**
>>>>       * auto-generated UID
>>>>       */
>>>>      private static final long serialVersionUID = 5390579612171776545L;
>>>> 
>>>>      public AddCDPanel(String id) {
>>>>              super(id, new CD());
>>>> 
>>>>              TextField labelTextField = new TextField("label", new PropertyModel(itemToInsert,"label"));
>>>>              FeedbackLabel labelFeedback = new FeedbackLabel("label.feedback", labelTextField);
>>>>              addItemForm.add(labelTextField.setRequired(true));
>>>>              addItemForm.add(labelFeedback);
>>>> 
>>>>              TextField artistTextField = new TextField("artist", new PropertyModel(itemToInsert,"artist"));
>>>>              FeedbackLabel artistFeedback = new FeedbackLabel("artist.feedback", artistTextField);
>>>>              addItemForm.add(artistTextField.setRequired(true));
>>>>              addItemForm.add(artistFeedback);
>>>> 
>>>>      }
>>>> }
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>> 
>>> 
>>> 
>>> To our success!
>>> 
>>> Mystic Coders, LLC | Code Magic | www.mysticcoders.com
>>> 
>>> ANDREW LOMBARDI | andrew@mysticcoders.com
>>> 2321 E 4th St. Ste C-128, Santa Ana CA 92705
>>> ofc: 714-816-4488
>>> fax: 714-782-6024
>>> cell: 714-697-8046
>>> linked-in: http://www.linkedin.com/in/andrewlombardi
>>> twitter: http://www.twitter.com/kinabalu
>>> 
>>> Eco-Tip: Printing e-mails is usually a waste.
>>> 
>>> ========================================================
>>> This message is for the named person's use only. You must not, directly or indirectly, use,
>>> disclose, distribute, print, or copy any part of this message if you are not the intended recipient.
>>> ========================================================
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> 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
> 


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


Re: (Form) Use two TextFields for one object property?

Posted by Igor Vaynberg <ig...@gmail.com>.
class lengthtextfield extends formcomponentpanel {
private final textfield minutes;
private final textfield seconds;

public lengthtextfield(string id, imodel<integer> model) {
  super(id, model);
  minutes=new textfield("min",new model(model.getobject()/60),integer.class);
  seconds=new textfield("min",new model(model.getobject()%60),integer.class);
}

convertinput() {
    int mins=minutes.getconvertedinput();
    int secs=seconds.getconvertedinput();
    setconvertedinput(mins*60+secs);
}
}

<wicket:panel><input type="text" wicket:id="minutes"/>:<input
type="text" wicket:id="seconds"/></wicket:panel>

-igor

On Thu, Feb 18, 2010 at 2:02 PM, srm <sr...@schokokeks.org> wrote:
>
> Am 18.02.2010 um 22:56 schrieb Andrew Lombardi:
>
>> It depends what your domain object looks like, if it's just a simple string you'll have to save the results of those two textfield's in their own model, and then merge them in the onSubmit method.
>>
>
> It's a int property. I was thinking about using the onSubmit method but
> how will this interfere with the PropertyModel setting the value according to
> TextField's value? Does this happen before onSubmit or after onSubmit?
>
> If that happens before, I surely can overwrite the DO's property (set via the
> PropertyModel) in the onSubmit().
>
> Regards,
> Stephan
>
>> On Feb 18, 2010, at 1:41 PM, srm wrote:
>>
>>> Hi List,
>>>
>>> the following may looked flawed, so I'm happy to hear your suggestions: I have a RegisterNewItem Form where a user can add new Items to a shop/database. I have items of type CD (audiocd) with an attribute PlayTime. I store this value as seconds and calculate the minutes to display at runtime. For adding a new CD, I thought that it would be inconvenient to have the user entering either seconds only, or how to agree on a format like Min:Sec OR Min.Sec etc. My idea now is to provide two textFields, one for the minutes and one for the additional seconds. Now I have no idea how to properly use the model of the textfields and the item-object, to calculate the seconds from both fields at submit time. Any help appreciated.
>>>
>>> Please see the code from the Panel below (currently without a textfield for the playtime).
>>>
>>> Regards,
>>> Stephan
>>>
>>>
>>> public class AddCDPanel extends AddItemPanel {
>>>
>>>
>>>      /**
>>>       * auto-generated UID
>>>       */
>>>      private static final long serialVersionUID = 5390579612171776545L;
>>>
>>>      public AddCDPanel(String id) {
>>>              super(id, new CD());
>>>
>>>              TextField labelTextField = new TextField("label", new PropertyModel(itemToInsert,"label"));
>>>              FeedbackLabel labelFeedback = new FeedbackLabel("label.feedback", labelTextField);
>>>              addItemForm.add(labelTextField.setRequired(true));
>>>              addItemForm.add(labelFeedback);
>>>
>>>              TextField artistTextField = new TextField("artist", new PropertyModel(itemToInsert,"artist"));
>>>              FeedbackLabel artistFeedback = new FeedbackLabel("artist.feedback", artistTextField);
>>>              addItemForm.add(artistTextField.setRequired(true));
>>>              addItemForm.add(artistFeedback);
>>>
>>>      }
>>> }
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>
>>
>> To our success!
>>
>> Mystic Coders, LLC | Code Magic | www.mysticcoders.com
>>
>> ANDREW LOMBARDI | andrew@mysticcoders.com
>> 2321 E 4th St. Ste C-128, Santa Ana CA 92705
>> ofc: 714-816-4488
>> fax: 714-782-6024
>> cell: 714-697-8046
>> linked-in: http://www.linkedin.com/in/andrewlombardi
>> twitter: http://www.twitter.com/kinabalu
>>
>> Eco-Tip: Printing e-mails is usually a waste.
>>
>> ========================================================
>> This message is for the named person's use only. You must not, directly or indirectly, use,
>> disclose, distribute, print, or copy any part of this message if you are not the intended recipient.
>> ========================================================
>>
>
>
> ---------------------------------------------------------------------
> 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: (Form) Use two TextFields for one object property?

Posted by Andrew Lombardi <an...@mysticcoders.com>.
class MyForm extends Form {
  private int hour;
  private int second;

  public Form {
 	add(new TextField("hour", new PropertyModel(MyForm.class, "hour")));
 	add(new TextField("second", new PropertyModel(MyForm.class, "second")));
  }

  public void onSubmit() {
	if(!validTime(hour, second)) error("uhh ... hello?");
        
 	// do more stuff
  }

On Feb 18, 2010, at 2:02 PM, srm wrote:

> 
> Am 18.02.2010 um 22:56 schrieb Andrew Lombardi:
> 
>> It depends what your domain object looks like, if it's just a simple string you'll have to save the results of those two textfield's in their own model, and then merge them in the onSubmit method.
>> 
> 
> It's a int property. I was thinking about using the onSubmit method but
> how will this interfere with the PropertyModel setting the value according to
> TextField's value? Does this happen before onSubmit or after onSubmit?
> 
> If that happens before, I surely can overwrite the DO's property (set via the
> PropertyModel) in the onSubmit().
> 
> Regards,
> Stephan
> 
>> On Feb 18, 2010, at 1:41 PM, srm wrote:
>> 
>>> Hi List,
>>> 
>>> the following may looked flawed, so I'm happy to hear your suggestions: I have a RegisterNewItem Form where a user can add new Items to a shop/database. I have items of type CD (audiocd) with an attribute PlayTime. I store this value as seconds and calculate the minutes to display at runtime. For adding a new CD, I thought that it would be inconvenient to have the user entering either seconds only, or how to agree on a format like Min:Sec OR Min.Sec etc. My idea now is to provide two textFields, one for the minutes and one for the additional seconds. Now I have no idea how to properly use the model of the textfields and the item-object, to calculate the seconds from both fields at submit time. Any help appreciated.
>>> 
>>> Please see the code from the Panel below (currently without a textfield for the playtime).
>>> 
>>> Regards,
>>> Stephan
>>> 
>>> 
>>> public class AddCDPanel extends AddItemPanel {
>>> 	
>>> 	
>>> 	/**
>>> 	 * auto-generated UID
>>> 	 */
>>> 	private static final long serialVersionUID = 5390579612171776545L;
>>> 
>>> 	public AddCDPanel(String id) {
>>> 		super(id, new CD());
>>> 
>>> 		TextField labelTextField = new TextField("label", new PropertyModel(itemToInsert,"label"));
>>> 		FeedbackLabel labelFeedback = new FeedbackLabel("label.feedback", labelTextField);
>>> 		addItemForm.add(labelTextField.setRequired(true));
>>> 		addItemForm.add(labelFeedback);
>>> 		
>>> 		TextField artistTextField = new TextField("artist", new PropertyModel(itemToInsert,"artist"));
>>> 		FeedbackLabel artistFeedback = new FeedbackLabel("artist.feedback", artistTextField);
>>> 		addItemForm.add(artistTextField.setRequired(true));
>>> 		addItemForm.add(artistFeedback);
>>> 		
>>> 	}
>>> }
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>> 
>> 
>> 
>> To our success!
>> 
>> Mystic Coders, LLC | Code Magic | www.mysticcoders.com
>> 
>> ANDREW LOMBARDI | andrew@mysticcoders.com
>> 2321 E 4th St. Ste C-128, Santa Ana CA 92705
>> ofc: 714-816-4488
>> fax: 714-782-6024
>> cell: 714-697-8046
>> linked-in: http://www.linkedin.com/in/andrewlombardi
>> twitter: http://www.twitter.com/kinabalu
>> 
>> Eco-Tip: Printing e-mails is usually a waste.
>> 
>> ========================================================
>> This message is for the named person's use only. You must not, directly or indirectly, use,
>> disclose, distribute, print, or copy any part of this message if you are not the intended recipient.
>> ========================================================
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 


To our success!

Mystic Coders, LLC | Code Magic | www.mysticcoders.com

ANDREW LOMBARDI | andrew@mysticcoders.com
2321 E 4th St. Ste C-128, Santa Ana CA 92705
ofc: 714-816-4488
fax: 714-782-6024
cell: 714-697-8046
linked-in: http://www.linkedin.com/in/andrewlombardi
twitter: http://www.twitter.com/kinabalu

Eco-Tip: Printing e-mails is usually a waste.

========================================================
This message is for the named person's use only. You must not, directly or indirectly, use,
 disclose, distribute, print, or copy any part of this message if you are not the intended recipient.
========================================================


Re: (Form) Use two TextFields for one object property?

Posted by srm <sr...@schokokeks.org>.
Am 18.02.2010 um 22:56 schrieb Andrew Lombardi:

> It depends what your domain object looks like, if it's just a simple string you'll have to save the results of those two textfield's in their own model, and then merge them in the onSubmit method.
> 

It's a int property. I was thinking about using the onSubmit method but
how will this interfere with the PropertyModel setting the value according to
TextField's value? Does this happen before onSubmit or after onSubmit?

If that happens before, I surely can overwrite the DO's property (set via the
PropertyModel) in the onSubmit().

Regards,
Stephan

> On Feb 18, 2010, at 1:41 PM, srm wrote:
> 
>> Hi List,
>> 
>> the following may looked flawed, so I'm happy to hear your suggestions: I have a RegisterNewItem Form where a user can add new Items to a shop/database. I have items of type CD (audiocd) with an attribute PlayTime. I store this value as seconds and calculate the minutes to display at runtime. For adding a new CD, I thought that it would be inconvenient to have the user entering either seconds only, or how to agree on a format like Min:Sec OR Min.Sec etc. My idea now is to provide two textFields, one for the minutes and one for the additional seconds. Now I have no idea how to properly use the model of the textfields and the item-object, to calculate the seconds from both fields at submit time. Any help appreciated.
>> 
>> Please see the code from the Panel below (currently without a textfield for the playtime).
>> 
>> Regards,
>> Stephan
>> 
>> 
>> public class AddCDPanel extends AddItemPanel {
>> 	
>> 	
>> 	/**
>> 	 * auto-generated UID
>> 	 */
>> 	private static final long serialVersionUID = 5390579612171776545L;
>> 
>> 	public AddCDPanel(String id) {
>> 		super(id, new CD());
>> 
>> 		TextField labelTextField = new TextField("label", new PropertyModel(itemToInsert,"label"));
>> 		FeedbackLabel labelFeedback = new FeedbackLabel("label.feedback", labelTextField);
>> 		addItemForm.add(labelTextField.setRequired(true));
>> 		addItemForm.add(labelFeedback);
>> 		
>> 		TextField artistTextField = new TextField("artist", new PropertyModel(itemToInsert,"artist"));
>> 		FeedbackLabel artistFeedback = new FeedbackLabel("artist.feedback", artistTextField);
>> 		addItemForm.add(artistTextField.setRequired(true));
>> 		addItemForm.add(artistFeedback);
>> 		
>> 	}
>> }
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
> 
> 
> To our success!
> 
> Mystic Coders, LLC | Code Magic | www.mysticcoders.com
> 
> ANDREW LOMBARDI | andrew@mysticcoders.com
> 2321 E 4th St. Ste C-128, Santa Ana CA 92705
> ofc: 714-816-4488
> fax: 714-782-6024
> cell: 714-697-8046
> linked-in: http://www.linkedin.com/in/andrewlombardi
> twitter: http://www.twitter.com/kinabalu
> 
> Eco-Tip: Printing e-mails is usually a waste.
> 
> ========================================================
> This message is for the named person's use only. You must not, directly or indirectly, use,
> disclose, distribute, print, or copy any part of this message if you are not the intended recipient.
> ========================================================
> 


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


Re: (Form) Use two TextFields for one object property?

Posted by Andrew Lombardi <an...@mysticcoders.com>.
It depends what your domain object looks like, if it's just a simple string you'll have to save the results of those two textfield's in their own model, and then merge them in the onSubmit method.

On Feb 18, 2010, at 1:41 PM, srm wrote:

> Hi List,
> 
> the following may looked flawed, so I'm happy to hear your suggestions: I have a RegisterNewItem Form where a user can add new Items to a shop/database. I have items of type CD (audiocd) with an attribute PlayTime. I store this value as seconds and calculate the minutes to display at runtime. For adding a new CD, I thought that it would be inconvenient to have the user entering either seconds only, or how to agree on a format like Min:Sec OR Min.Sec etc. My idea now is to provide two textFields, one for the minutes and one for the additional seconds. Now I have no idea how to properly use the model of the textfields and the item-object, to calculate the seconds from both fields at submit time. Any help appreciated.
> 
> Please see the code from the Panel below (currently without a textfield for the playtime).
> 
> Regards,
> Stephan
> 
> 
> public class AddCDPanel extends AddItemPanel {
> 	
> 	
> 	/**
> 	 * auto-generated UID
> 	 */
> 	private static final long serialVersionUID = 5390579612171776545L;
> 
> 	public AddCDPanel(String id) {
> 		super(id, new CD());
> 
> 		TextField labelTextField = new TextField("label", new PropertyModel(itemToInsert,"label"));
> 		FeedbackLabel labelFeedback = new FeedbackLabel("label.feedback", labelTextField);
> 		addItemForm.add(labelTextField.setRequired(true));
> 		addItemForm.add(labelFeedback);
> 		
> 		TextField artistTextField = new TextField("artist", new PropertyModel(itemToInsert,"artist"));
> 		FeedbackLabel artistFeedback = new FeedbackLabel("artist.feedback", artistTextField);
> 		addItemForm.add(artistTextField.setRequired(true));
> 		addItemForm.add(artistFeedback);
> 		
> 	}
> }
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 


To our success!

Mystic Coders, LLC | Code Magic | www.mysticcoders.com

ANDREW LOMBARDI | andrew@mysticcoders.com
2321 E 4th St. Ste C-128, Santa Ana CA 92705
ofc: 714-816-4488
fax: 714-782-6024
cell: 714-697-8046
linked-in: http://www.linkedin.com/in/andrewlombardi
twitter: http://www.twitter.com/kinabalu

Eco-Tip: Printing e-mails is usually a waste.

========================================================
This message is for the named person's use only. You must not, directly or indirectly, use,
 disclose, distribute, print, or copy any part of this message if you are not the intended recipient.
========================================================