2 Replies Latest reply on Feb 18, 2011 9:36 AM by sv kap

    Checkbox + a4j:commandLink select

    sv kap Newbie



      I have several dynamically generated checkboxes which I need to check/uncheck using a4j:commandLink . Here is part of the code which is used to generate the checkboxes:



      MethodExpression checkboxValueChangeExpression = expressionFactory
                      "#{bean.checkBoxClicked}", null,
                      new Class[] { ActionEvent.class });
      MethodExpressionActionListener checkboxValueChangeListener = new MethodExpressionActionListener(
      HtmlSelectBooleanCheckbox checkBox = new HtmlSelectBooleanCheckbox();
      String checkboxId = "checkBox_id_" + getNumber();
      HtmlAjaxSupport asCheckbox = new HtmlAjaxSupport();
      String ajaxCheckboxId = AJAX_CHECBOX_ID_PREFIX
              + getNumber();
      checkboxValues.put(ajaxCheckboxId, false);
      ValueExpression checkBoxValueExpression = expressionFactory
              .createValueExpression(elContext, "#{bean.checkboxValues."
                      + ajaxCheckboxId + "}", Boolean.class);
      checkBox.setValueExpression("value", checkBoxValueExpression);



      Here is a slightly modified code of the commandLink method:



      String id = AJAX_CHECBOX_ID_PREFIX + getNumber();
      checkboxValues.put(id, true);


      The problem is that although the reRender property is set to one of the parents of the checkboxes they are not updated in the UI (they remain unchecked). How can I make them refresh themselves?

        • 1. Checkbox + a4j:commandLink select
          sv kap Newbie

          I found the problem. Now I have to find the solution . The checkboxes are located in one ui:define tag and the command link is located in another. If both components are in the same ui:define it works. Otherwise I have to first click on one of the generated checkboxes and then it starts working perfectly (starts to refresh the UI).

          • 2. Checkbox + a4j:commandLink select
            sv kap Newbie

            Hi again.


            Here are some strange observations...


            Actually I have construction like that:


            <ui:define ..

                 <a4j:form id="form1">

                      <h:panelGroup layout="block" id="test"

                       ... some generaeted content (see the post above) ...




            <ui:define ..

                 <a4j:form id="form2">

                      <a4j:commandLink ... reRender="test"  ...





            When the page is loaded and I try to use the command link from form2 it does not work (it calls the backing bean and changes the checkbox value holder but does not refresh the UI). When I manually click on a checkbox then everything starts working and the command link refreshes the form1 UI.


            I hope that I am not writing only to myself and someone can give me a hand