Topic
  • 6 replies
  • Latest Post - ‏2012-05-12T13:46:24Z by JakeBerberich
JakeBerberich
JakeBerberich
117 Posts

Pinned topic RUI Combo Box - Retrieving the Value Selected

‏2012-05-02T15:43:34Z |
I'm using RBD 8.0.1.3 and looking for best practice on retrieving the selected value. Currently I'm using the IBM (non-Dojo) ComboBox widget
In the following example I found on the Forum the values are statically loaded... and a similar implementation worked for me initially.

Then, I loaded the values from a OS400 table via a service. While the values appear properly in the combo box, the values in my array returned by the service no longer remain at the time I execute
< selectedText.text = ComboBox.selection >

Now I'm calling yet another service to pass the ComboBox.selection value to retrieve the text desc from the OS400 table.

Works but seems inefficient... in JSF it's so easy.. appreciate any suggestions on how to get the text value in the combo box corresponding to the line value selected.

Regards, Jake

handler TestCombo type RUIhandler {initialUI = ui,onConstructionFunction = initialization, cssFile="css/Test.css"}
ComboBox Combo{onChange ::= ComboBox_onChange};
ui Div{children=ComboBox};
COLOR_NAMES String[] = ;
COLOR_VALUES String[] = ;

function initialization()
ComboBox.values = COLOR_NAMES;
end

function ComboBox_onChange(event Event in)
WriteStdOut("onChange: " + ComboBox.selection);
WriteStdOut("Selected: " + COLOR_VALUEShttp://ComboBox.selection);
end
end
Updated on 2012-05-12T13:46:24Z at 2012-05-12T13:46:24Z by JakeBerberich
  • bsvihovec
    bsvihovec
    194 Posts

    Re: RUI Combo Box - Retrieving the Value Selected

    ‏2012-05-03T15:10:33Z  
    Jake,

    Would it be possible to store the data from your service in local variables, so that your dynamic code looks just like your static code? (NOTE: Your EGL source did not come through in your post, due to the fact that the forum software converts content within square brackets into an HTML link)

    For example, you could write a service that builds a record containing two fields for each value that will be displayed in the combo box:

    Record aValue
      theValue String;
      theDescription String;
    end
    


    In your Rich UI application, you would load these records, store them locally, and then iterate over them to build an array of strings for the combo box's value field. When you want the description of a value, you would use something like:

    valueArray"["CombBox.selection"]".theDescription
    


    If the text descriptions for all of the values is quite large, and would take a while to download, then I think you will need to keep using two services, and then either download all of the descriptions dynamically, or possibly download the top 10 up front, and the rest on demand.

    -Brian
    Updated on 2014-03-25T04:44:06Z at 2014-03-25T04:44:06Z by iron-man
  • dan_darnell
    dan_darnell
    973 Posts

    Re: RUI Combo Box - Retrieving the Value Selected

    ‏2012-05-03T22:31:28Z  
    Hi Jake,

    I can hook you up with a combo box widget that stores both displayed values and associated values. I use it so that I can show one thing (say, a text description) in the drop down but still have access to a behind-the-scenes value (say, a code value that is associated with each description).

    It will cure your ills. You'll have to wait until tomorrow though -- I'll be back in the main office and can post a code example at that time...

    --Dan
  • dan_darnell
    dan_darnell
    973 Posts

    Re: RUI Combo Box - Retrieving the Value Selected

    ‏2012-05-03T22:36:55Z  
    (Rant)

    It's one of my perennial complaints that component designers never "get it" when it comes to drop-downs. It is rare that the actual value displayed in a drop-down is the value needed to act on the user's selection. More typical is the use case where a drop-down displays a description and the application needs to act upon a key value associated with the description.

    Therefore, in every language I have ever worked in I end up writing an extension of the base drop-down component that handles this ubiquitous use case. If EGL Rich UI were to actually support this out of the box it would differentiate EGL as a language for developers that REALLY understands developers' needs.

    (End rant)
  • dan_darnell
    dan_darnell
    973 Posts

    Re: RUI Combo Box - Retrieving the Value Selected

    ‏2012-05-03T22:42:34Z  
    (Rant)

    It's one of my perennial complaints that component designers never "get it" when it comes to drop-downs. It is rare that the actual value displayed in a drop-down is the value needed to act on the user's selection. More typical is the use case where a drop-down displays a description and the application needs to act upon a key value associated with the description.

    Therefore, in every language I have ever worked in I end up writing an extension of the base drop-down component that handles this ubiquitous use case. If EGL Rich UI were to actually support this out of the box it would differentiate EGL as a language for developers that REALLY understands developers' needs.

    (End rant)
    (More rant)

    My other perennial complaint about component designers ... they can't seem to design a data grid that is worth a darn. One of the big things they tend to miss is that there is almost always some information needed by the application (at a row level) that does NOT need to be rendered as a visual element. IBM i developers of DDS-based applications know this as hidden fields in subfile records. A developer should not have to jump through hoops to do things that are required in 99% of the applications they write.

    Again, if EGL Rich UI could get this right it would be a huge differentiator in the marketplace.

    (End rant)
  • dan_darnell
    dan_darnell
    973 Posts

    Re: RUI Combo Box - Retrieving the Value Selected

    ‏2012-05-04T17:42:52Z  
    Jake,

    So, in the simplest case, you just want the value displayed in a regular old combo box...here's how you get it:

    
    val string = combo.getValues()[combo.selected];
    


    Now, if you have a situation where you have values associated with descriptions and you want to work with a combo that supports this, here is some source code for a custom widget:

    
    handler CustomCombo type RUIWidget 
    {targetWidget = combo, onConstructionFunction = initialization, cssFile=
    "css/CustomCombo.css"
    }   
    
    private combo Combo 
    { 
    }; 
    
    private associatedValues string[0]; function initialization() combo.setValues([
    "----------"]); associatedValues = [
    "NONE"]; end   function getValues() returns(string[]) 
    
    return(combo.getValues()); end function getAssociatedValues() returns(string[]) 
    
    return(associatedValues); end function getAssociatedValue() returns (string) 
    
    return(getAssociatedValues()[combo.selection]); end function getSelection() returns (string) 
    
    return(getValues()[combo.selection]); end function setSelection(index string) combo.selection = index; end function getSelectionIndex() returns (
    
    int) 
    
    return(combo.selection); end function setSelectionByValue(value string) 
    
    for(i 
    
    int from 1 to combo.getValues().getSize()) 
    
    if(combo.getValues()[i] == value) combo.selection = i; end end end function setSelectionByAssociatedValue(value string in) 
    
    for(i 
    
    int from 1 to getAssociatedValues().getSize()) 
    
    if(getAssociatedValues()[i] == value) combo.selection = i; end end end function setValues(values string[], assocValues string[]) combo.setValues(values); associatedValues = assocValues; end end
    


    About the custom combo:

    Populate the custom combo with...

    custcombo.setValues(valuesArray, associatedValuesArray);

    If you want to get the selection displayed in the combo, use...

    val string = custcombo.getSelection();

    If you want the value associated with the displayed selection...

    val string = custcombo.getAssociatedValue();

    You can position the combo based on either a displayed value or the associated value.

    Lots of good stuff...

    Hope this helps.

    --Dan
  • JakeBerberich
    JakeBerberich
    117 Posts

    Re: RUI Combo Box - Retrieving the Value Selected

    ‏2012-05-12T13:46:24Z  
    Dan, thanks!