2

I have primefaces selectManyMenu and I want to select multiple items without using ctrlkey or something. Is there any way to do this ? I found richfaces multipleKeyboardFree for this, but in primefaces I have not found unfortunately

Richfaces example : http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=extendedDataTable&sample=exTableSelection&skin=blueSky

Primefaces works only clicked in checkbox or clicked with ctrl, I don't want this. I want to click anywhere on row and it must work like richfaces example

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
H.Celik
  • 25
  • 4
  • 1
    See the advanced example: http://www.primefaces.org/showcase/ui/input/manyMenu.xhtml – Jasper de Vries Sep 05 '16 at 11:39
  • Yes I saw advanced already, but it works only clicked in checkbox, I don't want this. I want to click everywhere on row and it must work like richfaces example. – H.Celik Sep 05 '16 at 13:06
  • 1
    @h.celik Please mention specific reqirements like that initially with your question next time and also update your question in this. Other user may not read every comment and do not know about this additional requirement. – irieill Sep 05 '16 at 13:29
  • I edited, thanks @irieill – H.Celik Sep 05 '16 at 14:05

1 Answers1

3

The only way I know of (at least up to PrimeFaces 6.0.x, the current version at the time of answering) is to override the bindEvent() function of the selectManyMenu so a click without a meta key (ctrl in this case) does not do an unselect. For the trunk version of PrimeFaces that is line 1879 in the forms.jsf file

So

if(!metaKey) {
    $this.unselectAll();
}

becomes

if(!metaKey) {
    //$this.unselectAll();
}

How to override a full PrimeFaces javascript function can be read in this Stackoverflow Q/A

In addition, under the line 1879 in the forms which above , there is if(metaKey && item.hasClass('ui-state-highlight')) line 1882. There shouldn't be metakey in if condition, it must be like this : if(item.hasClass('ui-state-highlight')) . So if user want to unselect the item without ctrl, it works correctly

Community
  • 1
  • 1
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • Yeah, this is an answer, I tried it and it works correctly. Thank you very much @Kukeltje – H.Celik Sep 05 '16 at 19:00
  • 1
    In addition, under the line 1879 in the forms which above @Kukeltje said, there is if(metaKey && item.hasClass('ui-state-highlight')) line 1882. There shouldn't be metakey in if condition, it must be like this : if(item.hasClass('ui-state-highlight')) . So if user want to unselect the item without ctrl, it works correctly – H.Celik Sep 06 '16 at 08:32
  • Please 'edit' the answer and I will aprove the edit so it will be part of it – Kukeltje Sep 06 '16 at 10:47