Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » How can I pass additional variables to injectFieldsInternal()
How can I pass additional variables to injectFieldsInternal() [message #1032799] Wed, 03 April 2013 08:52 Go to next message
Sebastiaan Hendriks is currently offline Sebastiaan Hendriks
Messages: 13
Registered: March 2013
Location: Netherlands
Junior Member
I'm trying to dynamically create fields on a Form based upon metadata that I get from a database before the form is created. The Form is going to be called via a Menu on a record in a AbstractTablePage.

I've managed to find out how to inject fields with the use of overriding the injectFieldsInternal() function, but sofar I havent yet figured out how I can pass a value to indicate how many fields need to be injected.

How can I best do this?

Relevant code in the Form:
@Order(10.0)
public class MainBox extends AbstractGroupBox {

    @Override
    protected void injectFieldsInternal(List<IFormField> fieldList) {

      //int params = this.reportId.intValue();
      int params = 1;

      for (int i = 1; i < params; i++) {
        final int param = i;
        fieldList.add(new AbstractStringField() {
          @Override
          protected String getConfiguredLabel() {
            return "Field " + param;
          }
        });
      }
    }

    @Order(10.0)
    public class OkButton extends AbstractOkButton {
    }

    @Order(20.0)
    public class CancelButton extends AbstractCancelButton {
    }
 }


Code in my page:
@Order(30.0)
public class GenerateReportWithParametersMenu extends AbstractMenu {

    @Override
    protected String getConfiguredText() {
    return TEXTS.get("ProduceerRapportMetParameters");
    }

    @Override
    protected void execAction() throws ProcessingException {

    Long reportId = getTable().getReportIDColumn().getSelectedValue();
    GenericForm form = new GenericForm(reportId);
    form.setGenericFormNr(reportId);
    form.startModify();
    form.waitFor();
    if (form.isFormStored()) {
        reloadPage();
      }
    }
}
Re: How can I pass additional variables to injectFieldsInternal() [message #1032804 is a reply to message #1032799] Wed, 03 April 2013 09:04 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan Motsch
Messages: 100
Registered: March 2010
Senior Member
What is the constructor of GenericForm ?

try the following:


public class GenericForm extends AbstractForm{
 private int m_myParam;

 public GenericForm(int myParam){
  super(false);//false=do not yet initialize the form
  m_myParam=myParam;
  callInitializer();//now init the form, this will inject the fields etc.
 }

 //use m_myParam inside the MainBox inject

}
Re: How can I pass additional variables to injectFieldsInternal() [message #1032812 is a reply to message #1032804] Wed, 03 April 2013 09:15 Go to previous messageGo to next message
Sebastiaan Hendriks is currently offline Sebastiaan Hendriks
Messages: 13
Registered: March 2013
Location: Netherlands
Junior Member
That works perfectly, thank you Ivan.
Re: How can I pass additional variables to injectFieldsInternal() [message #1032916 is a reply to message #1032804] Wed, 03 April 2013 12:02 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan Motsch
Messages: 100
Registered: March 2010
Senior Member
did this help?
Re: How can I pass additional variables to injectFieldsInternal() [message #1033702 is a reply to message #1032916] Thu, 04 April 2013 10:41 Go to previous message
Sebastiaan Hendriks is currently offline Sebastiaan Hendriks
Messages: 13
Registered: March 2013
Location: Netherlands
Junior Member
Ivan Motsch wrote on Wed, 03 April 2013 18:02
did this help?


Yes Ivan, it worked perfectly.
Previous Topic:Adding context menus to SVG fields
Next Topic:How can I read out values from a form that contains dynamically created elements
Goto Forum:
  


Current Time: Mon Jul 28 00:14:36 EDT 2014

Powered by FUDForum. Page generated in 0.01675 seconds