4 Replies Latest reply on Feb 27, 2009 7:00 AM by Alan Gross

    concept question - suggestionBox - return value after select

    Alan Gross Newbie

      Hi Forum
      I'm a bit confused about how to use suggestionBox correctly.

      Use case description:
      I'm working on a time reporting solution. When creating a time report I want to provide a list of projects.

      Datamodel:
      -timereports
      -- timereports.projectId
      --- projects.projectId
      --- projects.projectName
      (table timereports is related to table projects by field projectId (integer))

      The backing bean is called "timerepHandler".
      "timerepHandler" is instantiating a POJO "createReport"(timereports).

      In the backing bean I create a ArrayList containing the project objects.
      The suggestionBox is listing the projects using the projectName.

      Now is the question how the value is returned back to the input field. And also to what backing bean entity the input field is referencing.

      - returned value = createReport.project.projectId
      or
      - returned value = createReport.project.projectName
      or the whole object? returned value = createReport.project

      Into what entity of the backing bean?
      - a String that can be used to reselect the correct project when inserting the timereport record?
      or
      - createReport.project.projectId
      or
      - createReport.project.projectName
      or
      - createReport.project (-> best solution from my point of view, but how to display this value readable??)


      At the end I wan't to insert the timereport with a valid reference to a project (using the projectId). The projectId is a integer value, that i never want to show to the user. It's just the technical record identifier. So the ID is not displayed in the list and it is not displayed in the input field of the suggestion box (after selection). But from where do I get the identifier afterwords?

      Thank you very much for a hint!

        • 1. Re: concept question - suggestionBox - return value after se
          Nick Belaevski Master

          Hello,

          There is "fetchValue" attribute defining expression to evaluate in order to get input value.

          • 2. Re: concept question - suggestionBox - return value after se
            Alan Gross Newbie

             

            "nbelaevski" wrote:

            There is "fetchValue" attribute defining expression to evaluate in order to get input value.


            Hi Nick

            Maybe I described the scenario a bit too complicated. I try it again.
            Actually I already use the "fetchValue" Attribute.


            With the fetchValue attribute I am able to pass back a value to the inputText component. In this case this will be the contact full name (first/last).
            At the moment when the user selects from the suggestionbox I have access to the whole project-object. Beside of the contact full name I would like to assign the contact-Id to a backing bean property.

            How can I achieve this?

            Here is my code (works fine so far for the contact full name):

            <h:outputLabel value="#{cont.lblProjectResponsible }" />
             <h:panelGrid columns="2">
             <h:panelGrid columns="2" border="0" cellpadding="0"
             cellspacing="0">
             <h:inputText style="margin:0px;"
             value="#{projectHandler.projectCreateResponsible}"
             disabled="false" id="responsibleInput"/>
             <h:graphicImage
             value="#{facesContext.externalContext.requestContextPath}/../images/arrow.png"
             onclick="#{rich:component('suggestionResponsible')}.callSuggestion(true)"
             alt="" />
             </h:panelGrid>
             <h:outputText id="responsiblesSuggested" style="font-weight:bold" />
             </h:panelGrid>
            
             <rich:suggestionbox height="200" width="200"
             usingSuggestObjects="false"
             nothingLabel="No contacts found"
             onobjectchange="printObjectsSelected(#{rich:element('responsiblesSuggested')},#{rich:component('suggestionResponsible')});"
             suggestionAction="#{projectHandler.responsibleAutocomplete}"
             var="resp" for="responsibleInput"
             fetchValue="#{resp.firstName} #{resp.lastName}"
             id="suggestionResponsible" tokens=",">
             <h:column>
             <h:graphicImage value="../.././images/icon_person.jpg" />
             </h:column>
             <h:column>
             <h:outputText value="#{resp.firstName} #{resp.lastName}" />
             </h:column>
             <h:column>
             <h:outputText value="#{resp.contactId}" />
             </h:column>
             </rich:suggestionbox>
            


            Thank you very much for your help!
            Regards
            Alan

            • 3. Re: concept question - suggestionBox - return value after se
              Alan Gross Newbie

               

              "alan79" wrote:
              ... I have access to the whole project-object...


              Sorry. I messed up with project / contact example. I meant here the contact-object NOT project-object.

              It is actually the same use case... it's always about record.Id and record.name...

              • 4. Re: Solution found! - concept question - suggestionBox - ret
                Alan Gross Newbie

                Found myself the solution:

                <rich:suggestionbox height="200" width="200"
                 usingSuggestObjects="false"
                 nothingLabel="No contacts found"
                 onobjectchange="printObjectsSelected(#{rich:element('responsiblesSuggested')},#{rich:component('suggestionResponsible')});"
                 suggestionAction="#{projectHandler.responsibleAutocomplete}"
                 var="resp" for="responsibleInput"
                 fetchValue="#{resp.firstName} #{resp.lastName} (#{resp.contactId})"
                 id="suggestionResponsible" tokens=",">
                 <h:column>
                 <h:graphicImage value="../.././images/icon_person.jpg" />
                 </h:column>
                 <h:column>
                 <h:outputText value="#{resp.firstName} #{resp.lastName}" />
                 </h:column>
                 <h:column>
                 <h:outputText value="#{resp.contactId}" />
                 </h:column>
                 <a4j:support event="onselect" action="#{projectHandler.responsibleSelect}">
                
                 <f:setPropertyActionListener value="#{resp.contactId}" target="#{projectHandler.projectCreateResponsibleId}" />
                
                 </a4j:support>
                 </rich:suggestionbox>