Fórum

Programatically, reset a custom date field using ExpandoBridge

thumbnail
darren rose, modificado 8 Anos atrás.

Programatically, reset a custom date field using ExpandoBridge

Regular Member Postagens: 215 Data de Entrada: 04/04/15 Postagens Recentes
Hi,

Programatically, I need to reset/clear/set to null a custom field that is a date.

I am using the ExpandoBridge.

Any help welcomed, the errors I see when using null or empty string results in exceptions.

regards
thumbnail
Julien Mourad, modificado 8 Anos atrás.

RE: Programatically, reset a custom date field using ExpandoBridge

Junior Member Postagens: 78 Data de Entrada: 22/01/15 Postagens Recentes
layout.getExpandoBridge().setAttribute(String name, Serializable value, boolean secure)
ex: layout.getExpandoBridge().setAttribute("custom.value", "", false)

https://docs.liferay.com/portal/6.2/javadocs/com/liferay/portlet/expando/model/ExpandoBridge.html
thumbnail
darren rose, modificado 7 Anos atrás.

RE: Programatically, reset a custom date field using ExpandoBridge

Regular Member Postagens: 215 Data de Entrada: 04/04/15 Postagens Recentes
Julien Mourad:
layout.getExpandoBridge().setAttribute(String name, Serializable value, boolean secure)
ex: layout.getExpandoBridge().setAttribute("custom.value", "", false)

https://docs.liferay.com/portal/6.2/javadocs/com/liferay/portlet/expando/model/ExpandoBridge.html



using "" results in

java.lang.RuntimeException: jodd.typeconverter.TypeConversionException: Unable to convert value: ; <--- java.lang.NumberFormatException: For input string: ""
thumbnail
Pankaj Kathiriya, modificado 7 Anos atrás.

RE: Programatically, reset a custom date field using ExpandoBridge

Liferay Master Postagens: 722 Data de Entrada: 05/08/10 Postagens Recentes
Liferay uses millisecond value wrt(01/01/1970) for Date custom field. So you have to set its value as 0 instead "".

So,by setting it as 0, custom field value will be set as default date 01/01/1970.
thumbnail
darren rose, modificado 7 Anos atrás.

RE: Programatically, reset a custom date field using ExpandoBridge

Regular Member Postagens: 215 Data de Entrada: 04/04/15 Postagens Recentes
Pankaj Kathiriya:
Liferay uses millisecond value wrt(01/01/1970) for Date custom field. So you have to set its value as 0 instead "".

So,by setting it as 0, custom field value will be set as default date 01/01/1970.



Sure, but actually, my business case is to reset a date to null and not 1/1/1970 - which doesn't seem possible?