4 Replies Latest reply on Aug 21, 2009 6:14 AM by smonty1

    Programmically resetting/clearing rich:pickList?

    smonty1

      Hi,
      I have a standard rich:pickList:

      <rich:pickList value="#{searchCriteria.bookList}" title="Books" id="BookPickList">
       <f:selectItems value="#{searchCriteria.booksDropList}" />
      </rich:pickList>
      


      Everything is working fine - I'm able to populate and receive information out without issue.

      I do however have, in my application a "Clear Search" button which is responsible for resetting all of search criteria (including my pickList) back to their default values. In the pickList's case I don't want to have any values selected for it.

      In my Clear Search action, I tried to do a bookList.clear(), bookList.remove() etc but this fails with a Java UnsupportedOperation item. Googling I found the reason (and a RichFaces JIRA item) was the RichFaces implementation behind the pickList used an immutable type Array$ArrayList so you can't manipulate it outside of the control.

      Attempting to use "this.bookList = new ArrayList()" in the Clear Search Action gives me the desired behaviour but the pickList selected items on the RHS box maintains the previous contents. How do I clear the RHS box? I've tried the usual Ajax rerendering without success? Can a programmatic manipulation (outside of the Richfaces control) be performed?

      Thanks,
      Stephen

        • 1. Re: Programmically resetting/clearing rich:pickList?
          ilya_shaikovsky

          Could you please check if the same clearance action used at h:command will works the same?

          Watch an issue you've found in jira to get updates on its resolution.

          • 2. Re: Programmically resetting/clearing rich:pickList?
            smonty1

            Hi Ilya,
            Thanks for your quick response.

            I see the rich:pickList UnsupportedOperation has been fixed and available in 3.3.2.CR1 http://www.mail-archive.com/richfaces-issues@lists.jboss.org/msg27945.html. I'll maybe have a look at that release, even though it's not deemed to be a stable release.

            I'm not sure what you meant when you said "Could you please check if the same clearance action used at h:command will works the same?" Could you please explain further?

            Thanks,
            Stephen.

            • 3. Re: Programmically resetting/clearing rich:pickList?
              ilya_shaikovsky

              To check the last snapshot where this fixed - seems best idea because 3.3.2 should be released soon and you will have no need in workarounds if it will works ok.

              I mean to place clearing action to some standard JSF control which perform regular submission, not Ajax one.

              • 4. Re: Programmically resetting/clearing rich:pickList?
                smonty1

                Hi Ilya,
                I've been playing around with this and it looks like I jumped the gun and am actually reporting the wrong issue - I'll go back to the start:

                1. I have a search criteria panel where users can select what information they want to search on. I want to allow the user to select one or more books from a large list. Given the large amount of selectable books I thought it best that the user is able to click on a link, get a modal panel popup with the the pickList on it. The user selects one or more books and then clicks OK to complete.

                <h:form>
                <a4j:outputPanel id="searchCriteriaAjax">
                 <rich:simpleTogglePanel label="Search Criteria" switchType="ajax">
                 <h:panelGrid columns="7" width="100%" >
                
                 <h:panelGroup>
                 <h:outputText value="#{msgs.books}" />
                 <rich:spacer width="3" />
                 <a4j:commandLink value="#{searchCriteria.booksLinkName}" id="editBooksLink">
                 <rich:componentControl for="selectBooksMPanel" attachTo="editBooksLink" operation="show" event="onclick" />
                 </a4j:commandLink>
                 </h:panelGroup>
                ...
                


                2. The modal panel code is below:
                <rich:modalPanel id="selectBooksMPanel" width="300" autosized="true" moveable="false" resizeable="false">
                 <h:form>
                 <h:panelGrid columns="1" width="100%">
                 <rich:pickList value="#{searchCriteria.bookList}" title="Books" id="BookPickList">
                 <f:selectItems value="#{searchCriteria.booksDropList}" />
                 </rich:pickList>
                
                 <f:facet name="footer">
                 <h:panelGroup style="display:block; text-align:center">
                 <a4j:commandButton value="OK" reRender="editBooksLink, searchCriteriaAjax"
                 action="#searchCriteria.updateBooks}" oncomplete="Richfaces.hideModalPanel('selectBooksMPanel')" />
                 </h:panelGroup>
                 </f:facet>
                 </h:panelGrid>
                ...
                


                I did some playing around with the rich:pickList and h:selectManyListbox and found that both widgets did not clear (when the user clicked on the Clear Search button) when the widgets were defined within the modalPanel popup. But both did when I moved the widget code out and defined in the "parent" Search Criteria panel... Make sense?

                Any suggestions on how to fix this?