Exercises to lear Velocity Template Language and to develop forms in XNAT

88 views
Skip to first unread message

Matteo Riva

unread,
Nov 3, 2022, 6:47:50 AM11/3/22
to xnat_discussion
Hello everyone,

I have a very simple question and I hope a simple task too for you:

Do you know where I can find exercises to learn Velocity Template Language and to develop forms in XNAT, please? I have already read the following guide:


Maybe I am not clever enough, but I find it very difficult in XNAT forms. Exercises, examples, anything could be helpful, please.

Thank you so much in advance.
Cheers,

Matteo

Will Horton

unread,
Nov 4, 2022, 5:47:34 AM11/4/22
to xnat_discussion
Matteo, 
Speaking from personal experience, there is no need to doubt your cleverness. The UI development documentation for XNAT has been a sore spot for some time. We are planning on releasing a new Custom Forms experience that will allow you to create new input forms using a WYSIWYG editor in the UI -- but these forms will only pertain to new variable data that is appended to an existing datatype (as an upgraded version of Custom Variables). 

Can I ask what kind of form you're trying to create? What type of data are you trying to capture? And are you developing in a plugin environment? I might be able to point you to similar code that already exists elsewhere in the platform for you to use as a template.  

Regards,
Will 

Matteo Riva

unread,
Nov 4, 2022, 10:04:58 AM11/4/22
to xnat_discussion
Hello Will,

Thank you so much for your kindness and your reply!
Great for the new Custom Forms experience! It is a fantastic new :)
What I am trying to do is something like this:

NEW SUBJECT

new_subject.JPG
In this first step, I would like to create a new Subject ID, which is the merge of the Primary Project (the hospital) and of the Codice Soggetto.

NEW EXPERIMENT

new_experiment.JPG
In this second step, I would like to select the Project and automatically the Subject and finally the type of experiment.

NEW NM SESSION

new_nmsession.JPG

In this last step, I would like to add "Time Point", "Date", etc in order to create a new record.

All these things have been developed by a collaborator, but he can't explain to me the source code, the scripts he is writing, the steps he is making, etc. But I would like to understand how to develop these things by my own on XNAT, what are the files I need to see, if I need to deeply learn Velocity Template Language, etc.
All I know is that he is using these two plugins: dxm-settings-plugin-1.0.jar and xnat-base-files-modifications-plugin-1.7.6.jar.

I hope I replied to your questions WIll.
Thank you again for your help!

Cheers,

Matteo

Matteo Riva

unread,
Nov 8, 2022, 10:02:13 AM11/8/22
to xnat_discussion
Hello Will and hello everyone,

I hope everything is fine.
I am writing since I wonder if you have found something to help me to do this work and to learn Velocity Template Language? Do you need something else? Was my reply exhaustive enough?

Thank you!
Cheers,

Matteo

Will Horton

unread,
Nov 10, 2022, 3:50:42 PM11/10/22
to xnat_discussion
Matteo, 
It looks like you are looking for some fairly extensive customizations, and that will require a mix of Velocity and Javascript interactions with the existing UI templates to sort out. This kind of development modifying the XNAT core UI does have a learning curve attached, and we sadly do not have great internal documentation for teaching developers how to code in Velocity, outside what already exists. What we generally do is point at working code elsewhere in XNAT or its universe of plugins if there are other examples of similar work, or rely on good old-fashioned hacking to explore what works. 

In terms of the plugins you mentioned, I can rule out the "dxm-settings" plugin, as that is one of our distributed plugins as a companion with the XNAT Desktop Client (or "Desktop Transfer Manager", hence the "dxm" acronym). So if you are hoping to use and modify the existing code done by your previous developer, the goal would be to extract the contents of the other plugin jar and examine those files. 

For the specific changes that you're looking for, these are the locations of the original files in core XNAT. Your goal would be to create modified versions of those files in your plugin. All of these files are located within the xnat-web repo, under /src/main/webapp/
  • The standard Subject ID input field in experiment edit forms is in:
    • xnat-templates/screens/xnat_subjectData/xnat_subjectData_ProjectSelector.vm
    • scripts/subject/SubjectLabelEditor.js
  • I'm not sure I understand what you're trying to do in your second step, but the Experiment selection screen code is at: 
    • xnat-templates/screens/XDATScreen_add-experiment.vm 
    • scripts/xnat/app/addExperiment.js
    • scripts/projectSubjectSelector.js
  • For your third step, it will depend on whether you want to make changes that apply to all image sessions, or only to modality-specific session edit pages, such as the NM Session that you are showing.   

Matteo Riva

unread,
Nov 11, 2022, 3:29:26 AM11/11/22
to xnat_discussion
Hello Will,

I thank you so much for your help.
Unfortunately, I have already tried to read those files in order to understand what it is written, but it is like reading an unknown language at least for me. That is why I am searching for exercises or lessons or anything else that could help me and teach me how to use VTL and how to apply it in XNAT.
May I ask how you did manage to get skilled in VTL? What are the steps you did?

Thank you so much again.
Cheers,

Matteo

Will Horton

unread,
Nov 15, 2022, 4:40:08 PM11/15/22
to xnat_discussion
Matteo, I wish I could point you to a set of killer tutorials that would enable a learn-on-your-own work style. I benefitted from working within the lab for years among developers who wrote this code, being able to tap people on the shoulder and ask for help as I went. We have long talked about the benefits of having a more transparent codebase, built on a modern framework, to invite more collaboration from the open source community, and this is a primary example of why. 

Sorry I can't be more immediately helpful. 

Regards,
Will 

Matteo Riva

unread,
Nov 16, 2022, 4:49:48 AM11/16/22
to xnat_discussion
Hello Will,

Unfortunately, I cannot ask for help to our developer in XNAT, since he is not paid for teaching me how he wrote the script.
I thank you so much WIll for your kind reply. I hope to learn something during time :)

Regards,

Matteo
Reply all
Reply to author
Forward
0 new messages