Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » How can I read out values from a form that contains dynamically created elements
How can I read out values from a form that contains dynamically created elements [message #1033718] Thu, 04 April 2013 15:04 Go to next message
Sebastiaan Hendriks is currently offline Sebastiaan HendriksFriend
Messages: 13
Registered: March 2013
Location: Netherlands
Junior Member
I'm creating a form (called GenericForm) which is going to allow the user to set parameters for the generation of reports. The form is going to contain an unknown amount of elements. These elements are being created on the form using a override of the InjectFieldsInternal function, showing here:
@Override
protected void injectFieldsInternal(List<IFormField> fieldList) {

    List<ReportParameter> metadata = null;
    if (reportId != null)
    {
      metadata = SERVICES.getService(IReportingService.class).getMetadataFromReport(reportId);
    }
    IFieldConstructorService constructService = SERVICES.getService(IFieldConstructorService.class);
    Iterator<ReportParameter> metait = metadata.iterator();
    while (metait.hasNext())
    {
      ReportParameter rp = metait.next();
      if (rp.getName().equals("Unit"))
      {
        rp = metait.next();
      }

      String dataType = rp.getDataType();
      switch (dataType)
      {
        case "date":
         fieldList.add(constructService.AbstractDateField(rp.getName(), 0, true));
         break;
        case "string":
         fieldList.add(constructService.AbstractStringField(rp.getName(), 0, true));
         break;
        default:
         break;
        }
      }
      fieldList.add(constructService.DefaultUnitBox());
      fieldList.add(constructService.DefaultReportFormBox());
    }


Normally when handeling the data from the form after the user is done with giving its preferred parameterdata, I would use the exportFormData function in the Handler to chuck it in a formData value, and then handle it from there.

public class ReportHandler extends AbstractFormHandler {
  @Override
  public void execLoad() throws ProcessingException {
  }

  @Override
  public void execStore() throws ProcessingException {
      
    GenericFormData formData = new GenericFormData();
    exportFormData(formData); //formData remains to be empty
    
    //Further handeling of formData
  }


However, since I got dynamically created elements in GenericForm, they dont show up in my GenericFormData class which is used by the exportFormData function. Which in turn doesnt export the values from the form into the formData value. Atleast, if I understand it correctly.

Is there another way to get the data from the form, or am I tasked with somehow (temporarily) populating my GenericFormData class with the information required for scout to fill out the formData value via the exportFormData function?
Re: How can I read out values from a form that contains dynamically created elements [message #1033755 is a reply to message #1033718] Thu, 04 April 2013 15:49 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan MotschFriend
Messages: 102
Registered: March 2010
Senior Member
You can add a property to your form that holds as container for your values:


public class GenericForm extends AbstractForm{

 private MyDynamicData m_dynamicData;

 @FormData
 public MyDynamicData getDynamicData(){
  return m_dynamicData;
 }

 @FormData
 public void setDynamicData(MyDynamicData data){
  m_dynamicData=data;
 }

}


Scout will add a property MyDynamicDataProperty to the formdata due to the @FormData annotation of the property.

Then you can override the export/import formdata methods of the generic form and write / read the values of your dynamic fields to / from the MyDynamicData bean.

Note that MyDynamicData must be serializable.

Does this solve your issue?

Re: How can I read out values from a form that contains dynamically created elements [message #1034530 is a reply to message #1033755] Fri, 05 April 2013 14:57 Go to previous messageGo to next message
Sebastiaan Hendriks is currently offline Sebastiaan HendriksFriend
Messages: 13
Registered: March 2013
Location: Netherlands
Junior Member
That pushed me into the right direction and I got things working now as intended. Thank you Ivan.

This is how I added the functionality. Per your suggestion I added a property to my GenericForm class to hold the information from the form, namely a List of ReportParameter objects, which I was able to read out.

Code showing here on accessing the list:
@Override
public void execStore() throws ProcessingException {

    GenericFormData formData = new GenericFormData();
    exportFormData(formData);
    List<ReportParameter> rpList = getReportParameterList();

    //Code omitted handeling values from static elements (formData),
    //and dynamic elements(rpList)
}

Then I got to the issue of actually filling that List of objects. I've done that by overriding the execChangedValue function on the injected elements to add a new ReportParameter object to my List.

Code showing here:
@Override
protected void execChangedValue() throws ProcessingException {
    if (this.getValue() != null) {
        GenericForm form = (GenericForm) this.getForm();
        form.setReportParameter(this.getLabel(), this.getValue(), "date");
    }
}

That code is placed in a separate class in order to keep the InjectInteralFields function nice and tidy. That is why there is an explicit unboxing on the form value in my code.
Re: How can I read out values from a form that contains dynamically created elements [message #1729685 is a reply to message #1033718] Mon, 18 April 2016 07:03 Go to previous message
Vijayachandra kumar ramamurthy is currently offline Vijayachandra kumar ramamurthyFriend
Messages: 3
Registered: December 2015
Junior Member
I am using wrappedfield in a search form to load a form with dynamic elements and collecting dynamic field labels and values in a list as directed in this thread, but I dont get idea to pass this List to search form FORMDATA/service, can it be guided, please?

I need guidance to manually write/override the import/export Formdata functions to pass the data from inner form(using wrappedfield) to outer/parent form.

Loading/setting of the inner form is invoked from a Button's ExecClickAction() of SearchForm,

MyForm form = new MyForm(param);
form.setIconId(Icons.Download);
getWrapField().setInnerForm(form);
form.setHandler(new SearchHandler());
form.initForm();

In the MyForm, the GUI fields are loaded dynamically using injectFieldsInternal(OrderedCollection<IFormField> fieldList) function,

Now inner form is getting loaded with the dynamic elements from database, and now need to pass back the GUI field input values to searchform for the further processing, guide plz.
Thanks in advance
Previous Topic:[neon] M6 mobile support
Next Topic:[Neon] Multiple config files
Goto Forum:
  


Current Time: Thu Jun 30 09:05:16 GMT 2016

Powered by FUDForum. Page generated in 0.03946 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software