Search the FirstSpirit Knowledge Base
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!
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
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
Hello Kavin,
do you need further help or did Michael's reply already help you? If so, it would be great, if you marked his "correct answer".
If you have already found a solution by yourself, it would be very kind of you, if you posted it here.
Best regards
Michaela