Menu

#835 Set null value for an ID

closed-fixed
5
2009-10-18
2009-09-30
No

Hi,

Actually, if you try to set ID to null, you can not do by setting the ID on 0, for example. The method will not know if you wanted to set zero or null.
So, why not modify a little this method GridTabWrapper.invoke(Object, Method, Object[]) to allow to set the ID to null. If the name is ending with _ID and the ID is lower the 0, then this means that will be set on null.

WDYT?

Regards,
Cristina Ghita, www.arhipac.ro

Discussion

  • Cristina Ghita

    Cristina Ghita - 2009-09-30

    Hi Carlos,

    Try to do this from a callout.

    E.g

    final I_A_Asset model = GridTabWrapper.create(mTab, I_A_Asset.class);
    if (model.getC_Location_ID() > 0 )
    {
    model.setM_Locator_ID(-1);
    }
    Without the modification that I am saying , you can't. In the DB it will try to insert -1 for M_Locator_ID and not null.

    This is the modification that I propose in method GridTabWrapper.invoke :

    String propertyName = methodName.substring(3);
    Object value = args[0];
    if (propertyName.endsWith("_ID")
    && value instanceof Integer && (Integer)value < 0)
    {
    m_gridTab.setValue(propertyName, null);
    }
    else
    {
    m_gridTab.setValue(propertyName, value);
    }
    I hope I made myself clear.

    Regards,
    Cristina Ghita, www.arhipac.ro

     
  • Carlos Ruiz

    Carlos Ruiz - 2009-09-30

    Thanks Cristina, I see, your code is equivalent to write in the callout:

    mTab.setValue("M_Locator_ID", -1);

    I think it will be better if we change the GridTab method instead of the wrapper, I tested this patch and it covers both situations, and it's not dependent on the column name:

    Index: base/src/org/compiere/model/GridTab.java

    --- base/src/org/compiere/model/GridTab.java (revision 10439)
    +++ base/src/org/compiere/model/GridTab.java (working copy)
    @@ -40,6 +40,7 @@
    import org.compiere.util.CLogMgt;

    import org.compiere.util.CLogger;

    import org.compiere.util.DB;

    +import org.compiere.util.DisplayType;

    import org.compiere.util.Env;

    import org.compiere.util.Evaluatee;

    import org.compiere.util.Evaluator;

    @@ -2480,6 +2481,9 @@
    return "NoField";

    log.fine(field.getColumnName() + "=" + value + " - Row=" + m_currentRow);

    +

    + if (DisplayType.isID(field.getDisplayType()) && value instanceof Integer && ((Integer)value).intValue() < 0)

    + value = null;

    int col = m_mTable.findColumn(field.getColumnName());

    m_mTable.setValueAt(value, m_currentRow, col, false);

    Regards,

    Carlos Ruiz

     
  • Carlos Ruiz

    Carlos Ruiz - 2009-09-30
     
  • Carlos Ruiz

    Carlos Ruiz - 2009-09-30

    Better I upload the patch because the formatting was lost.

    Attached file patch2870645.patch with the proposed patch on GridTab

    Regards,

    Carlos Ruiz

     
  • Carlos Ruiz

    Carlos Ruiz - 2009-09-30
    • status: open --> open-remind
     
  • Carlos Ruiz

    Carlos Ruiz - 2009-10-01
    • assigned_to: nobody --> globalqss
    • status: open-remind --> pending-remind
     
  • Cristina Ghita

    Cristina Ghita - 2009-10-02
    • status: pending-remind --> open-fixed
     
  • Cristina Ghita

    Cristina Ghita - 2009-10-02

    Ups..

    I did not see that Carlos already updated. Sorry!

     
  • Carlos Ruiz

    Carlos Ruiz - 2009-10-02
    • status: open-fixed --> pending-fixed
     
  • SourceForge Robot

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 15 days (the time period specified by
    the administrator of this Tracker).

     
  • SourceForge Robot

    • status: pending-fixed --> closed-fixed
     

Log in to post a comment.