0 Replies Latest reply on Sep 30, 2011 10:36 AM by campos

    dynamic rich:suggestion

    campos

      Hello guys,

       

      (sorry about my english)

       

      This is my first post on richfaces forum, because I really needed to! All the problems that I've passed through I was able to solve with the existents discussion in this forum. So I'm running a project that create every component via Java (hard code). I know is kind of insane do that.

       

      I'm stuck with the suggestion because no mather what i've tried to implement it simply doesn't work with all the user requirements. Wich is an input for id and an input for description like the image below

      untitled.JPG

      The user want to fill the code and automatically fill the description OR fill the description wich is a suggestion and automatically fill the code.

      So, I have a class that create this set of components ( input for id, input for description and suggestion ) in my backbean I have a MAP attribute to hold the value of these components (becouse every component is made via hard code) this piece of code I have changed in so many ways trying to get it work FINE (user requirements) that I'm almost giving up!

       

      The GenericSuggestion.java is the class that generate the set of components showed on image. *attached

       

      In my xhtml page i have a panel with a binding to a method of my backbean

       

      <h:panelGrid id="renderPanel" binding="#{geradorRelatorioManagerBean.renderPanel}"/>
      

       

      On my backbean piece of code that add the components to the panel

       

      putComponentOnMap("desc"+par.getNome(), null); //to hold the value of component
      UnimedSuggestion unimed = new UnimedSuggestion(par);
      putComponentOnMap("sggParam_"+par.getNome(), unimed.getObjeto()); //control params
      renderPanel.getChildren().add(unimed.buildComponent());
      

       

       

      The user requirements is

      * when fill the code automatically fill description

      * when fill the description (suggestion) automatically fill the code

      * when empty the code automatically empty description

      * when empty description automatically empty code

       

      It is almost workig but with little issues like

      * when I select the option in suggestion with mouse it broke

      * when the box of suggestion is opened the user click outside the box without selecting an option it broke

      * if i write something that doesn't exist in the list in the description input and hit TAB before box with options appears it broke

      * if a have two objects in the list and change one of then it is always picking up the first on in the list. This happens becouse I'm unable to dynamic set the id of the object in my backbean so, the method gets the text in the description and query in database obviously it get the first ocurrence.

       

      So, can anyone helo with this issues.

       

      I have made a tag that do all these things but in xhtml and some things that I do in code in this tag I can't do with hard code

       

      this is the code of my tag that is working:

       

       

      <ui:composition>
                <a4j:outputPanel id="panelUnimed#{id}">
                          <ui:decorate template="edit.xhtml">
                                    <ui:param name="idComponente" value="#{id}" />
                                    <ui:param name="cssColumnClasses" value="#{cssColumnClassesOpt}" />
                                    <ui:define name="label">#{label}</ui:define>
                                    <h:inputText id="#{id}" title="C&#243;digo #{unimedOptComponentBean.titulo(label, title)}"
                                              value="#{valueCodUnimed}" size="4" maxlength="3"
                                              requiredMessage="#{requiredMessage}" readonly="#{readonly}"
                                              required="#{required}"
                                              disabled="#{disabled}"
                                              rendered="#{rendered != null ? rendered : 'true'}"
                                              styleClass="#{validationUtil.invalid(id, facesContext) ? 'invalido' : ''} #{styleClass}"
                                              onkeypress="return(soEntraNumero(event,this)); #{onkeypress}" 
                                              onblur="soArrastaNumero(this); #{onblur}">
                                              <a4j:support event="onchange" immediate="true"
                                                        ignoreDupResponses="true" eventsQueue="componentUnimed"
                                                        requestDelay="500" limitToList="true" reRender="#{reRender}"
                                                        action="#{unimedOptComponentBean.findByKey}" ajaxSingle="true">
                                                        <f:setPropertyActionListener
                                                                  target="#{unimedOptComponentBean.panelId}"
                                                                  value="panelUnimed#{id}" />
                                                        <f:setPropertyActionListener
                                                                  target="#{unimedOptComponentBean.labelInvisivel}"
                                                                  value="#{labelInvisivel==null ? '' : labelInvisivel}" />
                                                        <f:setPropertyActionListener
                                                                  target="#{unimedOptComponentBean.nomeComponente}"
                                                                  value="#{unimedOptComponentBean.defineNomeComponente(label)}" />
                                                        <a4j:actionparam noEscape="true"
                                                                  value="jQuery(this).val() == '' ? '-11111' : jQuery(this).val()"
                                                                  assignTo="#{unimedOptComponentBean.codUnimed}" />
                                                        <a4j:support event="oncomplete" ajaxSingle="true" focus="#{valueCodUnimed == null ? '' : focus}"
                                                                  eventsQueue="componentUnimed"
                                                                  reRender="#{id}, nomeUnimed#{id}, suggestionUnimed#{id}, #{reRenderOncomplete}">
                                                                  <f:setPropertyActionListener target="#{valueCodUnimed}"
                                                                            value="#{unimedOptComponentBean.codUnimed}" />
                                                                  <f:setPropertyActionListener target="#{valueNomeAbrev}"
                                                                            value="#{unimedOptComponentBean.nomeAbrev}" />
      
      
                                                        </a4j:support>
                                              </a4j:support>
                                    </h:inputText>
      
      
                                    <a4j:region>
                                              <h:inputText id="nomeUnimed#{id}" title="Nome #{unimedOptComponentBean.titulo(label, title)}"
                                                        value="#{valueNomeAbrev}" size="35" readonly="#{readonly}"
                                                        disabled="#{disabled}"
                                                        maxlength="26" required="#{required}"
                                                        rendered="#{rendered != null ? rendered : 'true'}"
                                                        requiredMessage="#{requiredMessage}"
                                                        styleClass="#{validationUtil.invalid(id, facesContext) ? 'invalido' : ''} #{styleClass}">
                                                        <a4j:support event="onchange" immediate="true"
                                                                  ignoreDupResponses="true" eventsQueue="componentUnimed"
                                                                  requestDelay="500" limitToList="true" 
                                                                  action="#{unimedOptComponentBean.autoCompleteUnimed(valueNomeAbrev)}"
                                                                  ajaxSingle="true">
                                                                  <f:setPropertyActionListener
                                                                            target="#{unimedOptComponentBean.panelId}"
                                                                            value="panelUnimed#{id}" />
                                                                  <f:setPropertyActionListener
                                                                            target="#{unimedOptComponentBean.nomeComponente}"
                                                                            value="#{unimedOptComponentBean.defineNomeComponente(label)}" />
                                                                  <a4j:actionparam noEscape="true"
                                                                            value="jQuery(this).val() == '' ? '-11111' : jQuery(this).val()"
                                                                            assignTo="#{unimedOptComponentBean.nomeAbrev}" />
                                                                  <a4j:support event="oncomplete" ajaxSingle="true"
                                                                            reRender="nomeUnimed#{id}">
                                                                            <f:setPropertyActionListener target="#{valueCodUnimed}"
                                                                                      value="#{unimedOptComponentBean.codUnimed}" />
                                                                            <f:setPropertyActionListener target="#{valueNomeAbrev}"
                                                                                      value="#{unimedOptComponentBean.nomeAbrev}" />
                                                                            <a4j:support event="oncomplete" limitToList="true"
                                                                                      ajaxSingle="true" reRender="#{id}, suggestionUnimed#{id}, #{reRender}, #{reRenderOncomplete}"
                                                                                      focus="#{valueCodUnimed == null ? '' : focus}" />
      
      
                                                                  </a4j:support>
                                                        </a4j:support>
                                              </h:inputText>
                                              <rich:suggestionbox id="suggestionUnimed#{id}" for="nomeUnimed#{id}"
                                                        nothingLabel="Nenhum registro encontrado."
                                                        suggestionAction="#{unimedOptComponentBean.autoCompleteUnimed}"
                                                        var="_unimed" width="350" height="300" minChars="2"
                                                        requestDelay="800" frequency="0.1">
                                                        <h:column>
                                                                  <h:outputText value="#{_unimed.nomeAbrev}" />
                                                        </h:column>
                                                        <h:column>
                                                                  <h:outputText value="#{_unimed.codUnimed}" />
                                                        </h:column>
                                                        <a4j:support event="onselect" ajaxSingle="true"
                                                                  limitToList="true">
                                                                  <f:setPropertyActionListener
                                                                            target="#{unimedOptComponentBean.codUnimed}"
                                                                            value="#{_unimed.codUnimed}" />
                                                                  <f:setPropertyActionListener
                                                                            target="#{unimedOptComponentBean.nomeAbrev}"
                                                                            value="#{_unimed.nomeAbrev}" />
                                                                  <f:setPropertyActionListener target="#{valueCodUnimed}"
                                                                            value="#{_unimed.codUnimed}" />
                                                                  <f:setPropertyActionListener target="#{valueNomeAbrev}"
                                                                            value="#{_unimed.nomeAbrev}" />
                                                                  <f:setPropertyActionListener
                                                                            target="#{unimedOptComponentBean.panelId}"
                                                                            value="panelUnimed#{id}" />
                                                                  <a4j:support event="oncomplete" focus="#{focus}" 
                                                                            reRender="#{id}, nomeUnimed#{id}, suggestionUnimed#{id}, #{reRender}" />
                                                        </a4j:support>
                                              </rich:suggestionbox>
                                    </a4j:region>
                          </ui:decorate>
                </a4j:outputPanel>
      </ui:composition>
      
      

       

      But in hard code I can't do things like this: in a4jsupport put the

      <a4j:support .... >

      <f:setPropertyActionListener  target="#{unimedOptComponentBean.panelId}" value="panelUnimed#{id}" />

      </a4j:support>

       

      If I could do this via hard code I will be able to solve most of my problems!

       

      Thanks and sorry for the big post!