jakartaee / faces

Jakarta Faces
Other
102 stars 54 forks source link

Faces 4.0: add f:selectItemGroups #1559

Closed BalusC closed 3 years ago

BalusC commented 3 years ago

There's currently no way to declare SelectItemGroup via the view. These have to be manually created in the model.

Proposal: introduce <f:selectItemGroups>

<h:selectOneMenu value="#{bean.selectedProduct}">
    <f:selectItem itemValue="#{null}" />
    <f:selectItemGroups value="#{bean.categories}" var="category" itemLabel="#{category.name}">
        <f:selectItems value="#{category.products}" var="product" itemLabel="#{product.name}" />
    </f:selectItemGroups>
</h:selectOneMenu>

Example implementation: https://showcase.omnifaces.org/components/selectItemGroups

While at it, SelectItemGroup#setSelectItems() currently only accepts a SelectItem[] (pre Java 1.5 approach). Improve it to accept varargs and/or a Collection.

tandraschko commented 3 years ago

+1

BalusC commented 3 years ago

It's now in Faces 4.0, along with an IT :+1:

tandraschko commented 3 years ago

@BalusC i currently implement this feature in MyFaces and im not sure if selectItemGroups should inherit from selectItems i would like to implement it without, it feels a bit hacky - at least how its implemented in Mojarra to wrap getValue.

I think i could also implement with inheritance but without that #getValue overload, we dont have to be backward compatible i think.

tandraschko commented 3 years ago

also i wonder if we shoudlnt add f:selectItemGroup, too?

BalusC commented 3 years ago

Existing UISelectOne/UISelectMany components only support UISelectItems/UISelectItem children. Hence UISelectItemGroups really has to extend from one of these. As the value attribute is an array/iterable, it has to be UISelectItems.

f:selectItemGroup isn't terribly useful, but I think you're right, that it should be added too.

tandraschko commented 3 years ago

yep, or change UISelectOne/Many renderers. Not sure whats better.

Would you like to create a ticket + impl in Mojarra for f:selectItemGroup? I will continue with MyFaces then.

BalusC commented 3 years ago

Changing renderers completely breaks backwards compatibility on component libraries.

I'll add ticket.

BalusC commented 3 years ago

Reopening; itemLabel and itemDisabled attributes are missing in taglib documentation.