4

I'm having trouble with a JSF selectManyCheckbox and A4J support. The purpose is to run some action when a checkbox is selected. This works perfectly in Firefox. Yet, when testing in any IE (ie6 / ie7 / ie8), found out that the action was being called but the selected value was put to null. Just to test it, I placed a JSF commandButton to submit the form and to check the value that was selected and it was correct. So the problem is really in the ajax action (without submiting the form). Here is my code:

        <h:selectManyCheckbox id="supportCategoryCardFilter" value="#{cardListProvider.categoriesHolder.selectedCategories}"  layout="pageDirection" required="false" >
            <f:selectItems value="#{cardListProvider.categoriesList}" />
            <a:support ajaxSingle="true" status="statusSearchCard" id="supportCategoryCardFilter2" event="onclick" reRender="cardsHolder, renderCardsCategoriesPanel" 
                 action="#{cardListProvider.findCards(cardListProvider.categoriesHolder.selectedCategories)}"  >
            </a:support>
        </h:selectManyCheckbox>

where cardListProvider.categoriesList is a List<SelectItem> and cardListProvider.categoriesHolder.selectedCategories is a List<String>

Has anyone had this problem? Can anyone help me with this? Thank you

Jon Onstott
  • 13,499
  • 16
  • 80
  • 133
GuilhermeA
  • 1,051
  • 1
  • 13
  • 17
  • After some more debbuging I noticed that selectManyCheckbox value (value="#{cardListProvider.categoriesHolder.selectedCategories}") is being set when I click a checkbox in Firefox but not in IE! Only submitting the form! Can't understand this... – GuilhermeA Nov 17 '09 at 10:46
  • 2
    Check that you don't have nested forms. It can cause this behaviour. – Damo Nov 17 '09 at 20:09
  • Man, it was it... we made a huge redesign and in the middle a colleague of mine included the form inside a form...We are including lots of .xhtml in others .xhtml that was hard to notice! thank you very much! I can't understand why it worked in firefox! Thank you – GuilhermeA Nov 18 '09 at 08:31
  • Hello, I am having a similar problem...In my case, on a click event ajax sets only the value of the first of the selected check-boxes in the backing bean. There are no nested forms. Any idea what could be wrong? – Katerina Mpagouli Jul 22 '14 at 08:40

2 Answers2

4

You should use either JBoss EL, or declare a JSF function. If you are using facelets, this is as easy as:

  • declare a public static method in a class of your preference
  • in a my.taglib.xml (facelets decriptor) add:
  • <function>
        <function-name>concat</function-name>
        <function-class>com.mycompany.myproject.ServiceFunctions</function-class>
        <function-signature>java.lang.String concat(java.lang.String, java.lang.String)   </function-signature>
    </function>
    

  • Also, try setting the event to "onselect" (or "onchange") rather than "onclick"
  • try seting immediate="true"
  • try removing the method parameter - you don't need it, since you can access it via the property of the managed bean - i.e. action="#{cardListProvider.findCards}" and then in findCards() get this.cardListProvider.categoriesHolder.selectedCategories
  • try upgrading to richfaces 3.3.2.SR1
  • Bozho
    • 588,226
    • 146
    • 1,060
    • 1,140
    • Then try "onchange" or better "onselect" rather than "onclick" – Bozho Nov 17 '09 at 11:00
    • Another event isn't going to help. Besides, in a checkbox/radiobutton you really want onclick instead of onchange. – BalusC Nov 17 '09 at 11:16
    • you're right BalusC, changing the event did not help me... thank you anyway Bozho! Any other idea? – GuilhermeA Nov 17 '09 at 11:27
    • Check firefox error console. And see if there is a JS error in IE. (P.S. I don't agree 'onclick' is preferable with radios/checkboxes) – Bozho Nov 17 '09 at 11:33
    • Try immediate="true" (to suppress validation problems) – Bozho Nov 17 '09 at 12:33
    • Bozho: in case of radios/checkboxes the change event is in certain browsers only fired if you click 2 times. – BalusC Nov 17 '09 at 13:07
    • yeah, I already tried it! The problem is that in IE, the setter of the selected elements (this.cardListProvider.categoriesHolder.selectedCategories) is not running! So, even if I do it the way you suggested, I get the same result! I would understand that I had something wrong in the whole mechanism if it wasn't working in Firefox but since it is I can't understand what I'm doing wrong! – GuilhermeA Nov 17 '09 at 16:38
    • which version of richfaces, btw. If not 3.3.2.SR1 , try upgrading to it. – Bozho Nov 17 '09 at 17:00
    • it's not the 3.3.2.SR1, it's the 3.3.1.GA. I cannot update, other colleagues depend on this version too.. But do you think the problem comes from richfaces? Isn't the JSF selectManyCheckbox control that is not setting the variable? – GuilhermeA Nov 17 '09 at 17:18
    • perhaps "not triggering the event". Which is fine with JSF alone, but breaks richfaces. btw, JSF RI or MyFaces? P.S. Upgrading is something that CAN be done within a team. Just agree on a time for the upgrade. In my team we have changed 2 versions of richfaces for tha past 4 months with no problems. – Bozho Nov 17 '09 at 17:43
    • It's not myfaces (don't know what JSF RI means). I've tried so many things and can't get this to work. It's very frustrating. Yeah, I will suggest we upgrade, we are overloaded with work this week so maybe next week! By the way, than you very much for the time you are spending helping me! Back to my bug... :/ – GuilhermeA Nov 17 '09 at 18:20
    • How exactly? after an upgrade? – Bozho Nov 18 '09 at 08:34
    • No... stupid mistake... we made a huge redesign and during the process a colleague of mine included the form inside a form...We are including lots of .xhtml in others .xhtml so it was hard to notice! thank you very much! I can't understand why it worked in firefox! Thank you – GuilhermeA Nov 18 '09 at 10:00
    1

    I am surprised this even works in Firefox. Action methods don't support parameters. From the Richfaces docs:

    signature must match java.lang.Object action()

    http://livedemo.exadel.com/richfaces-demo/richfaces/support.jsf?tab=info&cid=1615759

    Naganalf
    • 1,091
    • 7
    • 11