1 Reply Latest reply on Mar 25, 2011 6:29 AM by Ilya Shaikovsky

    rich:suggestionbox - Passing values to other suggestion boxes

    Michael Hughes Newbie

      Looking for help to get pointed in the right direction. I'm currently working on a project where we have three suggestion boxes that are tied to each other within our database. Individually, the rich:suggestion boxes work perfectly (showing 3 columns with the fetchValue based on what inputText box you're searching). What I am unsure of doing (mainly because I'm not good at coding JavaScript) is how to pass the selected values to the other input fields? I'm assuming it is through JavaScript and not through the rich:suggestionbox attributes.suggestionBoxExample.jpg

       

       

      Here's my xhtml code for the suggestion boxes:

       

      [code]

       

      <s:decorate template="/layout/verticaldisplay.xhtml">

                  <ui:param

                    name="label"

                    value="Customer Name" />

                 <ui:param

                    name="underLabel"

                    value="(minimum 2 characters)"/>

                  <h:inputText

                    id="customerName"

                    value="#{gnvcustomerdataList.gnvcustomerdata.customerName}" />

                  <rich:suggestionbox

                    id="customerNameSBox"

                    for="customerName"

                    var="result"

                    fetchValue="#{result.customerName}"

                    suggestionAction="#{customerSearchBean.autocomplete}"

                    minChars="2"

                    nothingLabel="No customers found"

                    width="400"

                    height="250">

                    <h:column>

                      <h:outputText value="#{result.customerName}" />

                    </h:column>

                    <h:column>

                      <h:outputText value="#{result.customerAddress}" />

                    </h:column>

                    <h:column>

                      <h:outputText value="#{result.customerCity}" />

                    </h:column>

                  </rich:suggestionbox>

                </s:decorate>

       

                <s:decorate template="/layout/verticaldisplay.xhtml">

                  <ui:param

                    name="label"

                    value="Address" />

                 <ui:param

                    name="underLabel"

                    value="(minimum 2 chars)"/>

                  <h:inputText

                    id="customerAddress"

                    value="#{gnvcustomerdataList.gnvcustomerdata.id.customerAddress}" />

       

                  <rich:suggestionbox

                    id="customerAddressSBox"

                    for="customerAddress"

                    var="result"

                    fetchValue="#{result.customerAddress}"

                    suggestionAction="#{customerSearchBean.autocompleteCustAddr}"

                    minChars="2"

                    nothingLabel="No customers found"

                    bypassUpdates="true"

                    width="400"

                    height="250"

                    ignoreDupResponses="true">

                    <h:column>

                      <h:outputText value="#{result.customerAddress}" />

                    </h:column>

                    <h:column>

                      <h:outputText value="#{result.customerName}" />

                    </h:column>

                    <h:column>

                      <h:outputText value="#{result.customerCity}" />

                    </h:column>

                  </rich:suggestionbox>

       

                </s:decorate>

       

                <s:decorate template="/layout/verticaldisplay.xhtml">

                  <ui:param

                    name="label"

                    value="City" />

                 <ui:param

                    name="underLabel"

                    value="(Minimum three chars)"/>

                  <h:inputText

                    id="customerCity"

                    value="#{gnvcustomerdataList.gnvcustomerdata.id.customerCity}" />

       

                  <rich:suggestionbox

                    id="customerCitySBox"

                    for="customerCity"

                    var="result"

                    fetchValue="#{result.customerCity}"

                    suggestionAction="#{customerSearchBean.autocompleteCustCity}"

                    minChars="3"

                    nothingLabel="No customers found"

                    bypassUpdates="true"

                    width="400"

                    height="280"

                    ignoreDupResponses="true">

                    <h:column>

                      <h:outputText value="#{result.customerCity}" />

                    </h:column>

                    <h:column>

                      <h:outputText value="#{result.customerName}" />

                    </h:column>

                    <h:column>

                      <h:outputText value="#{result.customerAddress}" />

                    </h:column>

                  </rich:suggestionbox>

       

                </s:decorate>

      [/code]

        • 1. rich:suggestionbox - Passing values to other suggestion boxes
          Ilya Shaikovsky Master

          trye something like:

                      <h:inputText

                        id="customerName"

                        value="#{gnvcustomerdataList.gnvcustomerdata.customerName}" />

                      <rich:suggestionbox

                        id="customerNameSBox"

                        for="customerName"

                        var="result"

                        fetchValue="#{result.customerName}"

                        suggestionAction="#{customerSearchBean.autocomplete}"

                        minChars="2"

                        nothingLabel="No customers found"

                        width="400"

                        height="250">

          ...

                      </rich:suggestionbox>

                      <h:inputText

                        id="customerCity"

                        value="#{gnvcustomerdataList.gnvcustomerdata.id.customerCity}" />

           

                      <rich:suggestionbox

                        id="customerCitySBox"

                        for="customerCity"

                        var="result"

                        fetchValue="#{result.customerCity}"

                        suggestionAction="#{customerSearchBean.autocompleteCustCity}"

                        minChars="3"

                        nothingLabel="No customers found"

                        bypassUpdates="true"

                        width="400"

                        height="280"

                        ignoreDupResponses="true">

                         <a4j:actionparam noEscape="true" name="clientparamoffirstvalue" value="#{rich:element('customerName')}.value"/>

          ...

           

          that code in general should get current value for first input using JS and pass to server side. then you should be able to pick it from requestParametersMap in suggestion action.

           

          sorry not checked myself so please update me if there will be problems.