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
Hi Cristina, sorry, I don't understand the issue.
All ID setters in Adempiere on X_ classes behaves like you described - if ID < 1 then is set to null.
i.e. look at lines 111-112 here:
http://adempiere.svn.sourceforge.net/viewvc/adempiere/trunk/base/src/org/compiere/model/X_AD_ClientInfo.java?view=markup
Regards,
Carlos Ruiz
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
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
Better I upload the patch because the formatting was lost.
Attached file patch2870645.patch with the proposed patch on GridTab
Regards,
Carlos Ruiz
Revision: 10446
http://adempiere.svn.sourceforge.net/adempiere/?rev=10446&view=rev
Author: redchris
Date: 2009-10-01 07:21:32 +0000 (Thu, 01 Oct 2009)
Log Message:
-----------
FR [2870645] Set null value for an ID
https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2870645&group_id=176962
Solution suggested by Carlos
Please review
Modified Paths:
--------------
trunk/base/src/org/compiere/model/GridTab.java
Commited in revision 10446
Carlos I integrated your solution. Is better. Thanks!
Revision: 10446
http://adempiere.svn.sourceforge.net/adempiere/?rev=10446&view=rev
Author: redchris
Date: 2009-10-01 07:21:32 +0000 (Thu, 01 Oct 2009)
Log Message:
-----------
FR [2870645] Set null value for an ID
https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2870645&group_id=176962
Solution suggested by Carlos
Please review
Modified Paths:
--------------
trunk/base/src/org/compiere/model/GridTab.java
Ups..
I did not see that Carlos already updated. Sorry!
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).