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

      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 }" 
                 valueBinding="#{ scheduleUI.frequencyMenu }"                               
                 valueChangeListener="#{ scheduleMgr.frequencyChanged }"
           <s:convertEnum />
           <s:enumItem enumValue="ONCE"        label="Once" />
           <s:enumItem enumValue="QUARTERLY"   label="Quarterly" />
      <h:inputText id="execCnt" 
                   value="#{ scheduleMgr.instance.execCnt }" 
                   required="#{ scheduleMgr.instance.frequency.equals(Frequency.ONCE) }"
                   disabled="#{ scheduleMgr.instance.frequency.equals(Frequency.ONCE) }"
                   autocomplete="on" />

      Event scoped POJO with the JSF component bindings:

      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:

      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());
          // >> scheduleUI.getFrequencyMenu() returns null
          log.debug("ExecCnt Input text: #0", scheduleUI.getFrequencyMenu()); 
          if (frequency.equals(Frequency.ONCE)) {
            // NullPointer thrown....
          } else {
            // NullPointer thrown....

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

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

      Best regards,