3 Replies Latest reply on Jun 22, 2010 10:14 AM by Dean Hiller

    selectOneListBox not calling setTarget

    Dean Hiller Expert

      This should be simple but for the life of me, it is just not calling setSelectedScript though it is calling getSelectedScript.  This is mostly supposed to be a read page so no long conversations going on here either(We really really don't want one as this is the main landing page where conversations end).


      xhtml




      <h:form id="scriptsform">
      <div id="scriptstable">
          <h2>Scripts</h2>
           <!-- NOTE: init here instead of pages so freaking ajax
                         does not keep reloading and initing -->
           #{listScripts2.initialize()}
           
           <div id="scriptlist" style="float:left; width:200px">
          <h:selectOneListbox id="scripts" value="#{listScripts2.selectedScript}" required="true"
                          size="21" styleClass="singleListOfScripts">
              <s:selectItems var="s" value="#{listScripts2.scripts}" label="#{s.name}" >
              </s:selectItems>
              <s:convertEntity />
              <a:support event="onchange" reRender="desc" immediate="true" ajaxSingle="true" bypassUpdates="false"/>
          </h:selectOneListbox>
          </div>
            <s:div id="desc" style="float:left; width:200px">
               <h3>Name:</h3>
               #{listScripts2.selectedScript.name}<br/><br/>
               <h3>Language:</h3>
               #{listScripts2.selectedScript.language}<br/><br/>
               <h3>Description:</h3>
               <h:outputText escape="false" value="#{listScripts2.selectedScript.description}" />
          </s:div>
          <br/><br/>
      
      </div>
      </h:form>



      Java bean




      @Name("listScripts2")
      @Scope(ScopeType.SESSION)
      public class ListScriptsAction2 extends ActionBase implements Serializable {
      
           private static final long serialVersionUID = -6587296133429904762L;
      
           private Script selectedScript;
      
           protected List<Script> scripts;
      
           // NOTE: Each time we hit the page, this makes sure
           // we reload the entities....
           public void initialize() {
                if(selectedScript != null) {
                     if(selectedScript.getId() != null)
                          selectedScript = entityManager.find(Script.class, selectedScript.getId());
                     else
                          selectedScript = null;
                }
                
                scripts = Script.findAllScripts(entityManager);
           }
           
           public List<Script> getScripts() {
                return scripts;
           }
      
           public Script getSelectedScript() {
                return selectedScript;
           }
      
           public void setSelectedScript(Script selectedScript) {
                this.selectedScript = selectedScript;
           }
      }



      ONE last question.  I would prefer the list to be in the PAGE scope, the action bean in EVENT scope(as nearly all action beans I think should be stateless) and then the selectedScript in SESSION scope so if you come back to this page in any browser tab, the last selected value is selected for you.  Is this possible though?


      I guess first, I need the dang setSelectedScript to be called.  Any ideas on why it is not invoked when I make a selection and only getter is called every time I choose something new?


      thanks,
      Dean

        • 1. Re: selectOneListBox not calling setTarget
          Dean Hiller Expert

          odd something changed and I am now seeing the value not valid in the logs queued to be displayed(that wasn't there before) but that tells me the item in the list is not equal to any in the list...time for equals/hashcode now to fix it.....odd, warning went away but setter is still not called ....grrrrrr

          • 2. Re: selectOneListBox not calling setTarget
            Heri Bender Newbie

            From the code you put here I would assume that selectedScript never gets initialized (always  eq. null). How do you know if the getter is called?


            I do not know the h:selectOneListbox in particular, but I had similar problems with h:selectOneMenu. The value of the UIComponent can be an instance of Script, but the s:selectItems had to be a List<SelectItem>. And you have to provide a Converter which can convert between the Script instance and the String representation and back. The setter can only be called with a Script as parameter, but your post event only has a String representation of the selcted item (value of the UIComponent). It's up to you to convert it back to a Script instance.



            Heri

            • 3. Re: selectOneListBox not calling setTarget
              Dean Hiller Expert

              I was using the debugger and it stopped in getter but never setter.


              This morning, I reset to an old implementation and it started working and then flipped back to my new implementation and it worked without any changes!!!  I can't figure out what I changed if anything or why it started working now.  so weird...I would have like to have known what I had wrong...maybe it was my environment or something...very odd, but it works now....same code as above...very weird.