1 2 Previous Next 17 Replies Latest reply: Jul 31, 2013 7:36 AM by vinaykumar2 RSS

    adding new option in selectonechoice

    webcentercontentnewbie

      Hi All,

       

       

      I am using jdev 11.1.1.5 .

       

      I am showing selectonechoice on base of some query. I need to add a new option as ALL .so that user can select all..

       

      How to achieve this. I have to also display please select in the selectonechoice. Any suggestion

        • 1. Re: adding new option in selectonechoice
          Timo Hahn

          This question sounds familiar...

           

          What should the 'ALL' do in a selectOneChoice?

           

          Not sure you can set a watermark to a select one choice (not even with javascript). Why don't you make it mandatory. This would have the same effect.

           

          Timo

          • 2. Re: adding new option in selectonechoice
            931325

            Hi,

            As Timo said, the 'ALL' option in selectOneChoice doesn't make much sense.

             

            However, if you want to add 'ALL' just as constant value apart from the other values fetched by your query, then you can programatically do it by building your selectItems of your selectOneChoice by binding a List<SelectItem> from your bean which in turn is populated based on your query.  But before looping through your values and populating the list, you can add 'ALL' as a static option to the top of the list and handle the logic behind ALL selection in your code.  Or, instead see if you can use selectManyListBox.

            • 3. Re: adding new option in selectonechoice
              webcentercontentnewbie

              well i am making a search form in which there are multiple dropdown as search filter.All mean user want to get result for all option ,not to any specific.

               

              @931325 - can u help me with some sample code.

              • 4. Re: adding new option in selectonechoice
                931325

                Check this out...Try to understand how the selectItems is populated and do it accordingly.  Note: if you are planning to populate in the getter, then add null check and populate only if your list is null.

                 

                af:selectOneChoice - setting default selected value other than the first in line (JSF forum at JavaRanch)

                • 5. Re: adding new option in selectonechoice
                  webcentercontentnewbie

                  i try to understand..but not able to get it.how to achieve this..please tell me

                  • 6. Re: adding new option in selectonechoice
                    931325

                    In your fragment

                    <af:selectOneChoice id="soc1"

                                                          value="#{MyTestBean.myValue}"

                                                            unselectedLabel="Select One"

                                                          label="My Items">

                                                          <f:selectItems id="items"

                                                       value="#{MyTestBean.valueList}"/>

                                      </af:selectOneChoice>

                                    

                    In Backing Bean

                    private List<SelectItem> valueList = null;

                        public List<SelectItem> getValueList() {

                              if (valueList == null || valueList.size() == 0) {

                     

                                  valueList = getYourValueListFromServiceByRunningQuery();

                              }

                              return valueList;

                          }

                     

                    private List<SelectItem> getYourValueListFromServiceByRunningQuery()

                    {

                                  valueList = new ArrayList<SelectItem>();

                                  SelectItem selIt = new SelectItem();

                                  selIt.setLabel("ALL");

                                  selIt.setValue("ALL");

                                   valueList.add(selIt);

                                   //Get the remaining values from your VO by calling ApplicationModule method.

                                   //populate the list with values returned from your query

                                   return valueList;

                    }

                     

                    See if this helps....the getYourValueListFromServiceByRunningQuery will return a list of List<SelectItem>

                    • 7. Re: adding new option in selectonechoice
                      webcentercontentnewbie

                      thanks again for explained reply

                       

                      bt hw to execute  this

                       

                         //Get the remaining values from your VO by calling ApplicationModule method.

                                     //populate the list with values returned from your query

                                     return valueList;


                      can u help me please.i am new to adf

                      • 8. Re: adding new option in selectonechoice
                        webcentercontentnewbie

                        which method i should call to Get the remaining values from your VO by calling ApplicationModule method.

                        • 9. Re: adding new option in selectonechoice
                          931325

                          This should guide you through

                          http://xmlandmore.blogspot.com/2011/05/invoking-application-module-custom.html

                           

                          And regarding which method you should call....you need to write a custom method accessing your viewobject, setting bind variables (if any) and returning a list to populate your selectItem list.

                          • 10. Re: adding new option in selectonechoice
                            webcentercontentnewbie

                            can u let me know how to access viewobject and execute query.i hve bind variable..

                             

                            how to get list from VO

                            • 11. Re: adding new option in selectonechoice
                              Timo Hahn

                              Take a look at solution 2 in http://wp.me/pcBZk-4M where you see how to setup a method in the vo and how to add the method in the binding layer, calling the method from a bean and how to set the parameter used by the method in the vo.

                               

                              Timo

                              • 12. Re: adding new option in selectonechoice
                                webcentercontentnewbie

                                @timo

                                 

                                I am able to get all the values in list.  now when i am setting into  like below.A new option is added into dropdown..thank u.

                                 

                                valueList = new ArrayList<SelectItem>();

                                                    SelectItem selItNew = new SelectItem();
                                                    String nameValue=iterator.next().toString();
                                                    System.out.println("configGrp name: " + nameValue);
                                                    selItNew.setLabel(nameValue);
                                                    selItNew.setValue(nameValue);
                                                    valueList.add(selItNew);

                                 

                                but when i am selecting any value, i am getting error. like

                                Error For input string: "H CP US Configuration"

                                Error For input string: "ALL"

                                 

                                How to solve this

                                • 13. Re: adding new option in selectonechoice
                                  Timo Hahn

                                  Sorry, you have to provide more code. The bit you posted does not even show where you add your item and where you get the items from the list.

                                   

                                  Timo

                                  • 14. Re: adding new option in selectonechoice
                                    webcentercontentnewbie
                                    public List<SelectItem> getValueList() {

                                     

                                              if (valueList == null || valueList.size() == 0) {

                                     

                                     

                                                  valueList = getYourValueListFromServiceByRunningQuery();

                                     

                                              }

                                     

                                              return valueList;

                                     

                                          }
                                      
                                    private List<SelectItem> getYourValueListFromServiceByRunningQuery()

                                     

                                    {

                                     

                                                  valueList = new ArrayList<SelectItem>();
                                                  List valueListFromBinding = new ArrayList();
                                                   BindingContainer bindings = getBindings();
                                                   OperationBinding operationBinding = bindings.getOperationBinding("executeConfigGrpCriteria");
                                                   valueListFromBinding = (List<SelectItem>)operationBinding.execute();
                                                    Iterator<String> iterator = (Iterator<String>)valueListFromBinding.iterator();
                                                    Integer count=0;
                                                    while (iterator.hasNext())
                                                   
                                                    {  
                                                        count++;
                                                        SelectItem selItNew = new SelectItem();
                                                        String nameValue=iterator.next().toString();
                                                        System.out.println("configGrp name: " + nameValue);
                                                        selItNew.setLabel(nameValue);
                                                        selItNew.setValue(count);
                                                        valueList.add(selItNew);
                                                    }
                                                      
                                                       SelectItem selIt = new SelectItem();
                                                        selIt.setLabel("ALL");
                                                        selIt.setValue(count+1);
                                                        valueList.add(selIt);
                                                   if (!operationBinding.getErrors().isEmpty()) {
                                                       return null;
                                                   }
                                                 

                                     

                                                   return valueList;

                                     

                                    }

                                     

                                     

                                     

                                     

                                     

                                    In the value, i want to pass as string.. but it want integer.how to do that?

                                     

                                     

                                    1 2 Previous Next