How-to add row to a table?

Last modified by Frank Fock on 2024/05/25 12:52

This page describes how rows with SNMP values can be added to a SNMP4J-Agent table.

To add a row to a DefaultMOTable

  1. Make sure that the MOTableModel used by the table is an instance of the MutableMOTableModel.
  2. Create the row values as an array of Variable instances:

    Variable[] com2secValues = new Variable[] {
       new OctetString("public"),              // community name
       new OctetString("publicSecName"),       // security name
        getAgent().getContextEngineID(),        // local engine ID
       new OctetString(""),                    // default context name
       new OctetString(),                      // transport tag
       new Integer32(StorageType.nonVolatile), // storage type
       new Integer32(RowStatus.active)         // row status
    };
  3. Let the SNMP4J-Agent API create a new row based on the provided values and the index sub-OID for the new row. The new will be created by the MOTableRowFactory assigned to MOMutableTableModel of the snmpCommunityTable. If the row factory is not set (for example to a DefaultMOFactory instance) then an exception will be thrown:

    MOTableRow newRow = snmpCommunityTable.createRow(new OctetString("public").toSubIndex(true), com2secValues); 
  4. Add the newly created row to the table:

    ((MOMutableTableModel)snmpCommunityTable.getModel()).addRow(newRow);