You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Matt Jensen <ma...@picasystems.com> on 2007/10/11 04:25:31 UTC
Empty ListChoice
Is there any way to get a ListChoice to render as empty (no options)
when its choice model is empty? By default, "Choose One" appears. If I
set nullValid to true, an empty item appears which is still selectable.
I would like to have the list come up completely empty if the choice
model is empty, and I'd like to do it without creating a new component
(though obviously I will do that if it is what is needed.)
--Matt
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Empty ListChoice
Posted by Swaroop Belur <sw...@gmail.com>.
Try this:
List choices;
if(<empty_condition>){
choices = new ArrayList();
}
else{
choices = ....
}
DropDownChoice d = new DropDownChoice("drop", new
PropertyModel(this,"drop"), choices) {
protected void onComponentTagBody(final MarkupStream
markupStream, final ComponentTag openTag)
{
Object list =getChoices();
if(list instanceof List){
int size = ((List)list).size();
if(size > 0){
super.onComponentTagBody
(markupStream,openTag);
}
else{
replaceComponentTagBody(markupStream, openTag,
new AppendingStringBuffer());
}
}
else{
super.onComponentTagBody(markupStream,openTag);
}
}
};
-swaroop
On 10/11/07, Matt Jensen <ma...@picasystems.com> wrote:
>
>
> Is there any way to get a ListChoice to render as empty (no options)
> when its choice model is empty? By default, "Choose One" appears. If I
> set nullValid to true, an empty item appears which is still selectable.
> I would like to have the list come up completely empty if the choice
> model is empty, and I'd like to do it without creating a new component
> (though obviously I will do that if it is what is needed.)
>
> --Matt
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Empty ListChoice
Posted by Kent Tong <ke...@cpttm.org.mo>.
Matt Jensen-2 wrote:
>
> I believe that doing this causes the list to contain one empty, but
> still selectable, element. That is what I am trying to avoid--I just
> want a plain empty list. I'm starting to wonder whether empty lists are
> considered to not be the "Wicket way," as it seems like it should be
> easier than this. Does ListChoice *intentionally* not allow for an
> empty list? I expected to find something like
> "allowEmpty(boolean)"...but no dice.
>
Have you tried my code? The list has no selectable entry.
-----
--
Kent Tong
Wicket tutorials freely available at http://www.agileskills2.org/EWDW
--
View this message in context: http://www.nabble.com/Empty-ListChoice-tf4604759.html#a13186476
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: Empty ListChoice
Posted by Matt Jensen <ma...@picasystems.com>.
I believe that doing this causes the list to contain one empty, but
still selectable, element. That is what I am trying to avoid--I just
want a plain empty list. I'm starting to wonder whether empty lists are
considered to not be the "Wicket way," as it seems like it should be
easier than this. Does ListChoice *intentionally* not allow for an
empty list? I expected to find something like
"allowEmpty(boolean)"...but no dice.
I could see this being a technical issue since the whole "Choose
One"/empty item thing will cause a request parameter to be submitted
with a form, whereas an empty list would submit no parameter at
all...possibly making it difficult/impossible to determine when a null
must be applied to the model during form processing. Does that have
anything to do with it?
That aside...thanks very much for your response, Kent.
--Matt
Kent Tong wrote:
> Matt Jensen-2 wrote:
>
>> Is there any way to get a ListChoice to render as empty (no options)
>> when its choice model is empty? By default, "Choose One" appears. If I
>> set nullValid to true, an empty item appears which is still selectable.
>> I would like to have the list come up completely empty if the choice
>> model is empty, and I'd like to do it without creating a new component
>> (though obviously I will do that if it is what is needed.)
>>
>>
>
> Try:
>
> ListChoice lc = new ListChoice("lc", ...) {
> protected CharSequence getDefaultChoice(Object selected) {
> return "";
> }
> };
>
> -----
> --
> Kent Tong
> Wicket tutorials freely available at http://www.agileskills2.org/EWDW
>
Re: Empty ListChoice
Posted by Kent Tong <ke...@cpttm.org.mo>.
Matt Jensen-2 wrote:
>
> Is there any way to get a ListChoice to render as empty (no options)
> when its choice model is empty? By default, "Choose One" appears. If I
> set nullValid to true, an empty item appears which is still selectable.
> I would like to have the list come up completely empty if the choice
> model is empty, and I'd like to do it without creating a new component
> (though obviously I will do that if it is what is needed.)
>
Try:
ListChoice lc = new ListChoice("lc", ...) {
protected CharSequence getDefaultChoice(Object selected) {
return "";
}
};
-----
--
Kent Tong
Wicket tutorials freely available at http://www.agileskills2.org/EWDW
--
View this message in context: http://www.nabble.com/Empty-ListChoice-tf4604759.html#a13172939
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