Visualize a List as an html select that returns one choice

13 views
Skip to first unread message

Mario Giammarco

unread,
Mar 14, 2018, 5:11:57 PM3/14/18
to invesdwin-platform
Hi again,
I finally have some time for NoWicket.
I have this apparently basic problem but I need a suggestion.
Imagine these situations:
1) a java List that has to be shown as a select and return only one choice
2) a java Enum where I must show in a select only few items of the enum

How can I solve these problems? I have seen your ListAndChoices java class but there you use only the TimeUnit enum and not a List or a filtered Enum

Thanks again for help,
Mario

Edwin Stang

unread,
Mar 14, 2018, 5:30:24 PM3/14/18
to invesdwin-platform
Hi Mario,

for 1): See the tag transformations documentation here at "10.3) Tables & Choices". The "As Select" example shows that transforming the <table> tag in the html into <select> will make it a select box and the content of the values will be the toString() of the list elements. The "Model Code: " part shows how you have to code it for supporting only one selection (which I guess you meant by choice):
--------------
// here we use the choice utility element, it can also return an Iterable, Collection, etc

public
<TypeOfProperty> get<PropertyName>() { ... }
public
void set<PropertyName>(<TypeOfProperty> value) { ... }
public
<TypeOfProperty>[] get<PropertyName>Choice() { ... }
---------------

Though if you mean only one element with your statement of "only one choice", then just return only one value in the "get<PropertyName>Choice()" method. If "null" should be a valid choice for "no selection", just add null to the choice methods return values. You don't have to use an array, any type of Iterable, Collection, Set, List will work as the return type of a Choice utility method.

For 2): See the validation documentation here at "Choice Utility Methods". The example code exactly demonstrates your use case:
---------------
  • public CarBrand[] getBrandChoice() {
  • // filter PlutoNebula because someone said: "Pluto is not a planet!"
  • return new CarBrand[] { CarBrand.LunarIndustries, CarBrand.MarsRoveries };
  • }
---------------

  • Hope this answers your questions fully.


Best regards,

Edwin

Mario Giammarco

unread,
Mar 14, 2018, 6:58:07 PM3/14/18
to invesdwin-platform
Sorry I did not see the get<PropertyName>Choice() { ... } in the code. In my previous experience with an enum type get and set method were enough.
I have already tried with an ...Choice() method that returns an EnumSet and it works perfectly! (And it seems better to use EnumSet with Enum than Array)
Thanks again,
Mario

Mario Giammarco

unread,
Mar 18, 2018, 10:46:49 AM3/18/18
to invesdwin-platform
Hi Edwin,
are you sure that this works?
Enum X...
public X get<PropertyName>() { ... }
public
void set<PropertyName>(X value) { ... }
public
EnumSet<X> get<PropertyName>Choice() { ... }
I have tried also:

public X[] get<PropertyName>Choice() { ... }


It seems to me that when NoWicket sees Enum it does not care about the ...Choice() method
Il giorno mercoledì 14 marzo 2018 22:30:24 UTC+1, Edwin Stang ha scritto:

subes

unread,
Mar 18, 2018, 10:50:32 AM3/18/18
to Mario Giammarco, invesdwin-platform
You are right, even the example in the documentation does not work. Might have been a regression that happenend when i fixed the setvisible last time. I will look into it soon.

Thanks for reporting. :)

--
You received this message because you are subscribed to the Google Groups "invesdwin-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to invesdwin-platform+unsub...@googlegroups.com.
To post to this group, send email to invesdwin-platform@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/invesdwin-platform/d223235a-e81f-4e48-acfe-0b225ed53d39%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

Edwin Stang

unread,
Mar 18, 2018, 2:44:57 PM3/18/18
to invesdwin-platform
I was able to fix this issue: https://github.com/subes/invesdwin-norva/commit/235285e665b1ff0cda979fca1022e99366c728fb

You can try again after updating your snapshot of invesdwin-norva.
Message has been deleted

sub es

unread,
Mar 20, 2018, 6:14:43 AM3/20/18
to Mario Giammarco, invesdwin-platform
Hi Mario,

this is because the value of the field still contains E, this gets merged into the choice since the framework supports this as an initial setting. It would be problematic to handle this otherwise since the wrong data might come from a DB and NoWicket should not change the truth.

You have to fix this inconsistent data inside your model. Either add a validator utility method that checks that the selected value is in the choices. Or maybe better just change the selection to null inside your @Eager methods when such an inconsistency would occur. So the selection gets reset when it is inconsistent.

Best regards,
Edwin

Gesendet: 20. März 2018 10:03 vorm.
Betreff: Re: Visualize a List as an html select that returns one choice

OK, it works!
But I have just found a "strange" behaviour (in my mind it is a bug):

I have  a list of value A B C D E. I choose "E". Then with another @Eager widget I change the list with another one: B C F G.
Unfortunately the chosen value stays there so now I have a wrong list B C E F G to choose.


Il giorno domenica 18 marzo 2018 19:44:57 UTC+1, Edwin Stang ha scritto:
I was able to fix this issue: https://github.com/subes/invesdwin-norva/commit/235285e665b1ff0cda979fca1022e99366c728fb

You can try again after updating your snapshot of invesdwin-norva.

Am Sonntag, 18. März 2018 15:50:32 UTC+1 schrieb subes:
You are right, even the example in the documentation does not work. Might have been a regression that happenend when i fixed the setvisible last time. I will look into it soon.

Thanks for reporting. :)

Am 18.03.2018 3:46 nachm. schrieb "Mario Giammarco" <mgiam...@gmail.com>:
Hi Edwin,
are you sure that this works?
Enum X...
public X get<PropertyName>() { ... }
public void set<PropertyName>(X value) { ... }
public EnumSet<X> get<PropertyName>Choice() { ... }
I have tried also:

public X[] get<PropertyName>Choice() { ... }


It seems to me that when NoWicket sees Enum it does not care about the ...Choice() method
Il giorno mercoledì 14 marzo 2018 22:30:24 UTC+1, Edwin Stang ha scritto:

...

Mario Giammarco

unread,
Mar 20, 2018, 7:44:50 AM3/20/18
to sub es, invesdwin-platform
Ok I will set valid value in the model, I told you FYI.
Mario
Reply all
Reply to author
Forward
0 new messages