You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by John <mu...@gmail.com> on 2008/08/28 12:34:47 UTC

DropDownChoice - required, one item so preselection?

hi, when using a DropDownChoice is there a way to have the value
preselected if there is only one available and the field is required?

i have looked through the code but cannot see any settings that might
control this, and am stumped trying to work out how to extend the
control in this way.

john

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


Wicket 1.4M3 DateTextField

Posted by Stefan Lindner <li...@visionet.de>.
The DateTextField class reads like

	Class DateTextField {
		private IConverter converter = null;


		public DateTextField(String id, IModel model, String
datePattern)
		{
			super(id, model, Date.class);
			this.datePattern = datePattern;
			this.converter = new SqlDateConverter() {....};
		}

		public IConverter getConverter(Class type)
		{
			if (converter == null)
			{
				return super.getConverter(type);
			}
			else
			{
				return converter;
			}
		}
	}

So it never uses my own Dateconverter since the local veriable
"converter" is always "not null". Of cource, I can override the
getConverter method but that seems not to be the optimal way when I
already registered my own DateConverter in my Application class. What do
think about this?

Stefan



Re: DropDownChoice - required, one item so preselection?

Posted by m_salman <mo...@yahoo.com>.
Thanks so much for yoru response.  I tried a few things from your response
and one solution solved the problem.  I changed the ChoiceRenderer
constructor to include the "id" part. And it worked.

So here is the code:

 		
		form = new Form<IParameterMetaData>(
					"form",
					new CompoundPropertyModel<IParameterMetaData>(parameterMetaData));
		
		form.setOutputMarkupPlaceholderTag(true);
		
		add(form);
	
		
	
		form.add(choiceParameterInOutType = 
					new DropDownChoice<IParameterInOutType>(
						"parameterInOutType",
						listParameterInOutType,
						new ChoiceRenderer<IParameterInOutType>("name", "id")));
		
		choiceParameterInOutType.setOutputMarkupPlaceholderTag(true);
		

Thanks again.



Brill Pappin wrote:
> 
> Set the expected value of the id part in your form model (the model  
> where the dropdown will store the submitted value).
> when the dropdown renders it will use the existing value to preset the  
> choice.
> 
> In your code below, it looks like the model is created new every time.  
> for this to work, the model has to have the preselected choice set on  
> it, or it need to survive renders.
> Your ChoiceRenderer simply tells the component which part is id and  
> which is display.
> 
> - Brill Pappin
> 
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice---required%2C-one-item-so-preselection--tp19198000p23890566.html
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: DropDownChoice - required, one item so preselection?

Posted by Brill Pappin <br...@pappin.ca>.
Set the expected value of the id part in your form model (the model  
where the dropdown will store the submitted value).
when the dropdown renders it will use the existing value to preset the  
choice.

In your code below, it looks like the model is created new every time.  
for this to work, the model has to have the preselected choice set on  
it, or it need to survive renders.
Your ChoiceRenderer simply tells the component which part is id and  
which is display.

- Brill Pappin


On 2-Jun-09, at 6:54 PM, m_salman wrote:

>
> I have set the model. But I still don't see it preselected when the
> dropDownChoice object is displayed:
>
> 		form.add(new DropDownChoice<IParameterInOutType>(
> 						"parameterInOutType",
> 						new
> CompoundPropertyModel 
> <IParameterInOutType>(parameterMetaData.getParameterInOutType()),
> 						listParameterInOutType,
> 						new ChoiceRenderer<IParameterInOutType>("name")));
>
>
>
> Am I missing some thing?  DO I need to do something in the html?
>
> Thanks.
>
>
>
>
>
> Nino.Martinez wrote:
>>
>> just set the model to what you want selected:)
>>
>> John wrote:
>>> hi, when using a DropDownChoice is there a way to have the value
>>> preselected if there is only one available and the field is  
>>> required?
>>>
>>> i have looked through the code but cannot see any settings that  
>>> might
>>> control this, and am stumped trying to work out how to extend the
>>> control in this way.
>>>
>>> john
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>> -- 
>> -Wicket for love
>>
>> Nino Martinez Wael
>> Java Specialist @ Jayway DK
>> http://www.jayway.dk
>> +45 2936 7684
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/DropDownChoice---required%2C-one-item-so-preselection--tp19198000p23842503.html
> 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: DropDownChoice - required, one item so preselection?

Posted by m_salman <mo...@yahoo.com>.
I have set the model. But I still don't see it preselected when the
dropDownChoice object is displayed:

		form.add(new DropDownChoice<IParameterInOutType>(
						"parameterInOutType",
						new
CompoundPropertyModel<IParameterInOutType>(parameterMetaData.getParameterInOutType()),
						listParameterInOutType,
						new ChoiceRenderer<IParameterInOutType>("name")));



Am I missing some thing?  DO I need to do something in the html?

Thanks.





Nino.Martinez wrote:
> 
> just set the model to what you want selected:)
> 
> John wrote:
>> hi, when using a DropDownChoice is there a way to have the value
>> preselected if there is only one available and the field is required?
>>
>> i have looked through the code but cannot see any settings that might
>> control this, and am stumped trying to work out how to extend the
>> control in this way.
>>
>> john
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>   
> 
> -- 
> -Wicket for love
> 
> Nino Martinez Wael
> Java Specialist @ Jayway DK
> http://www.jayway.dk
> +45 2936 7684
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DropDownChoice---required%2C-one-item-so-preselection--tp19198000p23842503.html
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: DropDownChoice - required, one item so preselection?

