0 Replies Latest reply on Mar 16, 2012 3:37 PM by darvela

    Duplicate id error when  rerender jsf components

    darvela

      I'm trying to generate dynamically components and ajax behaviors from java. The component´s generation is good, adding blur event is good, but when The form is rerneder in order to update de values of components throw an Duplicate ID error in the the xhtml page.

       

      public void genretaForm() {

                          panelGrid.getChildren().clear();

       

       

                          HtmlInputText input1;

                          HtmlInputText input2;

                          HtmlOutputText label1;

                          HtmlOutputText label2;

       

       

                          // Input value

                          label1 = (HtmlOutputText) FacesContext.getCurrentInstance().getApplication()

                                              .createComponent(HtmlOutputText.COMPONENT_TYPE);

                          input1 = (HtmlInputText) FacesContext.getCurrentInstance().getApplication()

                                              .createComponent(HtmlInputText.COMPONENT_TYPE);

                          label1.setValue("Ingrese valor:");

       

       

                          // Output value

                          label2 = (HtmlOutputText) FacesContext.getCurrentInstance().getApplication()

                                              .createComponent(HtmlOutputText.COMPONENT_TYPE);

                          input2 = (HtmlInputText) FacesContext.getCurrentInstance().getApplication()

                                              .createComponent(HtmlInputText.COMPONENT_TYPE);

                          if ((valInput2 != null) && (valInput2.length() > 0)) {

                                    input2.setValue(valInput2);

                          }

                          label2.setValue("Valor nuevo:");

       

       

                          // Ajax behavior on blur event

                          AjaxBehavior ajaxBehavior = (AjaxBehavior) FacesContext.getCurrentInstance().getApplication()

                                              .createBehavior(AjaxBehavior.BEHAVIOR_ID);

                          MethodExpression listener = FacesContext

                                              .getCurrentInstance()

                                              .getApplication()

                                              .getExpressionFactory()

                                              .createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{testbean.onBlurInput1}",

                                                                  null, new Class[] { BehaviorEvent.class });

       

       

                          ajaxBehavior.addAjaxBehaviorListener(new MethodExpressionAjaxBehaviorListener(listener));

                          input1.addClientBehavior("blur", ajaxBehavior);

       

       

                          panelGrid.getChildren().add(label1);

                          panelGrid.getChildren().add(input1);

                          panelGrid.getChildren().add(label2);

                          panelGrid.getChildren().add(input2);

       

                }

       

       

      // XHTML snippet

      <h:form>

                                    <h:commandButton id="btnGenerar" value="Dynamic generate" action="#{testbeangenretaForm}"></h:commandButton>

                                    <h:panelGrid columns="4" binding="#{testbean.panelGrid}">

                                              <f:facet name="header">

                                                        <h:outputLabel value="Dinamica" />

                                              </f:facet>

                                    </h:panelGrid>

                                    <h:commandButton id="btnGuardar" value="Save" action="#{testbean.generarForma}"></h:commandButton>

      </h:form>

       

      Any idea to fiz this issue?