0

I have the following code:

<p:selectManyCheckbox id="contactrole"
                      value="#{contactDetail.contactRoles}"
                      required="#{}"
                      layout="grid"
                      columns="1"
                      disabled="#{!contactDetail.editMode}">
    <f:selectItems value="#{contactDetail.contactRoleItems}"/>
    <p:ajax event="change"
            process="@this"
            update="linked_relationship_detail"
            listener="#{contactDetail.doSomething()}"/>
</p:selectManyCheckbox>

When I select or unselect checkboxes the doSomething() method is executed, except when I unselect the last checkbox. So when there are no checkboxes selected this method is not called. When I set the required attribute to false then the method is called. Until a certain point I understand this logic, but certain components in my view are rendered (or not) depending if there are checkboxes selected or not. So how can I know that there are no checkboxes selected anymore?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Mynca
  • 21
  • 2

1 Answers1

0

if you need to render a component depending on whether or not your p:selectManyCheckbox have any component selected, you can simply do this:

... rendered="#{not empty contactDetail.contactRoles}" ...
David Florez
  • 1,460
  • 2
  • 13
  • 26
  • 1
    You can't just do that on the `p:selectManyCheckbox`... You need to wrap it: http://stackoverflow.com/questions/9010734/why-do-i-need-to-nest-a-component-with-rendered-some-in-another-component-w – Kukeltje Apr 26 '17 at 16:16
  • The same issue still exists with this solution. Because the contactRoles list is not empty (although everything is unselected), I don't get the correct behavior. – Mynca Apr 27 '17 at 07:05