Posted by John <mu...@gmail.com>.
hi, the items in the DropDownChoice come from another part of the
application.  someone could enter the page with the DropDownChoice on
it when there are three items in it but another user could delete two
of them and the first user could refresh the page and ideally it would
automatically select the only available option

when there is functionality that looks like it should be part of the
fabric of the application somewhere in a model or in a component but
i'm putting it on the page somewhere that will not activate in all
situations... i get the feeling that i'm doing something wrong. maybe
i am not

i will put the code in the constructor and will revisit this at a later date

thanks for all your responses

john


On Thu, Aug 28, 2008 at 2:13 PM, James Carman
<ja...@carmanconsulting.com> wrote:
> How are the items in the DDC changing?
>
> On Thu, Aug 28, 2008 at 9:02 AM, John <mu...@gmail.com> wrote:
>> hi, thanks for your response.  i know i can set the model manually at
>> point of component creation but as i understand it that code won't be
>> executed if the page is redisplayed and the items in the
>> DropDownChoice have changed and it would need to be duplicated each
>> time i need this functionality.  it seems to me that this
>> functionality should be in my custom extension of the component.  i
>> could put such code in the constructor of my component but again it
>> would not be executed when the component is redisplayed.
>>
>> apologies... maybe i have got the wrong end of the stick here...
>>
>> maybe should this code only be executed once, and not again?
>>
>> john
>>
>>
>>
>> On Thu, Aug 28, 2008 at 11:37 AM, Nino Saturnino Martinez Vazquez Wael
>> <ni...@jayway.dk> wrote:
>>> just set the model to what you want selected:)
>>>
>>> John wrote:
>>>>
>>>> hi, when using a DropDownChoice is there a way to have the value
>>>> preselected if there is only one available and the field is required?
>>>>
>>>> i have looked through the code but cannot see any settings that might
>>>> control this, and am stumped trying to work out how to extend the
>>>> control in this way.
>>>>
>>>> john

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


Re: DropDownChoice - required, one item so preselection?

Posted by James Carman <ja...@carmanconsulting.com>.
How are the items in the DDC changing?

On Thu, Aug 28, 2008 at 9:02 AM, John <mu...@gmail.com> wrote:
> hi, thanks for your response.  i know i can set the model manually at
> point of component creation but as i understand it that code won't be
> executed if the page is redisplayed and the items in the
> DropDownChoice have changed and it would need to be duplicated each
> time i need this functionality.  it seems to me that this
> functionality should be in my custom extension of the component.  i
> could put such code in the constructor of my component but again it
> would not be executed when the component is redisplayed.
>
> apologies... maybe i have got the wrong end of the stick here...
>
> maybe should this code only be executed once, and not again?
>
> john
>
>
>
> On Thu, Aug 28, 2008 at 11:37 AM, Nino Saturnino Martinez Vazquez Wael
> <ni...@jayway.dk> wrote:
>> just set the model to what you want selected:)
>>
>> John wrote:
>>>
>>> hi, when using a DropDownChoice is there a way to have the value
>>> preselected if there is only one available and the field is required?
>>>
>>> i have looked through the code but cannot see any settings that might
>>> control this, and am stumped trying to work out how to extend the
>>> control in this way.
>>>
>>> john
>
> ---------------------------------------------------------------------
> 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: DropDownChoice - required, one item so preselection?

Posted by John <mu...@gmail.com>.
hi, thanks for your response.  i know i can set the model manually at
point of component creation but as i understand it that code won't be
executed if the page is redisplayed and the items in the
DropDownChoice have changed and it would need to be duplicated each
time i need this functionality.  it seems to me that this
functionality should be in my custom extension of the component.  i
could put such code in the constructor of my component but again it
would not be executed when the component is redisplayed.

apologies... maybe i have got the wrong end of the stick here...

maybe should this code only be executed once, and not again?

john



On Thu, Aug 28, 2008 at 11:37 AM, Nino Saturnino Martinez Vazquez Wael
<ni...@jayway.dk> wrote:
> just set the model to what you want selected:)
>
> John wrote:
>>
>> hi, when using a DropDownChoice is there a way to have the value
>> preselected if there is only one available and the field is required?
>>
>> i have looked through the code but cannot see any settings that might
>> control this, and am stumped trying to work out how to extend the
>> control in this way.
>>
>> john

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


Re: DropDownChoice - required, one item so preselection?

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
just set the model to what you want selected:)

John wrote:
> hi, when using a DropDownChoice is there a way to have the value
> preselected if there is only one available and the field is required?
>
> i have looked through the code but cannot see any settings that might
> control this, and am stumped trying to work out how to extend the
> control in this way.
>
> john
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>   

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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


Re: DropDownChoice - required, one item so preselection?

Posted by James Carman <ja...@carmanconsulting.com>.
The DDC is bound to a model, so make sure that the model has that
value (if it's bound to a property on an object, set that property to
what you want pre-selected).

On Thu, Aug 28, 2008 at 6:34 AM, John <mu...@gmail.com> wrote:
> hi, when using a DropDownChoice is there a way to have the value
> preselected if there is only one available and the field is required?
>
> i have looked through the code but cannot see any settings that might
> control this, and am stumped trying to work out how to extend the
> control in this way.
>
> john
>
> ---------------------------------------------------------------------
> 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