Hi,

I am just evaluating joget (among others) - and I find it pretty much.

I have two issues/questions regarding the grid element in forms:

- Can the restriction to 5 columns lifted to 10 or 15?

- (How) is it possible to set initial values into the grid (i.e. populating grid cells with values from "outside")?

I would like to implement some order form processing where initial data is coming from an external system.

Kind regards,

Hans

  • No labels

6 Comments

  1. Hi Hans,

    -The current implementation had been fixed. You can change it at the coding level if you wish.

    -You can set the initial values only by javascript. Please refer to this page Sample Custom JavaScript in Form Builder for more information.

    Regards,

    Owen

  2. Hi Owen,

    can you give me some hints where in the code I can find grid related programming?

    I just found a first place in the formbuilder index.jsp where the number of columns is selected.

    Where are the procedures for saving resp. filling the grid at run-time?

    And do you see any chance to mix up read-only and editable grid cells (I want to display item information and let just enter related quantities)?

    Kind regards,

    Hans

  3. Hi Hans,

    You can actually add more columns and input types to the grid by modifying the gridSave() & changeColumn() javascript function in the formbuilder index.jsp

    1. Hi Owen,

      In formbuilder index.jsp,  i added some other input types to the grid,

      such as radiobutton:

      In gridSave():

          case 'radio':

          grid.addColumn(new RadioButton());

      In changeColumn():

          baseString +='<option value="radio"><fmt:message key="formbuilder.radio"/></option>;

      when build a form by grid, it works normbly,

      but when preview the form, the radiobutton is null.

      what is the problem?

      Regards.

  4. Hi there,

    If you find that by modifying the coding may spell too much of trouble to you or if your form is complicated, you may consider using external form.

    Here's a bit of read up you can do. Sample External Form Integration

    Good luck!

  5. Ok, so starting from the problem "filling my grid with data from the database" I reached this place. Unfortunately thare was nothing usefull, so I started my own "research".

    So basically when you put a grid on a form, in the database tabel the framework creates some columns. These columns are:

    • c_[yourControlOnGridName]_row - holds the number of rows in the model
    • c_[yourControlOnGridName]_col - holds the column number in the model
    • c_[yourControlOnGridName] - holds all the data for all the rows coresponding to one column

    In order to populate your grid you must populate these column in the model. The way I did this was with the BeanShell plugin (a system task before the performer task).

    Let me show you the code and then explain it:

    import java.sql.*;
    import java.util.Date;
    import java.util.ArrayList;
    import java.util.logging.Logger;
    import org.joget.plugin.base.PluginManager;
    import java.util.logging.FileHandler;
    import org.joget.workflow.model.service.WorkflowManager;
    import org.joget.form.model.service.FormManager;
    import org.joget.form.model.Form;
    import org.joget.commons.util.UuidGenerator;
    
    String formDataTable = "dl_manageList";
    
    FormManager formManager = (FormManager) pluginManager.getBean("formManager");
    processId = workflowAssignment.getProcessId();
    Form form = formManager.loadDynamicFormByProcessId(formDataTable, processId);
    
    String myList = "";
    int numberOfItems = 0;
    
    Connection con = null;
    try {
    
    &nbsp;&nbsp; Class.forName("com.mysql.jdbc.Driver").newInstance();
    &nbsp;&nbsp; con = DriverManager.getConnection("jdbc:mysql://localhost:3307/sampledb?useUnicode=true&characterEncoding=UTF-8", "root", "");
    
    &nbsp;&nbsp; if(\!con.isClosed()){
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String query = "select listItem from custom_listItems";
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Statement stmt = con.createStatement();
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ResultSet rs = stmt.executeQuery(query);
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (rs.next()) {
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String item = rs.getString(1);
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myList \+= "\"" + item.replace("\"", "\"\"") \+&nbsp;&nbsp;&nbsp; "\"" + (char)0x0a;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; numberOfItems++;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
    &nbsp;&nbsp;
    &nbsp;&nbsp; if (form == null) {
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; form = new Form();
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; form.setId(UuidGenerator.getInstance().getUuid());
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Map customProperties = new HashMap();
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; customProperties.put("processId", workflowAssignment.getProcessId());
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; customProperties.put("activityId", workflowAssignment.getActivityId());
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; customProperties.put("version", workflowAssignment.getProcessVersion());
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; customProperties.put("created", new Date());
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; customProperties.put("draft", "0");
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; form.setCustomProperties(customProperties);
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; form.setTableName(formDataTable);
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; formManager.saveOrUpdateDynamicForm(form);
    &nbsp;&nbsp; }
    
    &nbsp;&nbsp; formData = form.getCustomProperties();
    &nbsp;&nbsp; formData.put("c_grid_Items", myList);
    &nbsp;&nbsp; formData.put("c_grid_Items_col", "1");
    &nbsp;&nbsp; formData.put("c_grid_Items_row", numberOfItems.toString());
    &nbsp;&nbsp; form.setCustomProperties(formData);
    &nbsp;&nbsp; formManager.saveForm(form);
    } catch(Exception e) {
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.err.println("Exception: " + e.getMessage());
    } finally {
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(con \!= null)
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.close();
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch(SQLException e) {}
    }

    So basically I write in the formData all the mentioned columns above with the required data.

    But there is a catch: if the model si not created when the java code runs your grid can not be populated, so you must initialize the model by yourself (see the if(form == null ) branch).

    And also, every item is stored in the database surrounded by "" and followed by 0xa0.