1 Reply Latest reply on Aug 30, 2008 1:19 PM by Csahocska Csaho

    JSF component bindings and EJB session bean valueChange

    Csahocska Csaho Newbie

      Hello All!


      I would appreciate help in relation to the following problem:


      I would like to inject an Event scoped component (POJO) into a Conversation scoped
      EJB session bean, where the Event scoped bean has JSF components bound to it.Then,
      in the EJB session bean I would like to respond to valueChange events from the UI,
      where the valueChange event changes the JSF components bound to the event scoped
      (injected) bean.


      My utlimate goal is to listen to value changes from a selectOneMenu item in the UI and have
      other components (radio button and a couple of other inputtexts) change in response to that
      event. 


      The problem is that in the EJB conversation scoped bean's valueChange listener I get
      a NullPointer when trying to access the JSF componets bound to the injected Event scoped component...
      In other words, I'm not binding the components properly.


      UI menu component:


      <h:selectOneMenu id="frequency" 
                 value="#{ scheduleMgr.instance.frequency }" 
                 required="true"
                 onchange="this.form.submit();"
                 valueBinding="#{ scheduleUI.frequencyMenu }"                               
                 valueChangeListener="#{ scheduleMgr.frequencyChanged }"
                 immediate="true">
           <s:convertEnum />
           <s:enumItem enumValue="ONCE"        label="Once" />
              ...
           <s:enumItem enumValue="QUARTERLY"   label="Quarterly" />
      </h:selectOneMenu>
      
      <h:inputText id="execCnt" 
                   value="#{ scheduleMgr.instance.execCnt }" 
                   required="#{ scheduleMgr.instance.frequency.equals(Frequency.ONCE) }"
                   size="5"
                   maxlength="3"
                   disabled="#{ scheduleMgr.instance.frequency.equals(Frequency.ONCE) }"
                   autocomplete="on" />
      
      


      Event scoped POJO with the JSF component bindings:


      @Name("scheduleUI")
      @Scope(ScopeType.EVENT)
      public class ScheduleUI {
      
        private HtmlSelectOneMenu frequencyMenu;
        private HtmlSelectOneRadio frequencyOptsRadio;
        private HtmlInputText execCnt; 
        
        // getters / setters omitted...
      }



      Trimmed down version of the Conversation scoped Stateful EJB which responds to the
      event from the selectOneMenu:



      @Stateful
      @Name("scheduleMgr")
      public class ScheduleManagerBean implements ScheduleManagerLocal, Serializable {
       
        ...
      
        @In(scope = ScopeType.EVENT, required = false)
        private ScheduleUI scheduleUI;
        
        private Schedule instance;
      
        ...
      
        /**
         * Triggered in response to frequency change.
         * @param event
         */
        public void frequencyChanged(ValueChangeEvent event) {
          Frequency frequency = (Frequency) event.getNewValue();
          log.debug("Frequency changed event: #0. Phase ID: #1", frequency, event.getPhaseId());
      
          getInstance().setFrequency(frequency);
          
          // >> scheduleUI.getFrequencyMenu() returns null
          log.debug("ExecCnt Input text: #0", scheduleUI.getFrequencyMenu()); 
          
          if (frequency.equals(Frequency.ONCE)) {
            // NullPointer thrown....
            scheduleUI.getExecCnt().setValue(null);
          } else {
            // NullPointer thrown....
            scheduleUI.getExecCnt().setValue("1");
          }
          
          FacesContext.getCurrentInstance().renderResponse();
        }
        ...
      }



      (Pls note - the Frequency component is just an Enum class.)


      Pls suggest what the problem could be - I'd appreciate any input.


      Best regards,


      C.