4 Replies Latest reply on Sep 14, 2010 9:02 AM by harut

    Submitting values of conditionally rendered inputfields

    jensmander

      Hi,

       

      I'd like to show some fields of my form only in specific situations. It depends on the selected values of a combobox. To set up the conditional behavior of the inputtext-element I use the rendered-attribute and to reRender the inputtext-element I specified a a4j:support-element within the combobox which invokes the rerender process if the combobox changes it's values. The problem is that if I do it like that page never transfers the values of the inputtext into the defined BackingBean attribute or in other words the setInputtext method will never be invoked.

       

      Take a look at this JSF-Code

       

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:rich="http://richfaces.org/rich"
          xmlns:a4j="http://richfaces.org/a4j">
      <body>
      <ui:composition template="/templates/popup.xhtml">
          <ui:define name="pageTitle">Test</ui:define>
          <ui:define name="pageHeader">Testform</ui:define>
          <ui:define name="body">
              <h:form id="frmTest">
                  <h:panelGrid columns="2">
                      <h:outputLabel value="Choice" />
                      <rich:comboBox value="#{testBean.value}">
                          <f:selectItems value="#{testBean.values}" />
                          <a4j:support event="onchange" reRender="frmTest" />
                      </rich:comboBox>
                      <h:outputLabel for="txtInput" value="Inputtext" />
                      <h:inputText id="txtInput" value="#{testBean.inputText}" rendered="#{testBean.visible}"/>
                      <h:commandButton value="Submit" />
                  </h:panelGrid>
              </h:form>
          </ui:define>
      </ui:composition>
      </body>
      </html>
      

       

      The backing bean is set to request scope and looks like that

       

       

      package de.hd.kiwi.backingBean;
      
      import java.util.ArrayList;
      import java.util.List;
      
      import javax.faces.model.SelectItem;
      
      public class TestBean {
      
          private String choice;
          private String inputText;
          
          public boolean isVisible() {
              return choice != null && (choice.equals("Choice 2") || choice.equals("Choice 4"));
          }
          
          public List<SelectItem> getValues() {
              List<SelectItem> res = new ArrayList<SelectItem>();
              for (int i =0; i< 5;++i) {
                  res.add(new SelectItem("Choice " + i));
              }
              return res;
          }
      
          public void setValue(String s) {
              choice = s;
          }
          
          public String getValue() {
              return choice;
          }
      
          public String getInputText() {
              return inputText;
          }
      
          public void setInputText(String input) {
              System.out.println("Inputtext: " + input);
              this.inputText = input;
          }
      }
      

       

      May anybody tell me why this problems occures? The submit-button should invoke all the setters of the BackingBean I guess so why it doesn't? Is there a missmatch of the client and server-side? I hope somebody can tell me how to fix it. Thanks a lot.

       

      Jens