Conversation
| @NiagaraProperty(name = "fileName", type = "BString", defaultValue = "BString.DEFAULT") | ||
| @NiagaraProperty(name = "path", type = "BString", defaultValue = "BString.DEFAULT") | ||
| @NiagaraProperty(name = "size", type = "BInteger", defaultValue = "BInteger.DEFAULT") | ||
| @NiagaraProperty(name = "createdDate", type = "BAbsTime", defaultValue = "BAbsTime.now()") |
There was a problem hiding this comment.
You have to be careful using a defaultValue of BAbsTime.now() because this defaultValue is used to initialize the static Property field on line 105. Since that field is static, every instance of this class will share it. What that ultimately means is every new copy of this component that gets added to a station will have the same default value for the createdDate property and it won't be the time at which that particular component got created, but it will be the time that this class got loaded in the JVM.
If you want the value of the createdDate to be when the component got added to the station, it would be better to use a defaultValue of BAbsTime.DEFAULT like you're doing for modifiedDate and then override the started() callback to see if the component is starting for the first time and, if so, update the createdDate Property to BAbsTime.now(). Maybe something like:
@Override
public void started()
{
if (getCreatedDate().equals(BAbsTime.DEFAULT))
{
setCreatedDate(BAbsTime.now());
}
}|
I understand. Thank you.
Get Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: robert-tridium ***@***.***>
Sent: Wednesday, March 25, 2026 11:13:29 PM
To: robert-tridium/n4-developer-submissions ***@***.***>
Cc: Charles Soler ***@***.***>; Author ***@***.***>
Subject: [EXTERNAL] Re: [robert-tridium/n4-developer-submissions] module created per README.md (PR #53)
[ EXTERNAL EMAIL ]
@robert-tridium commented on this pull request.
Looks great!
________________________________
In 1 Niagara 4 Overview Exercise - BFile/myFile-rt/src/com/tridiumuniversity/myFile/BFile.java<#53?email_source=notifications&email_token=ASVF74ZGETKF6MD5B6AT3IL4SSN5TA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTIMBRGEYTMMRWGQ42M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K64DSL5ZGK5TJMV3V6Y3MNFRWW#discussion_r2992209822>:
+import javax.baja.nre.annotations.NiagaraProperty;
+import javax.baja.nre.annotations.NiagaraType;
+import javax.baja.sys.BAbsTime;
+import javax.baja.sys.BComponent;
+import javax.baja.sys.Action;
+import javax.baja.sys.BInteger;
+import javax.baja.sys.BString;
+import javax.baja.sys.Property;
+import javax.baja.sys.Sys;
+import javax.baja.sys.Type;
+
***@***.***
***@***.***(name = "fileName", type = "BString", defaultValue = "BString.DEFAULT")
***@***.***(name = "path", type = "BString", defaultValue = "BString.DEFAULT")
***@***.***(name = "size", type = "BInteger", defaultValue = "BInteger.DEFAULT")
***@***.***(name = "createdDate", type = "BAbsTime", defaultValue = "BAbsTime.now()")
You have to be careful using a defaultValue of BAbsTime.now() because this defaultValue is used to initialize the static Property field on line 105. Since that field is static, every instance of this class will share it. What that ultimately means is every new copy of this component that gets added to a station will have the same default value for the createdDate property and it won't be the time at which that particular component got created, but it will be the time that this class got loaded in the JVM.
If you want the value of the createdDate to be when the component got added to the station, it would be better to use a defaultValue of BAbsTime.DEFAULT like you're doing for modifiedDate and then override the started() callback to see if the component is starting for the first time and, if so, update the createdDate Property to BAbsTime.now(). Maybe something like:
@OverRide
public void started()
{
if (getCreatedDate().equals(BAbsTime.DEFAULT))
{
setCreatedDate(BAbsTime.now());
}
}
—
Reply to this email directly, view it on GitHub<#53?email_source=notifications&email_token=ASVF74YXOULX4OVIPN7IKJD4SSN5TA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTIMBRGEYTMMRWGQ42M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2L24DSL5ZGK5TJMV3V63TPORUWM2LDMF2GS33OONPWG3DJMNVQ#pullrequestreview-4011162649>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ASVF747HSTJLWCD2YCOJM234SSN5TAVCNFSM6AAAAACW55K3G2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHM2DAMJRGE3DENRUHE>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Create a new Niagara component named BFile with the following:
A Property named fileName with a type of String
A Property named path with a type of String
A Property named size with a type of int
A Property named createdDate with a type of BAbsTime
A Property named modifiedDate with a type of BAbsTime
An Action named touch that updates the modifiedDate Property to the current time
An Action named print that prints a summary of the Properties to stdout.