1 Reply Latest reply on Jan 20, 2011 11:07 PM by Mihai Poplacenel

    Potential bug in selectOneMenu reRendering

    Mihai Poplacenel Newbie

      I have the following code:

       

      {code}

                    <h:panelGrid columns="2" columnClasses="col1,col2">

                      <rich:panel id="treePanelId">

                        <rich:tree style="width:100%; height: 100%;" 

                            ajaxSubmitSelection="true" ajaxSingle="true"

                            switchType="client"

                            var="item"

                            nodeFace="#{item.type}"

                            value="#{myBean.treeNode}"

                            ajaxKeys="#{null}">

                        <rich:treeNode type="xxx"

                            nodeSelectListener="#{myBean.processTreeSelection}" reRender="detailsPanelId" >

                          <h:outputText value="#{item.value}"/>

                        </rich:treeNode>

                        <rich:treeNode type="yyy">

                          <h:outputText value='#{item.type}=#{item.value}' nodeSelectListener="#{null}"/>

                        </rich:treeNode>

                        <rich:treeNode>

                          <h:outputText value='WTF! #{item.type}=#{item.value}' nodeSelectListener="#{null}"/>

                        </rich:treeNode>

                      </rich:tree>               

                      </rich:panel>

                      <rich:panel id="detailsPanelId">

                        <rich:panel header="Samples" id="selectPanelId">

                          <a4j:region>

                            <h:selectOneMenu label="Select Item" id="selectFieldId" value="#{myBean.selectedItemId}"

                                valueChangeListener="#{myBean.changeSelection}">

                              <f:selectItems value="${myBean.selectItems}"/>

                              <a4j:support event="onchange" reRender="requestPanelId"/>

                            </h:selectOneMenu>

                          </a4j:region>

                          <a4j:outputPanel layout="none" id="requestPanelId">

                            <h:inputTextarea label="Sample Request" id="sampleFieldId" value="#{myBean.myRequest}"

                              rows="8" cols="80"/>

                          </a4j:outputPanel>

                        </rich:panel>

                      </rich:panel>

                    </h:panelGrid>

       

      {code}

      As I keep clicking the tree, the backing bean resets selectedItemId to empty string "". The 'myBean.selectItems' property includes an entry with "-- New --" as the display and "" as the value. My backing bean is request-scoped, with an a4j:keepAlive defined earlier in the page.

       

      Since a tree selection sets the value of the SELECT back to "", I would expect to see the drop-down repositioned to an empty string. Unfortunately though, this only happens if I select something from the drop-down after repositioning in the tree. In other words, the following sequence works:

      • click tree node TN1
      • change drop-down selection to non-empty "A1"
      • click tree node TN2
      • change drop-down selection to non-empty "B1"
      • click back TN1
      • Expected: empty ("-- New --") ; actual: -- New -- (CORRECT)

      The following scenario fails, though:

      • click tree node TN1
      • change drop-down selection to non-empty A1
      • click tree node TN2
      • skip step: change drop-down selection to non-empty "B1"
      • click back TN1
      • Expected: empty ("-- New --") ; actual: A1 (INcorrect)
      •  

      I'm using RichFaces 3.3.Final with JSF 2.0.2 (in backwards-compatible mode as RichFaces requires).

        • 1. Re: Potential bug in selectOneMenu reRendering
          Mihai Poplacenel Newbie

          I've actually figured that if the value in the drop-down is part of the new select item list, the list won't update its selected value. There's probably some optimization somewhere that checks if the value is the same and doesn't re-render it. In my case above, skipping the selection means the value is left at empty, which is part of the new select item list (as it's part of *all* of them). I've confirmed this as as one wonders off to other nodes in the tree and comes back, the old value is again displayed (in other words it stays "sticky", it hangs onto the underlying select control).

           

          Given this, any idea how I can work around this issue?

          1 of 1 people found this helpful