Forum Stats

  • 3,759,903 Users
  • 2,251,613 Discussions
  • 7,870,859 Comments

Discussions

How to check if select one choice component only contains 1 option?

User_8YH96
User_8YH96 Member Posts: 4 Green Ribbon

Hello all.

On the page I'm currently developing there is a popup which contains a tree table component with multiple columns and select one choice components, and one child disclosure also containing an soc component.

I am seeking a way to check if there is only one select item choice in the soc dropdown, and if so, I want the soc to default to the only available choice.

The soc components are populated dynamically and so may contain a varying number of elements in each dropdown. I have been trying to find a way to count the number of elements in the dropdown but have not found a successful way to count the number of items for both parent and child node lov/soc components.

So basically, I want to check if the soc item list count equals "1". If there is only "1" item option, then default the soc to that value.

Thank you for reading.

My Jdeveloper version is 12.2.1.4

Answers

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 37,566 Red Diamond

    A selectOneChoice gets its items from an f:selectItems tag value property. This value is pointing to a collection and you should be able to count the number of items in the collection.

    As you say you dynamically create this collection (an ArrayList I guess), so you can get the number of items using ArrayList.size() method.


    Timo


    User_8YH96
  • User_8YH96
    User_8YH96 Member Posts: 4 Green Ribbon

    Thank you for your response Timo.

    Just for some background I have only been working with jdeveloper and ADF for a little over a year. And so, this is my first time learning to programmatically access collection data from dynamically filtered tree components. Is there example documentation or a link to a resource that you can provide for studying the implementation of obtaining f:selectitems collection and element count via managed bean?

    Below is the tree table contained in the popup.

     <af:panelCollection id="pc4">
      <af:treeTable value="#{bindings.InstrumentRootModules1.treeModel}"
      var="node" id="tt1"
      columnStretching="column:c143" initiallyExpanded="true"
      disclosedRowKeys="#{viewScope.instrumentTreeHelperBean.newDisclosedTreeTableKeys}">
      <af:column headerText="#{c2mbtasksBundle['c2.label.CREATE_2_INDEXES']}"
      id="c15">
       <af:selectOneChoice id="soc5" autoSubmit="true"
      value="#{node.bindings.IbSplit.inputValue}"
      rendered="#{node.bindings.IbSplit.inputValue != 'EMPTY' ? true : false}">
      <af:selectItem label="Yes" value="Y" id="si6"/>
      <af:selectItem label="No" value="N" id="si7"/>
      </af:selectOneChoice>
      </af:column>
      <af:column headerText="#{c2mbtasksBundle['c2.label.TYPE_LOWER']}"
      id="c16">
      <af:selectOneChoice value="#{node.bindings.IbIndexTypeId.inputValue}"
      label="#{node.bindings.IbIndexTypeId.label}"
      shortDesc="#{bindings.InstrumentRootModules.hints.IbIndexTypeId.tooltip}"
      id="soc4"
      rendered="#{node.bindings.HierCode.inputValue != 'JDR' &amp;&amp; node.bindings.HierCode.inputValue != 'ONE_LEVEL' &amp;&amp; node.bindings.HierCode.inputValue != 'THEME_ONLY' &amp;&amp; node.bindings.HierCode.inputValue != 'EMPTY' ? true : false}" immediate="true"
      autoSubmit="true"
      required="true">
      <f:selectItems value="#{node.bindings.IbIndexTypeId.items}"
      id="si5"/> 
      <f:validator binding="#{node.bindings.IbIndexTypeId.validator}"/>
      </af:selectOneChoice>
      <af:outputText value="Theme Only" id="ot27"
      rendered="#{node.bindings.HierCode.inputValue == 'THEME_ONLY' ? true : false}"/>
      <af:outputText value="One Level" id="ot28"
      rendered="#{node.bindings.HierCode.inputValue == 'ONE_LEVEL' ? true : false}"/>
      <af:outputText value="JDR" id="ot17"
      rendered="#{node.bindings.HierCode.inputValue == 'JDR' ? true : false}"/>
      </af:column>
      <af:column id="c143" headerText="Scoring" partialTriggers="soc4 ">
      <af:selectOneChoice value="#{node.bindings.PreferredScoringId.inputValue}"
      label="#{node.bindings.PreferredScoringId.label}"
      id="soc42"
      immediate="true" autoSubmit="true"
      rendered="#{node.bindings.SelectScoringDisabled.inputValue == false}"
      partialTriggers="soc4">
      <f:selectItems value="#{node.bindings.PreferredScoringId.items}"
      id="si54"/>
      <f:validator binding="#{node.bindings.PreferredScoringId.validator}"/>
      </af:selectOneChoice>
      <af:outputText value="#{node.bindings.PreferredScoringId.model.rowCount}" id="ot177"/>
      </af:column>
      <f:facet name="nodeStamp" headerText="Index">
      <af:column id="c14">
      <af:outputText value="#{node.ModuleName}" id="ot217"/>
      </af:column>
      </f:facet>
      </af:treeTable>
      </af:panelCollection>
    

    For example, if I wanted to access f:selectItems value="{node.bindings.PreferredScoringId.item}" and programmatically count each parent and nested child node's array list in order to perform conditional operations for setting value or resetting value back to null choice.

    I understand creating bindings to managed beans and etc, but I am unsure of how to approach programmatically obtaining the model collection as an array or how to count for each node in a bean method with component of UISelectItems.

    Should these operation be performed in the setter of the binding?

      public void setIbPopScoringSOC(UISelectItems ibPopScoringSOC) {
      this.ibPopScoringSOC = ibPopScoringSOC;
      //code here?
      }
    
      public UISelectItems getIbPopScoringSOC() {
      return ibPopScoringSOC;
      }
    
    


  • User_8YH96
    User_8YH96 Member Posts: 4 Green Ribbon
  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 37,566 Red Diamond

    User, you said that the LOV is built dynamically. This I don't see from your code sample.

    Anyway, I don't know if you can use EL to get the info you are looking for. In a bean, you can get the select items and get their size via java. I don't understand what you mean by getting the number of parent nodes.

    Setting the selectOneChoice to the first element (or only element) is done by setting the value property of the af:seleectOneChoice to the value of the first element. This can be done in the bean too.


    Timo


  • User_8YH96
    User_8YH96 Member Posts: 4 Green Ribbon
     <af:selectOneChoice value="#{node.bindings.PreferredScoringId.inputValue}"
      label="#{node.bindings.PreferredScoringId.label}"
      id="soc42"
      immediate="true" autoSubmit="true"
      rendered="#{node.bindings.SelectScoringDisabled.inputValue == false}"
      partialTriggers="soc4">
    
      <f:selectItems value="#{node.bindings.PreferredScoringId.items}"
      id="si54"/>
    

    I will try to clarify. This select one choice component is responsible for generating all 8 of the the dropdowns seen in the "scoring" column of the popup (see screenshot).

    All 8 of these dropdowns contain different data, and may contain a different number of rows to select from. The data from these dropdowns all come from the same tree binding on the page, which pulls data from view objects querying dbs.

    The parent node in the example popup would be the row with type of "TDR" and has a "scoring" select one choice dropdown. This parent row has 5 child rows, each with their own "scoring" dropdowns.

    There is only a single af:selectOneChoice and "f:selectItems" component to work with however.

    So what I am asking is if there is a way to run a check on each dropdown as it is generated. If the dropdown only contains one choice then default to that choice in the dropdown and display the default selection on the page.

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 37,566 Red Diamond

    It's only one f:selectItems statement, but the data used is coming from the node so it can change each time the node changes.

    Do you have a reproducible test case build on the HR DB schema?


    Timo