How to get the selected value of CMS_INPUT_COMBOBOX
Author: kavin
Publication Date: 5/13/2016 8:17
Dear All,
I need to retrive the selected value from CMS_INPUT_COMBOBOX's.
I tried to get the value from OptionModel.getSelectedOption() but i am getting a NULL value.
OptionFactory optionFactory = ((OptionFactoryProvider) datset.getFormData().getForm().findEditor("tt_contact")).getOptionFactory();
OptionModel optionModel = optionFactory.getOptionModel(prjBroker, lang,true);
Option op=optionModel.getSelectedOption();
Could you please guide me to retrvie the data using FS 5.1 api?
Thank you!
Tags: access-api, fs5.1
-
Author: mbergmann - 5/13/2016 9:21
Hi Kavin,
you are working on the "wrong side" - namely the input component UI model - but you have to use the "data side".
As an INPUT_COMBOBOX can contain different types of date depending on its GOM definition, its general value type is an Option which acts as a wrapper object for the real data. From an Option, you get the value just using getValue().
I broke it down into seperate steps to make it clearer:
//lang may be null for language independent input components
FormField<Option> formField = (FormField<Option>) dataset.getFormData().get(lang, "tt_contact");
Option option = formField.get();
Object value = option.getValue();
// depending on the definition of the combobox, you get different types here.
// e.g. if the combobox has INCLUDE_OPTIONS type=Database (looks to me this is the case) you will get an Entity
Entity contactEntity = (Entity) value;
// OR, if you use "hardcoded" options <ENTRIES><ENTRY>...</ENTRY><ENTRY>...</ENTRY></ENTRIES> you get a String
String stringEntry = (String) value;
Michael
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
1 Kommentar