2 Replies Latest reply on Jan 18, 2011 9:53 AM by Earnest Dyke

    ValueChangeListener not working

    Olalekan Ogunleye Newbie
      Hi all,

      Can someone please help me and tell me what I am doing wrong? OK, this is what I want to do. I have a form which contains combox (<h:selectOneMenu>) only with some options. And so I want to make sure that when a user selects one of the options in the combox box a form should be rendered on the same page. I am using panel. I have tried to put some words like 11111, 22222, 3333 in the place where I want to display my other form and this words are displayed. I have also used ui:include but I get WARNING [renderkit] 'for' attribute cannot be null instead of displaying the form. Also, I have tried to do it from the code but its not working out. Can someone help me out please.

      Below is my code and backing bean


      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://jboss.com/products/seam/taglib"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:rich="http://richfaces.org/rich"
          xmlns:a4j="http://richfaces.org/a4j"
          template="layout/template.xhtml">

      <ui:define name="body">
           <a4j:keepAlive beanName="valueChangeManager"></a4j:keepAlive>
          <h:form id="serviceForm">
                 
                  <rich:panel>
                      <f:facet name="header">Configure Service for New Subscriber</f:facet>
                      <h:panelGrid columns="1">
                      <s:decorate id="nameDecoration" template="layout/edit.xhtml">
                        <ui:define name="label">Select Service:</ui:define>
                        <h:selectOneMenu value="#{valueChangeManager.state}" valueChangeListener="#{valueChangeManager.valueChanges}">
                              <f:selectItem itemValue="" />
                           <f:selectItem itemValue="keyword" />
                             <f:selectItem itemValue="sms" />
                              <f:selectItem itemValue="c3to" />
                              <a4j:support event="onchange" ajaxSingle="true" reRender="wrap1,wrap2,wrap3"></a4j:support>
                        </h:selectOneMenu>
                      </s:decorate>
                      </h:panelGrid>
                  </rich:panel>
                 
                  <rich:panel id="wrap1">
                  <rich:panel rendered="#{valueChangeManager.state eq 'keyword'}">
                  <ui:include src="/serviceKeyword.xhtml"/>
                  </rich:panel>
                  </rich:panel>
                 
                  <rich:panel id="wrap2">
                  <rich:panel rendered="#{valueChangeManager.state eq 'sms'}">
                   22222
                  </rich:panel>
                  </rich:panel>
                 
                  <rich:panel id="wrap3">
                  <rich:panel rendered="#{valueChangeManager.state eq 'c3to'}">
                   33333
                  </rich:panel>
                  </rich:panel>
                 
                 
              </h:form>


      </ui:define>

      </ui:composition>



      package valueChangeManager

      import java.io.Serializable;
      import org.jboss.seam.annotations.Name;
      import javax.faces.event.ValueChangeEvent;
      import javax.faces.context.FacesContext;

      @Name("valueChangeManager")
      public class ValueChangedBean implements Serializable, ValueChanged {
           private String state="";
           /**
            *
            */
           private static final long serialVersionUID = 1L;
           
           public String valueChanges(ValueChangeEvent e) {
                if (e.getNewValue().equals("keyword")) {
                     state="keyword";
                     keywordSelected();
                     //e.getNewValue();
                }else if (e.getNewValue().equals("sms")) {
                     state = "sms";
                     smsSelected();
                     //e.getNewValue();
                }else if (e.getNewValue().equals("c3t0")) {
                     state="c3t0";
                     c3toSelected();
                     //e.getNewValue();
                }
                state=e.getNewValue().toString();
                FacesContext.getCurrentInstance().renderResponse();
                return state;
           }
           
           public String getState() {
                return state;
           }
           public void setState(String state) {
                this.state = state;
           }

           public String keywordSelected() {
                
                return "/serviceKeyword.xhtml";
           }

           public String smsSelected() {
                
                return "/serviceSms.xhtml";
           }

           public String c3toSelected() {
                
                return "/servicec3to.xhtml";
           }
           
      }