IDEMPIERE-5529 StackOverflowError at Quick Entry using WDateEditor (#1940)
This commit is contained in:
parent
65a69ee332
commit
8034113ccc
|
@ -18,8 +18,10 @@
|
||||||
package org.adempiere.webui.editor;
|
package org.adempiere.webui.editor;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.adempiere.webui.ValuePreference;
|
import org.adempiere.webui.ValuePreference;
|
||||||
import org.adempiere.webui.component.Datebox;
|
import org.adempiere.webui.component.Datebox;
|
||||||
|
@ -171,30 +173,43 @@ public class WDateEditor extends WEditor implements ContextMenuListener
|
||||||
{
|
{
|
||||||
if (value == null || value.toString().trim().length() == 0)
|
if (value == null || value.toString().trim().length() == 0)
|
||||||
{
|
{
|
||||||
|
Timestamp currentValue = oldValue;
|
||||||
oldValue = null;
|
oldValue = null;
|
||||||
getComponent().setValue(null);
|
getComponent().setValue(null);
|
||||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, value);
|
if (currentValue != null)
|
||||||
super.fireValueChange(changeEvent);
|
{
|
||||||
|
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, null);
|
||||||
|
super.fireValueChange(changeEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (value instanceof Timestamp)
|
else if (value instanceof Timestamp)
|
||||||
{
|
{
|
||||||
getComponent().setValueInLocalDateTime(((Timestamp)value).toLocalDateTime());
|
Timestamp currentValue = oldValue;
|
||||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, value);
|
LocalDateTime localDateTime = ((Timestamp)value).toLocalDateTime();
|
||||||
super.fireValueChange(changeEvent);
|
getComponent().setValueInLocalDateTime(localDateTime);
|
||||||
oldValue = (Timestamp)value;
|
oldValue = Timestamp.valueOf(localDateTime);
|
||||||
|
if (!Objects.equals(currentValue, oldValue))
|
||||||
|
{
|
||||||
|
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, oldValue);
|
||||||
|
super.fireValueChange(changeEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Timestamp currentValue = oldValue;
|
||||||
getComponent().setText(value.toString());
|
getComponent().setText(value.toString());
|
||||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, value);
|
if (getComponent().getValue() != null)
|
||||||
super.fireValueChange(changeEvent);
|
oldValue = Timestamp.valueOf(getComponent().getValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
|
||||||
} catch (Exception e) {}
|
else
|
||||||
if (getComponent().getValue() != null)
|
oldValue = null;
|
||||||
oldValue = Timestamp.valueOf(getComponent().getValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
|
if (!Objects.equals(currentValue, oldValue))
|
||||||
else
|
{
|
||||||
oldValue = null;
|
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, oldValue);
|
||||||
|
super.fireValueChange(changeEvent);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,8 @@ import org.compiere.util.Util;
|
||||||
import org.zkoss.zk.ui.event.Event;
|
import org.zkoss.zk.ui.event.Event;
|
||||||
import org.zkoss.zk.ui.event.Events;
|
import org.zkoss.zk.ui.event.Events;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default editor for {@link DisplayType#DateTime} and {@link DisplayType#TimestampWithTimeZone}.
|
* Default editor for {@link DisplayType#DateTime} and {@link DisplayType#TimestampWithTimeZone}.
|
||||||
* Implemented with {@link DatetimeBox} component.
|
* Implemented with {@link DatetimeBox} component.
|
||||||
|
@ -215,30 +217,46 @@ public class WDatetimeEditor extends WEditor implements ContextMenuListener
|
||||||
{
|
{
|
||||||
if (value == null || value.toString().trim().length() == 0)
|
if (value == null || value.toString().trim().length() == 0)
|
||||||
{
|
{
|
||||||
|
Timestamp currentValue = oldValue;
|
||||||
oldValue = null;
|
oldValue = null;
|
||||||
getComponent().setValue(null);
|
getComponent().setValue(null);
|
||||||
|
if (currentValue != null)
|
||||||
|
{
|
||||||
|
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, null);
|
||||||
|
super.fireValueChange(changeEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (value instanceof Timestamp)
|
else if (value instanceof Timestamp)
|
||||||
{
|
{
|
||||||
Timestamp ts = (Timestamp) value;
|
Timestamp ts = (Timestamp) value;
|
||||||
if (isTimestampWithTimeZone())
|
if (isTimestampWithTimeZone())
|
||||||
{
|
{
|
||||||
|
Timestamp currentValue = oldValue;
|
||||||
ZonedDateTime zdt = ts.toInstant().atZone(getComponent().getDatebox().getTimeZone().toZoneId());
|
ZonedDateTime zdt = ts.toInstant().atZone(getComponent().getDatebox().getTimeZone().toZoneId());
|
||||||
getComponent().setValueInZonedDateTime(zdt);
|
getComponent().setValueInZonedDateTime(zdt);
|
||||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, value);
|
oldValue = Timestamp.from(zdt.toInstant());
|
||||||
super.fireValueChange(changeEvent);
|
if (!Objects.equal(currentValue, oldValue))
|
||||||
|
{
|
||||||
|
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, oldValue);
|
||||||
|
super.fireValueChange(changeEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Timestamp currentValue = oldValue;
|
||||||
LocalDateTime localTime = ts.toLocalDateTime();
|
LocalDateTime localTime = ts.toLocalDateTime();
|
||||||
getComponent().setValueInLocalDateTime(localTime);
|
getComponent().setValueInLocalDateTime(localTime);
|
||||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, value);
|
oldValue = Timestamp.valueOf(localTime);
|
||||||
super.fireValueChange(changeEvent);
|
if (!Objects.equal(currentValue, oldValue))
|
||||||
|
{
|
||||||
|
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, oldValue);
|
||||||
|
super.fireValueChange(changeEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
oldValue = ts;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Timestamp currentValue = oldValue;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
getComponent().setText(value.toString());
|
getComponent().setText(value.toString());
|
||||||
|
@ -249,10 +267,20 @@ public class WDatetimeEditor extends WEditor implements ContextMenuListener
|
||||||
oldValue = Timestamp.from(getComponent().getDatebox().getValue().toInstant());
|
oldValue = Timestamp.from(getComponent().getDatebox().getValue().toInstant());
|
||||||
else
|
else
|
||||||
oldValue = Timestamp.valueOf(getComponent().getDatebox().getValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
|
oldValue = Timestamp.valueOf(getComponent().getDatebox().getValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
|
||||||
|
if (!Objects.equal(currentValue, oldValue))
|
||||||
|
{
|
||||||
|
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, oldValue);
|
||||||
|
super.fireValueChange(changeEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
oldValue = null;
|
oldValue = null;
|
||||||
|
if (currentValue != null)
|
||||||
|
{
|
||||||
|
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, null);
|
||||||
|
super.fireValueChange(changeEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue