1
0
-1

Hello,

I'm working with an external database.

I succeeded importing fields for a select box creating my own FormOptionsBinder plugin.

Now I want to populate a spreadsheet (possibly in an Ajax subform if it helps) according to the selected value.

I think I have to create my own load binder for this purpose, but I can't find which class I must inherit from or which interfaces I must implement. Do you have any examples of spreadsheet load binders?

Regards,

Raphaël

    CommentAdd your comment...

    1 answer

    1.  
      2
      1
      0

      Hello,

      I ended up using this, which works : 

       
      public class IcaosListAjaxFormBinder extends FormBinder implements FormLoadBinder, FormLoadMultiRowElementBinder {

      public FormRowSet load(Element element, String primaryKey, FormData formData) {

      FormRowSet names = new FormRowSet();

       String processId = formData.getProcessId();

      if (primaryKey != null && processId!= null && !primaryKey.equals(processId)) {
                  //primaryKey != processId on AJAX loading because
      //primaryKey == manualName on AJAX loading

       RawPagesDao rawpagesdao = (RawPagesDao) AppContext.getInstance().getAppContext().getBean("rawPagesDao");

       Set<String> dataFromDB = rawpagesdao.getDatasFromManual(formData.getProcessId(), primaryKey);

       FormRow dataEntry = new FormRow();
       JSONStringer datasList = new JSONStringer();
      try {
      datasList.array();

      for (String dataName : dataFromDB) {
      datasList.object().key("dataName").value(dataName).key("selected").value(false).endObject();
       }

      datasList.endArray();

       dataEntry.put("generationRequirementsNames", datasList.toString());
       } catch (JSONException ex) {
      LogUtil.error(getClassName(), ex, String.format("Encountered a JSON error: %s", ex.getMessage()));
       }

      names.add(dataEntry);
       }

      return names;
       }

      //Add overriding stuff here
      }

      Regards,

      Raphaël

      1. Anders

        That's great, thanks for sharing your solution!

      2. Raphaël

        You're welcome, but do you know how to format code in a pretty way?

      CommentAdd your comment...