2 Replies Latest reply on Jan 13, 2010 4:46 AM by satish kumar

    <a4j:outputpanel> issue

    satish kumar Newbie

      Hi,

      I'm facing a typical problem.

       

      //main.html

       

      <!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>
      <a4j:form>
          <rich:panel style=" height : 550px;">
              <f:facet name="header">#{msgs.search_heading}</f:facet>
              <rich:messages style="color:red"/>
              <h:panelGrid columns="3">
                  <h:outputText value="#{msgs.search_type}" />
                  <h:selectOneMenu value="#{searchBean.selectedId}">
                      <f:selectItem itemLabel="Select type" itemValue="0" />
                      <f:selectItem itemLabel="MessageId" itemValue="1" />
                      <f:selectItem itemLabel="TrackId" itemValue="2" />
                      <f:selectItem itemLabel="All Messages" itemValue="3" />
                      <a4j:support event="onchange" actionListener="#{searchBean.process}" ajaxSingle="true"/>
                  </h:selectOneMenu>
              </h:panelGrid>
              <rich:spacer height="5" />
              <a4j:outputPanel id="one" ajaxRendered="true">
                  <h:panelGrid columns="3" rendered="#{searchBean.renderOne}">
                      <h:outputText value="#{searchBean.messageLable}" />
                      <h:inputText value="#{searchBean.id}" required="true"
                          requiredMessage="Please enter the id" />
                  </h:panelGrid>
                  <h:panelGrid columns="2" rendered="#{searchBean.renderTwo}">
                      <h:outputText value="#{msgs.search_fromdate}" />
                      <rich:calendar value="#{searchBean.fromdate}"
                          enableManualInput="false" popup="true" datePattern="dd/MM/yyyy"
                          showWeeksBar="false" />
                      <h:outputText value="#{msgs.search_todate}" />
                      <rich:calendar value="#{searchBean.todate}"
                          enableManualInput="false" popup="true" datePattern="dd/MM/yyyy"
                          showWeeksBar="false" />
                  </h:panelGrid>
              </a4j:outputPanel>
              <a4j:commandButton action="#{searchBean.execute}" value="Submit" />
          </rich:panel>
      </a4j:form>
      </body>
      </html>

       

      //my bean isin request scope

       

      public class SearchBean {

       

          private String selectedId;
          private String id;
          private String messageLable;
          private boolean renderOne;
          private boolean renderTwo;
          private boolean renderSubmit;
          private Date fromdate;
          private Date todate;

       

          public SearchBean() {
          }

       

          public String getId() {
              return id;
          }

       

          public void setId(String id) {
              this.id = id;
              System.out.println("in set id " + id);
          }

       

          public Date getFromdate() {
              return fromdate;
          }

       

          public void setFromdate(Date fromdate) {
              this.fromdate = fromdate;
          }

       

          public Date getTodate() {
              return todate;
          }

       

          public void setTodate(Date todate) {
              this.todate = todate;
          }

       

          public String getMessageLable() {
              return messageLable;
          }

       

          public void setMessageLable(String messageLable) {
              this.messageLable = messageLable;
          }

       

          public boolean isRenderSubmit() {
              return renderSubmit;
          }

       

          public void setRenderSubmit(boolean renderSubmit) {
              this.renderSubmit = renderSubmit;
          }

       

          public String getSelectedId() {
              return selectedId;
          }

       

          public void setSelectedId(String selectedId) {
              this.selectedId = selectedId;
          }

       

          public boolean isRenderOne() {
              return renderOne;
          }

       

          public void setRenderOne(boolean renderOne) {
              this.renderOne = renderOne;
          }

       

          public boolean isRenderTwo() {
              return renderTwo;
          }

       

          public void setRenderTwo(boolean renderTwo) {
              this.renderTwo = renderTwo;
          }

       

          public void process(ActionEvent event) {
              if (selectedId != null && selectedId.equalsIgnoreCase("1")) {
                  setMessageLable("Message Id");
                  setRenderOne(true);
                  setRenderSubmit(true);
              } else if (selectedId != null && selectedId.equalsIgnoreCase("2")) {
                  setMessageLable("Track Id");
                  setRenderOne(true);
                  setRenderSubmit(true);
              } else if (selectedId != null && selectedId.equalsIgnoreCase("3")) {
                  setMessageLable(null);
                  setRenderOne(false);
                  setRenderTwo(true);
                  setRenderSubmit(true);
              } else {
                  setMessageLable(null);
                  setRenderOne(false);
                  setRenderTwo(false);
                  setRenderSubmit(false);
              }

       

          }

       

          public String execute() {
              System.out.println("in execute id is " + id);
              System.out.println("from date" + fromdate);
              System.out.println("to date" + todate);
              return null;
          }
      }

       

      The problem here is, based on the option selected from drop down, i have to display the second row and this is working but when i submit the form.

      in bean all the values coming as null. even validation is not working. if i remove the <a4j:outputpanel> values are available in bean, but rendering is not working properly. could somebody help me on this. thanks in advance.