0 Replies Latest reply on May 18, 2009 6:07 PM by Michal Petrik

    Ajax submit of combo boxes values wrapped in data table

    Michal Petrik Newbie

      Hi,
      I'm trying to submit values from comboBoxes which are wrapped with rich date table. Number of table rows should be dynamic. When I tried it with traditional jsf command button everything works well, but I want to try ajax aproach.
      The main point is that when using standard jsf form and commandButton the values from tables comboboxes are injected into list of DAOs, but when using ajax approach listed below values are not injected and it obviously run into nullpointer exception.

      My example code:


      <a4j:form id="input">
       <h:panelGrid border="0" columns="2">
       <rich:panel style="width:160px">
       <f:facet name="header">
       Input
       </f:facet>
       <a4j:commandButton value="Add row" reRender="inputValues" action="#{MultiGraphChartBean.addRowInput}"
       rendered="#{MultiGraphChartBean.addDeleteRendered}" ajaxSingle="true" ignoreDupResponses="true" similarityGroupingId="addDel"/>
       <a4j:commandButton value="Del row" immediate="true" reRender="inputValues"
       action="#{MultiGraphChartBean.deleteRowInput}" rendered="#{MultiGraphChartBean.addDeleteRendered}"
       ignoreDupResponses="true" similarityGroupingId="addDel"/>
       <h:commandButton value="Edit rows" action="#{MultiGraphChartBean.edit}" rendered="#{MultiGraphChartBean.editRendered}"/>
       <br /><br />
       <h:commandButton value="Render" action="#{MultiGraphChartBean.redirectToNewView}" />
       </div>
       <br />
      
       </rich:panel>
       <rich:dataTable id="inputValues" width="100%" var="item" value="#{MultiGraphChartBean.rowInputs}">
       <f:facet name="header">
       <h:outputText value="Parameters"/>
       </f:facet>
      
       <rich:column>
       <f:facet name="header">
       <h:outputText value="Test"/>
       </f:facet>
       <rich:comboBox id="test" suggestionValues="#{MultiGraphChartBean.performanceTestIdents}"
       value="#{item.testIdent}" defaultLabel="Enter value" required="true"
       requiredMessage="#{FormatManagerBean.valueIsRequired}"
       listStyle="text-align:left"/>
       <rich:message for="test"/>
       </rich:column>
      
       <rich:column>
       <f:facet name="header">
       <h:outputText value="Test scenario"/>
       </f:facet>
       <rich:comboBox id="testSc" suggestionValues="#{MultiGraphChartBean.testScenarioIdents}"
       value="#{item.testScenarioIdent}" defaultLabel="Enter value" required="true"
       requiredMessage="#{FormatManagerBean.valueIsRequired}"
       listStyle="text-align:left"/>
       <rich:message for="testSc"/>
       </rich:column>
      
       <rich:column>
       <f:facet name="header">
       <h:outputText value="Environment config"/>
       </f:facet>
       <rich:comboBox id="envConf" suggestionValues="#{MultiGraphChartBean.environmentConfigs}"
       value="#{item.environmentConfig}" defaultLabel="Enter value" required="true"
       requiredMessage="#{FormatManagerBean.valueIsRequired}"
       listStyle="text-align:left"/>
       <rich:message for="envConf"/>
       </rich:column>
      
       <rich:column>
       <f:facet name="header">
       <h:outputText value="Default.cfg"/>
       </f:facet>
       <rich:comboBox id="defConf" suggestionValues="#{MultiGraphChartBean.defaultConfigs}"
       value="#{item.defaultConfig}" defaultLabel="Enter value" required="true"
       requiredMessage="#{FormatManagerBean.valueIsRequired}"
       listStyle="text-align:left"/>
       <rich:message for="defConf"/>
       </rich:column>
       </rich:dataTable>
       </h:panelGrid>
       </a4j:form>
      


      Bean:

      ....
      
      //initialization of this list is maintained elsewhere
      private List<MultiGraphChartInputDao> rowInputs;
      
       public void addRowInput() {
       if (rowInputs.size() < MAX_ROW_INPUTS) {
       rowInputs.add(new MultiGraphChartInputDao());
       }
       }
      
       public void deleteRowInput() {
       if (rowInputs.size() > MIN_ROW_INPUTS) {
       rowInputs.remove(rowInputs.size() - 1);
       }
       }
      
      ....
      getters and setters
      


      Thanks for any response.