5 Replies Latest reply on Dec 22, 2009 1:34 PM by marian furdui

    seam validation + rich:suggestionbox

    marian furdui Newbie

      Hi!


      I have issues using the seam validation style and rich:suggestionbox.


      The issue is that the selected value from the rich:suggestionbox is not kept in the inputText, only the typed value is saved (on value selection from the rich:suggestionbox, the input text is refreshed to the typed value, probably the onblur event is called).



      <s:decorate id="testField" template="includes/edit.xhtml">
           <h:inputText id="testInput" value="#{valuation.model.identification}"
                required="#{true}" rendered="#{true}">
                <a:support event="onblur" reRender="testField" ajaxSingle="true"
                     bypassUpdates="true" />
           </h:inputText>
           <rich:suggestionbox id="suggestion" for="testInput" minChars="1"
                frequency="0" selfRendered="true" ignoreDupResponses="true"
                requestDelay="200" var="result" rendered="true" height="150"
                immediate="true" nothingLabel="#{messages.noProposalFound}"
                suggestionAction="#{valueList.suggest}">
                <f:facet name="header">
                     <h:outputText value="#{messages.proposals}" />
                </f:facet>
                <h:column>
                     <h:outputText value="#{result}" />
                </h:column>
           </rich:suggestionbox>
      </s:decorate>
      




      seam version=2.2.0.GA
      richfaces version=3.3.2.SR1





      edit.xhtml is modified to show the error message as a tooltip on the error icon:





          <div class="prop">
      
              <span class="value #{invalid?'errors':''}">
                  <s:validateAll>
                      <ui:insert/>
                  </s:validateAll>
              </span>
      
              <span class="error">
                  <h:graphicImage value="/img/error.gif" rendered="#{invalid}" styleClass="errors"/>
                  <rich:toolTip rendered="#{invalid}">
                       <s:message styleClass="errors"/>
                  </rich:toolTip>
              </span>
      
          </div>




      How to keep the selected value from the rich:suggestionbox in the inputText?


      Thank you!

        • 1. Re: seam validation + rich:suggestionbox
          Ilya Dyoshin Novice

          Have a look into forums.


          In general that value is defined via fetchValue property.


          Recently I've answered that questions on using suggestionbox My response


          Best regards,


          Ilya Dyoshin

          • 2. Re: seam validation + rich:suggestionbox
            marian furdui Newbie

            I saw the post you mention, but is is quite complicated, I need a more simplified structure and to use the s:decorate--edit.xhtml combination.


            Well I have added fetchValue but there is no change. Also I don't need a converter, because I need only the String value on an object from the list returned by the suggest action not the whole object.


            What else do you think it is missing from my code?


            Thanks again!

            • 3. Re: seam validation + rich:suggestionbox
              German Escobar Newbie

              Take a look at this code:




              <s:decorate id="decCountry" template="layout/edit.xhtml">               
                   <ui:define name="label">Country</ui:define>          
                   <h:inputText id="txtCountry" value="#{countriesBean.selectedCountry.name}">
                        <rich:suggestionbox id="suggestionBox" for="txtCountry" 
                                  fetchValue="#{country.name}"
                                  suggestionAction="#{countriesBean.autocomplete}" 
                                  var="country" minChars="2">
                             <h:column>
                                  <h:outputText value="#{country.name}" />
                             </h:column>
                             <a4j:support event="onselect">
                                  <f:setPropertyActionListener value="#{country}" target="#{countriesBean.selectedCountry}" />
                             </a4j:support>
                        </rich:suggestionbox>
                   </h:inputText>
              </s:decorate>




              And the bean would be:




              @Name("countriesBean")
              @Scope(ScopeType.CONVERSATION)
              public class CountriesBean {
              
                   private Country selectedCountry;
                   
                   public CountriesBean() {
                        selectedCountry = new Country();
                   }
                   
                   public List<Country> autocomplete(Object suggestion) {
                        // retrieve the countries
                   }
              
                   // getters and setters     
              }




              • 4. Re: seam validation + rich:suggestionbox
                Ilya Dyoshin Novice

                Hello German,


                Sorry, I've looked at your code and don't get it.


                You're about creating new object with the same name ? Or you're trying to bind selected object.


                If you want to have a user possible to select object with viewing the selected country name try following code:


                <s:decorate id="decCountry" template="layout/edit.xhtml">               
                     <ui:define name="label">Country</ui:define>          
                     <h:inputText id="txtCountry"/>
                
                        <rich:suggestionbox id="suggestionBox" for="txtCountry" 
                                    fetchValue="#{country.name}"
                                    suggestionAction="#{countriesBean.autocomplete}" 
                                    var="country" minChars="2">
                     <h:column>
                            <h:outputText value="#{country.name}" />
                     </h:column>
                     <a4j:support event="onselect" reRender="countryInfoOutput">
                     <f:setPropertyActionListener value="#{country}" target="#{countriesBean.selectedCountry}" />
                     </a4j:support>
                          </rich:suggestionbox>
                
                        <br />
                        Selected country is <h:outputText value="#{countriesBean.selectedCountry.name}" id="countryInfoOutput"/>
                </s:decorate>



                in your initial case you having problem with sonething I'd like to call "double binding":


                from one point of view the value of your textInput should be replaced by fetchValue from the other point of view - it is binded to the current selected bean Name property, nevertheless its the same value - for Richfaces its a problem - you're editing the object and when you selected you replaced the object with another one.


                the last outputText which outputs countriesBean.selectedCountry.name is used for outputing the selectedCountry name between non-ajax post requests.



                Regards! Let me know if this helped.


                Ilya Dyoshin

                • 5. Re: seam validation + rich:suggestionbox
                  marian furdui Newbie

                  Hi!


                  Yes it helped!


                  Found the workaround here as well: RF-7527


                  Thanks!