2 Replies Latest reply on May 3, 2010 2:21 AM by Kapil Nimje

    HtmlAjaxSupport for HtmlSelectBooleanCheckbox

    Kapil Nimje Newbie

      Hi,

          I have a check box , when i checked that check box i need to subimit ajax request and rerender the panel. can anyone help me out how i do this.

       

      Please find the below code

       

                     HtmlSelectBooleanCheckbox cbRandomizeAnswer = new HtmlSelectBooleanCheckbox();

       

                      cbRandomizeAnswer.setId("RandomizeAnswer"+i);
                      cbRandomizeAnswer.setStyleClass("RandomizeAnswer");
                      cbRandomizeAnswer.getAttributes().put("style","width:20px;");
                      String randomizeAnswerValExpr = "#{projectBean.questions[" + i + "].randomizeAnswer}";
                      cbRandomizeAnswer.setValueExpression("value", application.getExpressionFactory().createValueExpression(context.getELContext(),                 randomizeAnswerValExpr, String.class));

       

       

      I have using below approach to do this but still its not working

       

                     HtmlAjaxSupport ajaxSupportType = new HtmlAjaxSupport();
                           ajaxSupportType.setActionExpression(FacesContext.getCurrentInstance().getApplication().getExpressionFactory().
                           createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{projectController.test}", String.class, new Class[] {}));

       

                      UIParameter paramRandomizeAnswerIndex = new UIParameter();
                      paramRandomizeAnswerIndex.setName("questionIndex");
                      paramRandomizeAnswerIndex.setValue(i);
                      ajaxSupportType.getChildren().add(paramRandomizeAnswerIndex);
                      ajaxSupportType.setEvent("onsubmit");
                      ajaxSupportType.setReRender("questionnaire_tab_panel");
                      cbRandomizeAnswer.getFacets().put("a4jsupport",ajaxSupportType);

        • 1. Re: HtmlAjaxSupport for HtmlSelectBooleanCheckbox
          Harut Sargsyan Apprentice

          Hi, here is similar code which works fine:

           

          ...................       

          HtmlSelectBooleanCheckbox checkbox = new HtmlSelectBooleanCheckbox();

           

          ValueExpression ve = createValueExpression(context, control.getIndex(), EDIT_ELEMENT_CHECK_BOX_TYPE);
          checkbox.setValueExpression("value", ve);

           

          HtmlAjaxSupport mySupport = new HtmlAjaxSupport();
          mySupport.setEvent("onclick");
          mySupport.setReRender(AjaxRendererUtils.asSet("dynamicPart"));
          mySupport.setAjaxSingle(false);
          checkbox.getFacets().put("a4jsupport", mySupport);

          ................................

           

           

          private ValueExpression createValueExpression(FacesContext pContext,
                                                            int index, int checkboxType) {

           

                  String expression = "#{parser.allControls.controlTypes[" + index + "].controlValue}";
                  if (checkboxType == CHECK_BOX_TYPE) {
                      expression = "#{parser.allControls.controlTypes[" + index + "].booleanValue}";
                  } else if (checkboxType == EDIT_ELEMENT_CHECK_BOX_TYPE) {
                      expression = "#{parser.allControls.controlTypes[" + index + "].enabled}";
                  }

           

                  ValueExpression ve = mFactory.createValueExpression(pContext.getELContext(), expression, String.class);

           

                  return ve;

          }

          • 2. Re: HtmlAjaxSupport for HtmlSelectBooleanCheckbox
            Kapil Nimje Newbie

            Thanks Its work for me...