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;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.adempiere.webui.ValuePreference;
|
||||
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)
|
||||
{
|
||||
Timestamp currentValue = oldValue;
|
||||
oldValue = null;
|
||||
getComponent().setValue(null);
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, value);
|
||||
if (currentValue != null)
|
||||
{
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, null);
|
||||
super.fireValueChange(changeEvent);
|
||||
}
|
||||
}
|
||||
else if (value instanceof Timestamp)
|
||||
{
|
||||
getComponent().setValueInLocalDateTime(((Timestamp)value).toLocalDateTime());
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, value);
|
||||
Timestamp currentValue = oldValue;
|
||||
LocalDateTime localDateTime = ((Timestamp)value).toLocalDateTime();
|
||||
getComponent().setValueInLocalDateTime(localDateTime);
|
||||
oldValue = Timestamp.valueOf(localDateTime);
|
||||
if (!Objects.equals(currentValue, oldValue))
|
||||
{
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, oldValue);
|
||||
super.fireValueChange(changeEvent);
|
||||
oldValue = (Timestamp)value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
Timestamp currentValue = oldValue;
|
||||
getComponent().setText(value.toString());
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, value);
|
||||
super.fireValueChange(changeEvent);
|
||||
} catch (Exception e) {}
|
||||
if (getComponent().getValue() != null)
|
||||
oldValue = Timestamp.valueOf(getComponent().getValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
|
||||
else
|
||||
oldValue = null;
|
||||
if (!Objects.equals(currentValue, oldValue))
|
||||
{
|
||||
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.Events;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* Default editor for {@link DisplayType#DateTime} and {@link DisplayType#TimestampWithTimeZone}.
|
||||
* Implemented with {@link DatetimeBox} component.
|
||||
|
@ -215,30 +217,46 @@ public class WDatetimeEditor extends WEditor implements ContextMenuListener
|
|||
{
|
||||
if (value == null || value.toString().trim().length() == 0)
|
||||
{
|
||||
Timestamp currentValue = oldValue;
|
||||
oldValue = null;
|
||||
getComponent().setValue(null);
|
||||
if (currentValue != null)
|
||||
{
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, null);
|
||||
super.fireValueChange(changeEvent);
|
||||
}
|
||||
}
|
||||
else if (value instanceof Timestamp)
|
||||
{
|
||||
Timestamp ts = (Timestamp) value;
|
||||
if (isTimestampWithTimeZone())
|
||||
{
|
||||
Timestamp currentValue = oldValue;
|
||||
ZonedDateTime zdt = ts.toInstant().atZone(getComponent().getDatebox().getTimeZone().toZoneId());
|
||||
getComponent().setValueInZonedDateTime(zdt);
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, value);
|
||||
oldValue = Timestamp.from(zdt.toInstant());
|
||||
if (!Objects.equal(currentValue, oldValue))
|
||||
{
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, oldValue);
|
||||
super.fireValueChange(changeEvent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Timestamp currentValue = oldValue;
|
||||
LocalDateTime localTime = ts.toLocalDateTime();
|
||||
getComponent().setValueInLocalDateTime(localTime);
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, value);
|
||||
oldValue = Timestamp.valueOf(localTime);
|
||||
if (!Objects.equal(currentValue, oldValue))
|
||||
{
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, oldValue);
|
||||
super.fireValueChange(changeEvent);
|
||||
}
|
||||
oldValue = ts;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Timestamp currentValue = oldValue;
|
||||
try
|
||||
{
|
||||
getComponent().setText(value.toString());
|
||||
|
@ -249,10 +267,20 @@ public class WDatetimeEditor extends WEditor implements ContextMenuListener
|
|||
oldValue = Timestamp.from(getComponent().getDatebox().getValue().toInstant());
|
||||
else
|
||||
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
|
||||
{
|
||||
oldValue = null;
|
||||
if (currentValue != null)
|
||||
{
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), currentValue, null);
|
||||
super.fireValueChange(changeEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue