1 2 Previous Next 16 Replies Latest reply: Feb 5, 2013 8:03 AM by Tshifhiwa RSS

    return two values for inputtext autosuggest

    Tshifhiwa
      hi i have inputtext with autosuggest,i what to return two values when i select the values for example if i select cityname i must return cityname and citypostacode for that city.this is how i did my inputtext autosuggest
      <af:inputText label="#{bindings.Cityname.hints.label}" columns="20"
                                              maximumLength="#{bindings.Cityname.hints.precision}"
                                              id="itc4" simple="true"
                                            value="#{pageFlowScope.orgDetailsBean.addressBean.city}"
                                            partialTriggers="it19" autoSubmit="true"
                                            shortDesc="Enter City Name Or Click Refresh To re-enter City Name">
                                  <af:autoSuggestBehavior suggestedItems="#{pageFlowScope.addressbean.oncitySuggest}"/>
                              <af:autoSuggestBehavior/>
                            </af:inputText>
      
          public List oncitySuggest(String searchCityName) {
          ArrayList<SelectItem> selectItems = new ArrayList<SelectItem>();
              searchCityName = searchCityName.toUpperCase();
          System.out.println(searchCityName);
          //get access to the binding context and binding container at runtime
          BindingContext bctx = BindingContext.getCurrent();
          BindingContainer bindings = bctx.getCurrentBindingsEntry();
          //set the bind variable value that is used to filter the View Object
          //query of the suggest list. The View Object instance has a View
          //Criteria assigned
          OperationBinding setVariable = (OperationBinding) bindings.get("setBind_city");
          setVariable.getParamsMap().put("value", searchCityName);
          setVariable.execute();
          //the data in the suggest list is queried by a tree binding.
          JUCtrlHierBinding hierBinding = (JUCtrlHierBinding) bindings.get("CityViewLOV1");
      
      
          //re-query the list based on the new bind variable values
          hierBinding.executeQuery();
      
          //The rangeSet, the list of queries entries, is of type
          //JUCtrlValueBndingRef.
          List<JUCtrlValueBindingRef> displayDataList = hierBinding.getRangeSet();
      
          for (JUCtrlValueBindingRef displayData : displayDataList){
          Row rw = displayData.getRow();
          //populate the SelectItem list
          selectItems.add(new SelectItem(
          (String)rw.getAttribute("Cityname"),
          (String)rw.getAttribute("Citycode")));
          }
      
          return selectItems;
          }
      Edited by: adf009 on 2013/01/31 12:06 PM
        • 1. Re: return two values for inputtext autosuggest
          umesh.agarwal
          Instead of the below code:
           selectItems.add(new SelectItem(
              (String)rw.getAttribute("Cityname"),
              (String)rw.getAttribute("Citycode")));
              }
          You can use the below code to return both CityName and City code.
           selectItems.add(new SelectItem(
              (String)rw.getAttribute("Cityname") + " - " + 
              (String)rw.getAttribute("Citycode"),
              (String)rw.getAttribute("Cityname") + " - " + 
              (String)rw.getAttribute("Citycode")));
              }
          • 2. Re: return two values for inputtext autosuggest
            Tshifhiwa
            ok than but how can i link or attach the citycode with its own inputtext,i don't what the citycode/postalcode to be return in the same inputtext with the surbub name.the list must list cityname-prostalcode but on return each must be attach to its own inpputtext currently the above code is returning all in one inputtext
            <af:inputText
                                                label="#{bindings.postalCode.hints.label}"
                                                required="#{bindings.postalCode.hints.mandatory}"
                                                columns="10"
                                                maximumLength="#{bindings.postalCode.hints.precision}"
                                                shortDesc="#{bindings.postalCode.hints.tooltip}"
                                                id="it5" simple="true"
                                                value="#{pageFlowScope.orgDetailsBean.addressBean.postalCode}">
                                    <f:validator binding="#{bindings.postalCode.validator}"/>
                                  </af:inputText>
            is there a way i can linkn my pageFlowScope.orgDetailsBean.addressBean.postalCode with the  (String)rw.getAttribute("Postalcode")));
            my class is
            
            public class AddressBean {
                public AddressBean() {
                    super();
                }
             private String suburb;
             private String postalCode;
                public void setSuburb(String suburb) {
                    this.suburb = suburb;
                }
            
                public String getSuburb() {
                    return suburb;
                }
                public void setPostalCode(String postalCode) {
                    this.postalCode = postalCode;
                }
            
                public String getPostalCode() {
                    return postalCode;
                }
                public List onSuburbuSuggest(String searchSububName) {
                ArrayList<SelectItem> selectItems = new ArrayList<SelectItem>();
                searchSububName = searchSububName.toUpperCase();
                System.out.println(searchSububName);
                //get access to the binding context and binding container at runtime
                BindingContext bctx = BindingContext.getCurrent();
                BindingContainer bindings = bctx.getCurrentBindingsEntry();
                //set the bind variable value that is used to filter the View Object
                //query of the suggest list. The View Object instance has a View
                //Criteria assigned
                OperationBinding setVariable = (OperationBinding) bindings.get("setsubub");
                setVariable.getParamsMap().put("value", searchSububName);
                setVariable.execute();
                //the data in the suggest list is queried by a tree binding.
                JUCtrlHierBinding hierBinding = (JUCtrlHierBinding) bindings.get("SuburbViewLOV1");
            
            
                //re-query the list based on the new bind variable values
                hierBinding.executeQuery();
            
                //The rangeSet, the list of queries entries, is of type
                //JUCtrlValueBndingRef.
                List<JUCtrlValueBindingRef> displayDataList = hierBinding.getRangeSet();
            
                for (JUCtrlValueBindingRef displayData : displayDataList){
                Row rw = displayData.getRow();
                //populate the SelectItem list
                selectItems.add(new SelectItem(
                   (String)rw.getAttribute("Suburb") + " - " + 
                   (String)rw.getAttribute("Postalcode")));
                }
            
                return selectItems;
                }
            }
            Edited by: adf009 on 2013/01/31 3:15 PM
            
            Edited by: adf009 on 2013/01/31 3:22 PM
            
            Edited by: adf009 on 2013/02/01 9:21 AM
            
            Edited by: adf009 on 2013/02/01 9:27 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
            • 3. Re: return two values for inputtext autosuggest
              umesh.agarwal
              how can i link or attach the citycode with its own inputtext
              While defining LOV, in the Configuration tab of Edit List of Values Wizard, go to List Return Values section and add one more attribute. There you can map your city code.
              the list must list cityname-prostalcode but on return each must be attach to its own inpputtext currently the above code is returning all in one inputtext
              To return the City Name in its input text, you can modify the code as below:
              selectItems.add(new SelectItem(
                  (String)rw.getAttribute("Cityname"),
                  (String)rw.getAttribute("Cityname") + " - " + 
                  (String)rw.getAttribute("Citycode")));
                  }
              • 4. Re: return two values for inputtext autosuggest
                Tshifhiwa
                am not using lov am using inputtext outosuggest
                <af:inputText label="#{bindings.Suburb.hints.label}" columns="20"
                                                        maximumLength="#{bindings.Suburb.hints.precision}"
                                                        id="itcs4" simple="true"
                                                     value="#{pageFlowScope.orgDetailsBean.addressBean.suburb}" partialTriggers="it19"
                                                     shortDesc="Enter Suburb Name Or Click Refresh To Re-enter Subub Name"
                                                     autoSubmit="true">
                                            <af:autoSuggestBehavior suggestedItems="#{pageFlowScope.addressbean.onSuburbuSuggest}"/>
                                          </af:inputText>
                
                <af:inputText
                                                    label="#{bindings.postalCode.hints.label}"
                                                    required="#{bindings.postalCode.hints.mandatory}"
                                                    columns="10"
                                                    maximumLength="#{bindings.postalCode.hints.precision}"
                                                    shortDesc="#{bindings.postalCode.hints.tooltip}"
                                                    id="it5" simple="true"
                                                    value="#{pageFlowScope.orgDetailsBean.addressBean.postalCode}">
                                        <f:validator binding="#{bindings.postalCode.validator}"/>
                                      </af:inputText>
                • 5. Re: return two values for inputtext autosuggest
                  umesh.agarwal
                  In that case, you can programmatically return/set the postal code as your postal code input text component is bounded to a managed bean.
                  • 6. Re: return two values for inputtext autosuggest
                    Tshifhiwa
                    how can i programmatically return/set the postal code as my postal code input text component which is bounded to a managed bean.i have attach my class above
                    • 7. Re: return two values for inputtext autosuggest
                      umesh.agarwal
                      This is a rough code, I haven't tried though.
                      1. Define a valueChangeListener method for your input text(City Name). So whenever you select a value using auto Suggest, this method will get fired.
                      2. In the valueChangeListener method, get hold of the CityViewLOV1 Iterator.
                      3. Set the current Row in the iterator with the newly selected value(i.e valueChangeEvent.getNewValue())
                      4. Get hold of the current Row in the iterator.
                      5. Get the Postal code attribute and set to the managed bean property bound to the postal code input text.
                      6. Partially refresh the postal code input text component.

                      Your code will be something like this:
                      public void onCityChange(ValueChangeEvent valueChangeEvent) {
                              if (valueChangeEvent.getNewValue() == valueChangeEvent.getOldValue()) {
                                  return;
                              }
                              String cityName = valueChangeEvent.getNewValue().toString();
                               DCIteratorBinding dcIterator = ADFUtils.findIterator("CityViewIterator");
                               if (dcIterator != null) {
                                      dcIterator.setCurrentRowWithKeyValue(socValue);
                                      Row currentRow = dcIterator.getCurrentRow();
                                      String postalCode = currentRow.getAttribute("PostalCode");
                                      //Set the postal code
                                      addressBean.setpostalCode(postalCode);
                                      AdfFacesContext.getCurrentInstance().addPartialTarget(<Postal Code Input text component binding>)
                      
                               }
                      
                      
                      }
                      • 8. Re: return two values for inputtext autosuggest
                        Tshifhiwa
                        ok am editing ur code where is this define
                        socValue in
                        dcIterator.setCurrentRowWithKeyValue(socValue);
                        • 9. Re: return two values for inputtext autosuggest
                          umesh.agarwal
                          Ooops. Its cityName string not socValue. Replace socValue with cityName
                          • 10. Re: return two values for inputtext autosuggest
                            Tshifhiwa
                            ok is this the id name of postalcode
                            where is this come from inputText in
                            AdfFacesContext.getCurrentInstance().addPartialTarget(inputText);
                            
                            is that the id name inputtext of postal code
                             id="it5"
                             when i run the code must i have this
                                selectItems.add(new SelectItem(
                                   (String)rw.getAttribute("Suburb") + " - " + 
                                   (String)rw.getAttribute("Postalcode")));
                                   //(String)rw.getAttribute("Suburb") + " - " + 
                                   //(String)rw.getAttribute("Postalcode")));
                            
                            or this
                                   // selectItems.add(new SelectItem(
                                (String)rw.getAttribute("Suburb"),
                                (String)rw.getAttribute("Postalcode"),
                                (String)rw.getAttribute("Citycode")));
                            Edited by: adf009 on 2013/02/05 2:25 PM

                            Edited by: adf009 on 2013/02/05 2:27 PM

                            Edited by: adf009 on 2013/02/05 2:27 PM

                            Edited by: adf009 on 2013/02/05 2:28 PM

                            Edited by: adf009 on 2013/02/05 2:34 PM
                            • 11. Re: return two values for inputtext autosuggest
                              umesh.agarwal
                              Your valueChangeListener code will be
                              public void onCityChange(ValueChangeEvent valueChangeEvent) {
                                      if (valueChangeEvent.getNewValue() == valueChangeEvent.getOldValue()) {
                                          return;
                                      }
                                      String cityName = valueChangeEvent.getNewValue().toString();
                                       DCIteratorBinding dcIterator = ADFUtils.findIterator("CityViewIterator");
                                       if (dcIterator != null) {
                                              dcIterator.setCurrentRowWithKeyValue(cityName);
                                              Row currentRow = dcIterator.getCurrentRow();
                                              String postalCode = currentRow.getAttribute("PostalCode");
                                              //Set the postal code
                                              addressBean.setpostalCode(postalCode);
                                              AdfFacesContext.getCurrentInstance().addPartialTarget(<Postal Code Input text component binding>)
                                        }
                              }
                              AdfFacesContext.getCurrentInstance().addPartialTarget() is used to partially refresh the component.

                              In your autoSuggest method as I have told earlier you should have,
                              selectItems.add(new SelectItem(
                                  (String)rw.getAttribute("Cityname"),
                                  (String)rw.getAttribute("Cityname") + " - " + 
                                  (String)rw.getAttribute("Citycode")));
                                  }
                              • 12. Re: return two values for inputtext autosuggest
                                Tshifhiwa
                                ok this is my code so far
                                    public void onCityname(ValueChangeEvent valueChangeEvent) {
                                        String postalcode = null;
                                        if (valueChangeEvent.getNewValue() == valueChangeEvent.getOldValue()) {
                                                   return;
                                               }
                                               String cityName = valueChangeEvent.getNewValue().toString();
                                                DCIteratorBinding dcIterator = ADFUtils.findIterator("BeanIterator1");
                                                if (dcIterator != null) {
                                                       dcIterator.setCurrentRowWithKeyValue(cityName );
                                                       Row currentRow = dcIterator.getCurrentRow();
                                                       postalcode = (String)currentRow.getAttribute("PostalCode");                       
                                                       
                                                       //Set the postal code
                                                       setPostalCode(postalCode);                  
                                                       AdfFacesContext.getCurrentInstance().addPartialTarget(where do i get the value i must put hear,where is it define);
                                        
                                                }
                                    }
                                Edited by: adf009 on 2013/02/05 2:46 PM

                                Edited by: adf009 on 2013/02/05 2:52 PM

                                Edited by: adf009 on 2013/02/05 3:47 PM
                                • 13. Re: return two values for inputtext autosuggest
                                  umesh.agarwal
                                  AdfFacesContext.getCurrentInstance().addPartialTarget(where do i get the value i must put hear,where is it define);
                                  Define a binding for your postal code input text component. The binding name will go as parameter in the above method call.
                                  • 14. Re: return two values for inputtext autosuggest
                                    Tshifhiwa
                                    you mean this id
                                    this is giving error
                                     AdfFacesContext.getCurrentInstance().addPartialTarget(postalCode);
                                    <attributeValues IterBinding="addressBeanIterator1" id="postalCode">
                                          <AttrNames>
                                            <Item Value="postalCode"/>
                                          </AttrNames>
                                        </attributeValues>
                                    Edited by: adf009 on 2013/02/05 3:33 PM
                                    1 2 Previous Next