2 Replies Latest reply on Jun 3, 2012 6:32 PM by Val Sw

    richfaces suggestionbox clears previous values on update screen

    Val Sw Expert



      We are using Richfaces (3.3.1 GA) , EJB3 in seam application

      I followed the second example to store id in database http://livedemo.exadel.com/richfaces-demo/richfaces/suggestionBox.jsf?c=suggestionBox

      This suggestion box displays data from web-service and we are storing name and id in database.


      It works fine during Create but facing issue during update screen.


      Summary :

      a) Suggestions are displayed from webservice correctly and as soon as user selects value from dropdown, javascript function "printObjectsSelectedTest" is called which gets the corresponding userId and displays in inputTextarea (showing for testing only).


      b) So, on update screen default value in h:inputTextarea is displayed from database (bean #{info.userId})  as it is bind to bean class.


      Issue : If user types anything in suggestion box using token to add new suggestion value, suggestions are displayed correctly but inputTextarea gets cleared.

      I came across some posts suggesting to use ajax support with f:setPropertyActionListener during onselect...

      But, I am not sure how it will behave if user selects and the value and press back-space to delete it.


      Is there any trick doing it from javascript, may be with-in printObjectsSelected ? OR any better way around.



      <script type="text/javascript">
                function printObjectsSelected(output, sgcomponent){
                          output.innerHTML = sgcomponent.getSelectedItems().pluck('uId');
      <h:inputText value="#{info.person}" id="personId" required="true">
      <rich:suggestionbox     usingSuggestObjects="true" 
           onobjectchange="printObjectsSelected(#{rich:element('objects')}, #{rich:component('suggestion')});"
           suggestionAction="#{bean.autocomplete}" var="cap" minChars="3" ajaxSingle="true"
           for="personId" fetchValue="#{cap.personName}" id="suggestion" tokens=",">
                <h:outputText value="#{cap.personName} | #{cap.uId}">                         
      <h:inputTextarea value="#{info.userId}" id="objects"/>


      Thanks for your help.