-1

I've got a data table with 17 attributes. The table can be rendered in two modes: with row selection enabled and without it.

<p:dataTable selection="#{isDefaultSelectionMode ? null : widget.selected}" />

It doesn't work because selection expects a reference to a property to be able to set/get it.

  1. I could create a dummy property widget.ignored and it's going to work. I don't like this for the obvious reason.

    <p:dataTable selection="#{isDefaultSelectionMode ? widget.ignored : widget.selected}" />
    
  2. I could split the table into two separate templates. I would exclude selection from one and duplicate 16 other attributes. It's not a good one, either.

I am looking for an elegant solution to either make the attribute optional (not to render it under some condition) or to avoid defining a dummy property.

I am new to JSF and PrimeFaces, feel free to correct. Any help would be welcomed.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
  • Something like this: https://stackoverflow.com/questions/5712364/jsf-2-0-dynamic-attributes-without-creating-new-components ? – Kukeltje Apr 08 '19 at 13:41
  • It is not **just** about custom attributes. It is about **dynamic** attributes as well. Try if it works, it might not, but it might... I never needed it and have currently no time to try. https://stackoverflow.com/questions/18231951/what-is-fattribute-used-for-in-this-example – Kukeltje Apr 08 '19 at 21:00
  • But then in combination with a `c:if` around it... https://stackoverflow.com/questions/33474926/how-not-to-set-an-attribute-of-a-component-inside-a-composite-component-if-it-is/33475114#33475114 – Kukeltje Apr 08 '19 at 21:08
  • Correct, that is why I removed that and just referenced the c:if like used in the referred question) – Kukeltje Apr 09 '19 at 14:11
  • You can create an answer yourself if you like, just refer to the other Q/A as well and I'll upvote yours ;-) – Kukeltje Apr 09 '19 at 14:14

1 Answers1

1

Fortunately, I didn't have to apply any of my terrible workarounds.

As suggested by @Kukeltje (thank you) and the links he provided, I defined the attribute conditionally

<c:if test="#{isDefaultSelectionMode}">
    <f:attribute name="selection" value="#{widget.selected}"/>
</c:if>

For more details, visit these questions:

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142