Initializing Bound Controls

From Apache OpenOffice Wiki
Jump to: navigation, search

All form controls specify a default value that is used when initially displaying the control, and when it is reset. For instance, resetting ( happens when a form is moved to the insert row, that allows data to be inserted as a new row into the underlying row set.

Now, you do not want a fixed default value for new records, but a dynamically generated one that is dependent on the actual context at the moment the new record is entered.

Or, you want to have real null values for date fields. This is currently not possible, because the service interprets a null default as an instruction to use the current system date. Effectively, you cannot have date fields in forms which default to null on new records, but you can get this by programming the API.

  public void handleReset(EventObject aEvent) throws {
      if (((Boolean)xFormProps.getPropertyValue("IsNew")).booleanValue()) {
          // the form is positioned on the insert row
          Object aModifiedFlag = xFormProps.getPropertyValue("IsModified");
          // get the columns of the form
          XColumnsSupplier xSuppCols = (XColumnsSupplier)UnoRuntime.queryInterface(
              XColumnsSupplier.class, xFormProps);
          XNameAccess xCols = xSuppCols.getColumns();
          // and update the date column with a NULL value
          XColumnUpdate xDateColumn = (XColumnUpdate)UnoRuntime.queryInterface(
              XColumnUpdate.class, xCols.getByName("SALEDATE"));
          // then restore the flag
          xFormProps.setPropertyValue("IsModified", aModifiedFlag);

The first decision is where to step in. We chose to add a reset-listener to the form, so that the form is reset as soon as it has been positioned on the new record. The <idlml></idlml>() method is called after the positioning is done.

However, resets also occur for various reasons therefore check if the form is really positioned on the insert row, indicated by the IsNew property being true.

Now besides retrieving and updating the data column with the desired value, null, there is another obstacle. When the form is moved to the insert row, and some values are initialized, the row should not be modified. This is because a modified row is saved in the database, and we only initialized the new row with the defaults, the user did not enter data., We do not want to store the row, therefore we save and restore the IsModified flag on the form while doing the update.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages